x402
x402 ↗ is a payment standard built around HTTP 402 (Payment Required). Services return a 402 response with payment instructions, and clients pay programmatically without accounts, sessions, or API keys.
- A client requests a resource —
GET /resource. - The server returns
402 Payment Requiredwith aPAYMENT-REQUIREDheader containing Base64-encoded payment details: the price, accepted token, network, and merchant address. - The client constructs a signed payment payload and retries the request with a
PAYMENT-SIGNATUREheader. - The server verifies the payment payload — directly or by calling a facilitator — and settles the transaction on-chain.
- The server returns the resource with a
PAYMENT-RESPONSEheader containing settlement confirmation.
The client is any entity that requests a paid resource: a human-operated app, an AI agent, or a programmatic service. Clients need only a crypto wallet — no accounts, credentials, or session tokens to manage.
The server defines payment requirements in the 402 response, verifies incoming payment payloads, settles the transaction, and serves the resource. The x402 SDKs and a facilitator handle most of this automatically.
The facilitator is an optional but recommended third-party service that abstracts blockchain interaction. Rather than connecting to a node directly, the server delegates two operations:
POST /verify— Confirms the client's payment payload is valid before the server fulfills the request.POST /settle— Submits the verified payment transaction to the blockchain.
The facilitator does not hold funds. It verifies and broadcasts the client's pre-signed transaction on behalf of the server. https://x402.org/facilitator is the public facilitator operated by Coinbase and is used in all Cloudflare examples. Multiple facilitators ↗ are available across different networks.
x402 uses payment schemes to define how a payment is constructed and settled on a given network.
| Scheme | Networks | Description |
|---|---|---|
exact ↗ | EVM, Solana, Aptos, Stellar, Hedera, Sui | Transfers a fixed token amount — typically ERC-20 ↗ USDC on EVM — to the merchant address. |
upto ↗ | EVM | Authorizes a maximum amount; the actual charge is determined at settlement time based on resource consumption. |
Supported networks include Base, Ethereum, Polygon, Optimism, Arbitrum, Avalanche, Solana, Aptos, Stellar, and Sui. Use base-sepolia for testing with free test USDC from the Circle Faucet ↗.
| Package | Install | Use |
|---|---|---|
x402-hono | npm install x402-hono | Hono middleware for Worker servers |
@x402/fetch | npm install @x402/fetch | Fetch wrapper with automatic payment handling |
@x402/evm | npm install @x402/evm | EVM payment scheme support |
agents/x402 | Included in agents | MCP client with x402 payment support |
- x402.org ↗ — Protocol specification
- x402 GitHub ↗ — Open source SDK
- x402 examples ↗ — Complete working code
- Pay Per Crawl — Cloudflare-native monetization