One paid call
Every step from the first request to the paid response.
- 01Agent → px402 gatewayThe agent sends a plain request.
- 02px402 gateway → AgentThe gateway stores a single-use nonce and answers with the price, asset, receiver shielded address and expiry.
- 03AgentThe SDK checks the price ceiling, allowed origin and caps, then reserves the nonce in its journal.
- 04Agent → Solana + HeliusOne Privacy Rings transfer to the receiver. The agent key is the only signer and pays the fee.
- 05Agent → px402 gatewayThe same request with PAYMENT-SIGNATURE: nonce, transaction signature and a sender proof signed by the agent key.
- 06px402 gateway → Solana + HeliusThe gateway reads the transaction and decrypts the receiver's output with that provider's viewing key.
- 07px402 gatewayThe payment is bound to the nonce in Postgres before anything is forwarded.
- 08px402 gateway → Provider APIThe gateway calls the provider API with the proxy secret, payment id, route id and attempt number.
- 09Provider API → px402 gatewayThe provider answers.
- 10px402 gateway → AgentThe agent gets the body and a receipt. The earning is counted once. The receipt leaves out the payer.
The built-in demo route runs inside px402, so there is no forward: claiming the nonce, running the handler and counting the earning happen in one database transaction.
What the agent checks before paying
All of these refuse before anything moves on chain:
| Check | Error |
|---|---|
Price above PX402_MAX_PRICE_BASE | SDK_PRICE_ABOVE_MAX |
| Origin not allowed, or the 402 arrived through a redirect to another origin | SDK_ORIGIN_NOT_ALLOWED |
| A spending cap would be passed | SDK_CAP_EXCEEDED |
| Another network, asset or binding mode than the wallet supports | SDK_UNSUPPORTED_REQUIREMENT |
What the gateway checks
- The nonce is known, unexpired and not already used.
- The transaction exists and is not older than the nonce.
- The claim was signed by the transaction’s single public signer.
- A decrypted output pays this receiver at least the price, in the right asset.
Because the claim must be signed by the payer, copying someone’s transaction signature does not let you claim it.
Why you never pay twice
- The agent writes the nonce to its journal before paying, and the transaction signature after signing and before sending. A crash resumes the claim and does not send a second transfer.
- If the transfer is not visible yet, the gateway answers
402 TRANSFER_NOT_FOUNDand the SDK resends the same claim with backoff, until 2 minutes after the nonce expires. - Unique constraints in Postgres mean one nonce is used once and one transfer pays for one nonce.
If a payment is refused after money moved (for example TRANSFER_AMOUNT_TOO_LOW), the journal records it as rejected.
Refunds are manual today.
How long it takes
Seconds, not milliseconds. A paid call took about 4 s at p50 in one measurement and about 6 s at p50 through the deployed stack in another; 20 concurrent calls from one wallet measured a p95 of 34 s. These are small devnet samples. Use px402 for fewer, higher-value calls.