x402
Last updated Oct 22, 2026 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.
How it works
- 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.
Key components
Client
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.
Server
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
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.
Payment schemes and 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, Algorand | 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, Sui, and Algorand. Use base-sepolia for testing with free test USDC from the Circle Faucet ↗︎.
Charge for resources
HTTP content
Gate APIs, web pages, and files with a Worker proxy
MCP tools
Charge per tool call using paidTool
Pay for resources
Agents SDK
Wrap MCP clients with withX402Client
Coding tools
OpenCode plugin and Claude Code hook
SDKs
| 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 |
@x402/avm |
npm install @x402/avm |
Algorand payment scheme support |
agents/x402 |
Included in agents |
MCP client with x402 payment support |
Related
- x402.org ↗︎ — Protocol specification
- x402 GitHub ↗︎ — Open source SDK
- x402 examples ↗︎ — Complete working code
- Pay Per Crawl — Cloudflare-native monetization
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"WebPage","@id":"https://developers.cloudflare.com/agents/tools/payments/x402/#page","headline":"x402","description":"Accept and make machine-to-machine payments using the x402 HTTP payment protocol on Cloudflare Workers and the Agents SDK.","url":"https://developers.cloudflare.com/agents/tools/payments/x402/","inLanguage":"en","image":"https://developers.cloudflare.com/agents/tools/payments/x402/og.png?v=b40a4227417737f2","dateModified":"2026-10-22","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Gate HTTP endpoints with x402 payments using a Cloudflare Worker proxy. title: Charge for HTTP content image: https://developers.cloudflare.com/agents/tools/payments/x402/charge-for-http-content/og.png?v=af4a2346e36e5439
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/agents/llms.txt
Use this file to discover all available pages before exploring further.
Docs