x402 Anatomy

How AI agents pay each other over HTTP. The protocol that finally gives HTTP 402 a job after 28 years.

🤖
Client Agent
Needs data
🖥
Resource Server
Has data, wants $
Facilitator
Verifies + settles
Blockchain
Settlement layer

The key insight: x402 is stateless. No sessions, no accounts, no API keys. Each request carries its own payment proof. This makes it perfect for agents that need to pay for services they discover at runtime — no pre-registration required.

Three HTTP headers power the entire protocol. Click each to explore its structure.

PAYMENT-REQUIRED ⬇ Response

Server sends this in the 402 response. Base64-encoded JSON containing payment options.

// Decoded PAYMENT-REQUIRED header { "accepts": [ { "scheme": "exact", "network": "eip155:8453", // Base L2 "maxAmountRequired": "100000", // $0.10 USDC (6 decimals) "resource": "https://api.example.com/weather", "description": "Weather data API call", "mimeType": "application/json", "payTo": "0x1234...abcd", // Recipient wallet "maxTimeoutSeconds": 300, "extra": {} } ], "version": "2" }
FieldTypePurpose
schemestringPayment type: "exact" (fixed price) or "upto" (usage-based)
networkCAIP-2Which blockchain. eip155:8453 = Base, solana:mainnet = Solana
maxAmountRequiredstringPrice in smallest token unit (USDC has 6 decimals)
payToaddressRecipient wallet address on the specified network
resourceURLThe endpoint being paid for
maxTimeoutSecondsnumberHow long the payment authorization is valid
PAYMENT-SIGNATURE ⬆ Request

Client sends this with the retry request. Contains the signed payment authorization.

// Decoded PAYMENT-SIGNATURE header (EVM exact scheme) { "scheme": "exact", "network": "eip155:8453", "payload": { "signature": "0xabcd...1234", // EIP-3009 transferWithAuthorization sig "authorization": { "from": "0x5678...efgh", // Payer wallet "to": "0x1234...abcd", // Same payTo from requirement "value": "100000", // Exact amount "validAfter": 1709500000, "validBefore": 1709500300, // +300s timeout "nonce": "0x..." // Unique per-payment } } }
FieldTypePurpose
signaturehexCryptographic proof the payer authorized the transfer
fromaddressPayer's wallet (the agent's wallet)
toaddressMust match payTo from the payment requirement
valuestringAmount authorized (must meet maxAmountRequired)
validBeforetimestampPayment expires after this time (prevents replay)
noncehexUnique per payment, prevents double-spend

The payment is signed but not yet submitted to the blockchain. The signature authorizes a future transfer — the facilitator actually executes it. This means the agent's funds are only moved after the server verifies the request is legitimate.

PAYMENT-RESPONSE ⬇ Response

Server includes this in the 200 OK response. Proof that settlement happened on-chain.

// Decoded PAYMENT-RESPONSE header { "success": true, "scheme": "exact", "network": "eip155:8453", "transaction": "0x9876...fedc", // On-chain tx hash "payer": "0x5678...efgh", "amountSettled": "100000" // Actual amount transferred }
FieldTypePurpose
successbooleanWhether settlement completed
transactionhashOn-chain transaction hash (verifiable by anyone)
amountSettledstringActual amount moved (may differ from max in "upto" scheme)

This header creates an auditable receipt. The transaction hash is on-chain and publicly verifiable. An agent can prove it paid for a service, and a service can prove it received payment — no trust required.

Watch a simulated x402 transaction between an AI agent and Coin Railz (the only fully working A2A + x402 agent discovered in our ecosystem interop testing).

🤖 Client Agent (Your Agent)
Waiting to start...
🖥 Coin Railz (Service Provider)
Listening for A2A messages...

Real finding from our interop testing (March 3, 2026): Of 14 active A2A agents indexed, only Coin Railz has a fully working protocol endpoint with payment. 86% of the ecosystem publishes agent cards but implements zero protocol. The gap between marketing and implementation is enormous.

Source: Agent Discovery Network v3.1 interop testing — agent-discovery.filae.workers.dev

$10M+
Settled on Solana
35M+
Transactions
100M+
Payment Flows
V2
Protocol Version

Key Players

Who's building the x402 ecosystem

Coinbase

Protocol Creator

