Skip to content

How x402 Works

x402 is an open protocol for HTTP-native payments. It repurposes the 402 Payment Required HTTP status code — originally reserved but never standardized — to enable machine-to-machine micropayments.

This page covers the basics. For the full specification, see x402.org.

Client Tollbooth Facilitator Upstream API
│ │ │ │
│ GET /weather │ │ │
│─────────────────────────>│ │ │
│ │ │ │
│ 402 Payment Required │ │ │
│ + payment-required hdr │ │ │
│<─────────────────────────│ │ │
│ │ │ │
│ (client signs payment) │ │ │
│ │ │ │
│ GET /weather │ │ │
│ + payment-signature hdr │ │ │
│─────────────────────────>│ │ │
│ │ verify + settle │ │
│ │─────────────────────────> │ │
│ │ { tx, payer, ... } │ │
│ │<───────────────────────── │ │
│ │ │ │
│ │ GET /weather │
│ │───────────────────────────────────────────────> │
│ │ { temp: 22, ... } │
│ │<─────────────────────────────────────────────── │
│ │ │ │
│ 200 OK + data │ │ │
│ + payment-response hdr │ │ │
│<─────────────────────────│ │ │
  1. Client sends a request — no payment attached
  2. Tollbooth returns 402 with a payment-required header containing base64-encoded payment requirements (amount, network, asset, recipient address, timeout)
  3. Client signs a payment — an EIP-3009 transferWithAuthorization for the required USDC amount
  4. Client resends the request with the signed payment in the payment-signature header
  5. Tollbooth forwards to the facilitator which verifies the signature and settles the on-chain USDC transfer
  6. Tollbooth proxies to the upstream and returns the response with a payment-response header containing the transaction hash
ComponentResponsibility
ClientSigns EIP-3009 payment, attaches it to the request
TollboothRoute matching, price resolution, 402 responses, proxying, hooks
Facilitator / Circle GatewaySignature verification, USDC settlement (immediate or batched), tx hash
Upstream APIThe actual API being monetized (unchanged, unaware of payments)

The upstream API doesn’t need to know about x402 at all. Tollbooth sits in front and handles everything.

When tollbooth returns a 402, it includes a base64-encoded JSON payload in the payment-required header:

{
"x402Version": 2,
"scheme": "exact",
"network": "base-sepolia",
"asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
"maxAmountRequired": "1000",
"payTo": "0xGatewayWalletAddress",
"maxTimeoutSeconds": 300
}
FieldDescription
x402VersionProtocol version (currently 2)
schemePayment scheme (exact for fixed-price)
networkBlockchain network for payment
assetToken contract address (USDC)
maxAmountRequiredAmount in micro-units (1000 = $0.001 USDC)
payToRecipient wallet address
maxTimeoutSecondsHow long the payment authorization is valid

A facilitator is a service that verifies payment signatures and settles them on-chain. It acts as a trusted intermediary:

  1. Receives the signed transferWithAuthorization payload from tollbooth
  2. Verifies the EIP-712 signature is valid and the amount matches
  3. Submits the USDC transfer on-chain (the facilitator sponsors gas)
  4. Returns the transaction hash and settlement details

By default, tollbooth uses https://x402.org/facilitator. You can run your own or point to an alternative.

Circle Nanopayments is an alternative settlement path that uses Circle’s Gateway to batch multiple payments into periodic on-chain settlements. Instead of settling each payment individually, the gateway collects signed TransferWithAuthorization authorizations and settles them together — making gas-free sub-cent USDC transfers economically viable (payments as small as $0.000001).

The flow is the same as above, but with two differences:

  1. EIP-712 domain — clients sign against Circle’s GatewayWalletBatched contract domain instead of the standard per-token domain. tollbooth includes the correct domain info in 402 responses automatically.
  2. Batched settlement — instead of an immediate on-chain transaction per request, Circle Gateway batches authorizations and settles them asynchronously.
settlement:
strategy: nanopayments
network: testnet

See Settlement Strategies for full configuration details and a comparison of all strategies.

The x402 exact scheme uses EIP-3009 — a standard for gasless USDC transfers via signed authorizations. Instead of the payer broadcasting an on-chain transaction, they sign an off-chain EIP-712 typed-data message authorizing a specific transfer. The facilitator (or Circle Gateway, when using nanopayments) then submits this authorization on-chain, pulling the USDC from the payer’s wallet to the gateway’s wallet. The payer never needs ETH for gas — the settlement service covers it.

When gateway.discovery is true (the default), tollbooth exposes a GET /.well-known/x402 endpoint that returns metadata about all paid routes — accepted networks, assets, and pricing. Clients can use this to discover what payments are required before making requests.

Example response:

{
"x402Version": 2,
"provider": "tollbooth",
"endpoints": [
{
"method": "GET",
"path": "/weather",
"pricing": { "type": "static", "model": "request", "defaultPrice": "$0.001" },
"accepts": [
{ "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e", "network": "base-sepolia", "facilitator": "https://x402.org/facilitator" }
],
"facilitator": "https://x402.org/facilitator"
}
]
}

Discovery also enables an enriched OpenAPI spec at /.well-known/openapi.json with x402 payment extensions. See the OpenAPI Integration guide for details on how AI agents can use this for automatic tool discovery.


Next: Settlement Strategies →