x402 flow
XDC AI uses the x402 protocol: HTTP-native, pay-per-request payments. Payment is an off-chain signed authorization that a relayer settles on-chain — so the paying agent never holds gas.
Sequence
Agent Service Relayer / XDC
│ GET /x402/resource │ │
├─────────────────────────────▶ │
│ 402 Payment Required │ │
│ { accepts: [ amount, asset,│ │
│ payTo, network ] } │ │
◀─────────────────────────────┤ │
│ │ │
│ sign EIP-3009 transferWith- │ │
│ Authorization (USDC → payTo)│ │
│ │ │
│ GET /x402/resource │ │
│ X-PAYMENT: base64(auth) ────▶ verify signature + amount │
│ ├──────── settle authorization ──▶ on-chain USDC
│ │ (relayer pays gas) │ transfer
│ 200 OK + data ◀───────── confirmed ───────────┤
◀─────────────────────────────┤ │
Steps in detail
- Request. The agent calls the service URL with no payment.
- Challenge. The service returns
402 Payment Requiredwith the requirements:scheme(exact),network(xdc), USDCasset,maxAmountRequired(base units), andpayTo. - Authorize. The agent signs an EIP-3009
transferWithAuthorization— an off-chain EIP-712 signature authorizing exactly the required USDC topayTo. No gas, no on-chain tx yet. - Resend. The agent repeats the request with
X-PAYMENT: <base64 of the signed authorization>. - Verify. The service (via a facilitator) checks the signature, amount, recipient, and network.
- Settle. A relayer/sponsor submits the
transferWithAuthorizationon XDC and pays the gas. The USDC moves from the agent's wallet to the provider'spayTo. - Respond. The service returns
200 OKwith the data.
Why gasless
EIP-3009 lets a third party submit a token transfer on behalf of the signer. The agent only ever signs; a sponsor relayer broadcasts and covers gas. That's why an agent wallet needs only USDC, never native XDC. See Wallet & gasless.
For implementers
- The
402amount is in USDC base units (6 decimals):10000=0.01USDC. X-PAYMENTis base64 of the signed authorization payload.- Settlement should be idempotent per nonce to make retries safe.
- Advertised price /
asset/payTomust match the402challenge.
See also: Make an x402 endpoint · Constants.