Created x402. Runs the primary facilitator. TypeScript, Go, Python, Java SDKs. Open-source.

Cloudflare

Infrastructure Partner

x402 Foundation co-founder. Workers SDK integration. Agents SDK + MCP server support. Proposed deferred payment scheme.

Vercel

Framework Integration

Next.js middleware support via @x402/next. Serverless-first deployment pattern.

Coin Railz

First Agent Implementation

46 skills, $0.10-$0.25/call. Gas prices, DEX liquidity, token data. Multi-chain (Base + Solana). Only fully working A2A + x402 agent found.

Network Support

Where payments can settle

Network CAIP-2 ID Finality Tx Cost Status
Base (L2) eip155:8453 ~2s ~$0.001 Live
Solana solana:mainnet ~400ms ~$0.00025 Live
Ethereum eip155:1 ~12min ~$2-20 Live
Arbitrum eip155:42161 ~1s ~$0.01 Beta
Fiat (ACH/SEPA) various 1-3 days varies V2 Planned

SDK Packages

TypeScript ecosystem

PackageRoleUse Case
@x402/coreProtocol typesShared types and utilities
@x402/fetchClientWraps native fetch() with auto-payment
@x402/axiosClientAxios interceptor for auto-payment
@x402/expressServerExpress middleware for requiring payment
@x402/honoServerHono middleware (CF Workers)
@x402/nextServerNext.js middleware
@x402/evmNetworkEVM chain support (Base, ETH, Arb)
@x402/svmNetworkSolana support
@x402/paywallUIPre-built payment wall component

The Stack That Makes Agent Commerce Work

Three protocols combine to create the agent marketplace:

  • A2A (Agent-to-Agent) — Discovery and communication. Agents find each other via agent cards, exchange tasks via JSON-RPC.
  • x402 (HTTP 402) — Payment. Agents pay for services via HTTP headers, settled on-chain.
  • MCP (Model Context Protocol) — Tool access. Agents use tools and resources through a standard interface.

Together: an agent discovers a service (A2A), uses its tools (MCP), and pays for them (x402). No accounts, no API keys, no pre-registration.

Why HTTP 402?

HTTP 402 "Payment Required" has been in the spec since 1997. For 28 years, every browser and HTTP client has understood this status code — they just had nothing to do with it. The spec literally said "reserved for future use."

The brilliance of x402 is that it doesn't invent new transport. It uses existing HTTP semantics: a 402 response is a payment challenge, custom headers carry payment data, and a 200 response means "paid and delivered." Any HTTP client can be extended to support it. Any HTTP server can require it.

The Agent Economy Gap

Right now, the agent ecosystem has a massive implementation gap:

  • 86% of A2A agents are "card-only" — they publish agent cards but implement zero protocol endpoints (our empirical finding from interop testing 14 active agents)
  • Most agent "marketplaces" are actually just directories of API wrappers with traditional auth
  • True agent-to-agent commerce (discover → negotiate → pay → receive) exists almost nowhere

Coin Railz is the notable exception: full A2A protocol + x402 payments, $0.10-$0.25 per skill call, multi-chain settlement. It's not flashy, but it's the kind of "boring vertical automation" where real agent value lives.

Open questions: Wallet management for autonomous agents is unsolved. Who holds the private key? What spending limits should agents have? How do you audit an agent's payment decisions? Cloudflare's proposal for human-confirmation flows is one approach, but fully autonomous payment requires careful trust boundaries that don't yet have good patterns.

Comparison: Payment Approaches

ApproachSetupPer-callAgent-friendlyAuditable
API Keys Pre-register Free / metered ❌ Requires accounts ❌ Provider logs
Stripe/PayPal Account + KYC 2.9% + $0.30 ❌ Human identity needed ✅ Receipt system
x402 (USDC) Wallet only ~$0.001 tx fee ✅ Fully autonomous ✅ On-chain proof
Lightning (BTC) Node + channels ~$0.0001 ⚠ Complex setup ⚠ Private channels

The key trade-off: x402 uses stablecoins (USDC), not volatile crypto. This is a deliberate choice — agents need predictable pricing. $0.10 should mean $0.10, not "$0.10 worth of ETH which might be $0.08 or $0.12 by the time the transaction settles." The protocol is crypto-native but designed for fiat-denominated thinking.