Skip to main content

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

  1. Request. The agent calls the service URL with no payment.
  2. Challenge. The service returns 402 Payment Required with the requirements: scheme (exact), network (xdc), USDC asset, maxAmountRequired (base units), and payTo.
  3. Authorize. The agent signs an EIP-3009 transferWithAuthorization — an off-chain EIP-712 signature authorizing exactly the required USDC to payTo. No gas, no on-chain tx yet.
  4. Resend. The agent repeats the request with X-PAYMENT: <base64 of the signed authorization>.
  5. Verify. The service (via a facilitator) checks the signature, amount, recipient, and network.
  6. Settle. A relayer/sponsor submits the transferWithAuthorization on XDC and pays the gas. The USDC moves from the agent's wallet to the provider's payTo.
  7. Respond. The service returns 200 OK with 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 402 amount is in USDC base units (6 decimals): 10000 = 0.01 USDC.
  • X-PAYMENT is base64 of the signed authorization payload.
  • Settlement should be idempotent per nonce to make retries safe.
  • Advertised price / asset / payTo must match the 402 challenge.

See also: Make an x402 endpoint · Constants.