x402 on the wire: three headers and a one-dollar default
How x402 puts the price in a 402 reply and the payment in the retry, and why the official client stops payments above one dollar by default.
Charging for an API call usually means accounts, keys and invoices. x402 replaces all three with the HTTP exchange itself. The price travels in the reply, the payment travels in the retry, and the whole flow fits in three headers. This post follows that exchange on the wire, then covers the one default that stops agents from paying for anything larger than a small call.
The first request: price in the reply
The client sends an ordinary request. If the resource is paid, the server answers with status 402, Payment Required, and a PAYMENT-REQUIRED header. The header holds base64-encoded JSON. Decoded, its core is a list of payment options the server accepts. The excerpt below shows selected fields from accepts. A complete v2 challenge also includes resource.url. For the EIP-3009 option shown here, accepts[0].extra.name and accepts[0].extra.version supply the token's EIP-712 domain name and version. The addresses below are abbreviated.
{
"x402Version": 2,
"accepts": [
{
"scheme": "exact",
"network": "eip155:8453",
"amount": "5000000",
"asset": "0xUSDC...",
"payTo": "0xPayee...",
"maxTimeoutSeconds": 60
}
]
}Three fields do most of the work:
amountis in atomic token units. For a token with 6 decimals, 5000000 is 5 tokens.payTois the address that receives the payment.schemenames how the payment is made. Theexactscheme transfers a specific amount from the client to the server.
The retry: payment in a header
The client picks one option, signs a payment for exactly that amount, and sends the same request again with a PAYMENT-SIGNATURE header. On EVM chains the exact scheme uses an EIP-3009 transfer authorization by default: a signed message, not a transaction, so signing it costs the payer no gas. The payload echoes the option the client accepted and carries the signature with the authorization fields.
GET /resource HTTP/1.1
Host: api.example.com
PAYMENT-SIGNATURE: eyJ4NDAyVmVyc2lvbiI6Mi...Check, run, settle, reply
In the default flow, which the spec calls authorization, the server works in four steps:
- Verify the payment. This check is read-only.
- Run the request.
- Settle the payment on chain.
- Reply.
Funds move only after the resource has run successfully. A successful reply is a 200 with the third header, PAYMENT-RESPONSE. The decoded receipt includes success, transaction and network. It may also include the payer's address in payer.
HTTP/1.1 200 OK
PAYMENT-RESPONSE: eyJzdWNjZXNzIjp0cnVl...That is the whole protocol from the client's side: read the price, sign, retry, read the receipt.
The one-dollar default
The official x402 client ships with a spending guard. By default it refuses any payment above $1. The cap applies per payment, not to a running total. For a call that costs a few cents, that default is sensible. For an agent that pays for something larger, every payment above the cap is refused by its own client.
The fix is to raise the cap to the largest single payment the agent is meant to make:
const client = new x402Client().setSpendControls({ maxAmountPerPayment: "$50" });The value is in dollars, not token units. Passing "50000000" by mistake would allow fifty million dollars per payment.
Where Cleave Protocol uses it
Cleave Protocol's gas top-up is an x402 resource. An agent whose wallet holds USDC but no native coin pays USDC over x402, on Base, Arbitrum or Polygon, to order native gas (ETH, BNB or POL) on any of six chains. Orders go up to 50 USDC, so an agent on the official client needs its cap raised for any order above $1, and $50 covers every offer.
Three details matter when wiring it up:
- The 402 reply is for one exact order. Sign for exactly that amount to that
payToaddress. - On the retry, echo the accepted requirement unchanged.
- A settled payment is not delivery. The payment response reports the order as pending even when settlement succeeds. Track the order by its
requestIdto see how it ended.
The query parameters, response codes and tracking steps are on the x402 gas top-up docs page.