x402 payments explained: how AI agents pay with stablecoins
What the x402 protocol is, how an HTTP 402 payment works with server and client code, facilitators and fees, real adoption numbers, alternatives like MPP and AP2, and cost.
By Przemysław Paczoski, CEO & Founder at 23studio
Published 10 min read

x402 is an open payment protocol that uses the HTTP 402 Payment Required status code to let any client, including an AI agent, pay for an API call or web resource in stablecoins inside the request itself. The server answers 402 with a price, the client signs a payment and retries, and a facilitator settles it on-chain in about two seconds, without accounts or API keys.
This post explains how x402 works under the hood, shows a working server and client in TypeScript, covers facilitators, chains and fees, looks at how much real usage there is in 2026, compares x402 with Stripe and Tempo's MPP, Google's AP2 and Lightning's L402, and ends with what an integration costs.
What is x402?
Coinbase announced x402 on May 6, 2025 as an open standard for internet-native payments. HTTP has had a 402 status code reserved for payments since the 1990s, and nobody used it because there was no payment method that worked over HTTP without a human filling in a card form. Stablecoins on cheap chains filled that gap.
Governance moved out of Coinbase in 2026. Coinbase and Cloudflare first proposed an x402 Foundation in 2025, and the Linux Foundation announced its operational launch on July 14, 2026 with 40 member organizations. The 17 premier members include Visa, Mastercard, American Express, Stripe, Google, AWS, Cloudflare, Coinbase, Circle, Shopify and the Solana Foundation. That list matters more than any transaction count: card networks and cloud providers are building on it.
The reference implementation lives at github.com/coinbase/x402, with SDKs for TypeScript, Python, Go and Java.
How an x402 payment works
The flow has three parties: the client (a browser, a script or an agent), the resource server (your API), and a facilitator that checks and settles payments on-chain so your server doesn't need to run a node.
- The client requests a resource, for example
GET /weather. - The server replies
402 Payment Requiredwith aPAYMENT-REQUIREDheader. It lists what the server accepts: scheme, network, token, amount and the address to pay. - The client picks one option, signs a payment authorization with its wallet, and retries the request with a
PAYMENT-SIGNATUREheader. - The server sends the payload to the facilitator's
/verifyendpoint. If it's valid, the server does the work. - The server calls the facilitator's
/settleendpoint, which submits the transaction on-chain. - The server returns
200 OKwith the resource and aPAYMENT-RESPONSEheader containing the settlement result (including the transaction hash).
The client never sends a transaction itself and doesn't need gas. On EVM chains it signs an EIP-3009 transferWithAuthorization message (which USDC supports) or a Permit2 approval, and the facilitator submits it and pays the gas. Version 1 of the protocol, replaced by v2 in December 2025, used X-PAYMENT and X-PAYMENT-RESPONSE headers. You'll still see them in older tutorials.
Payment schemes
A scheme defines how money moves. The current spec has three:
exactpays a fixed amount per request. This is the default for paid API calls.uptoauthorizes a maximum, and the seller settles actual usage up to the cap. Useful for metered work like LLM tokens or compute time.batch-settlement(EVM only) uses escrow and off-chain vouchers, so many small charges are redeemed on-chain together. This makes sub-cent payments economical.
x402 code example: server and client
Here is a minimal paid endpoint in Express, adapted from the official example. It charges $0.001 per request in USDC on Base Sepolia (testnet).
import express from "express";
import { paymentMiddleware, x402ResourceServer } from "@x402/express";
import { ExactEvmScheme } from "@x402/evm/exact/server";
import { HTTPFacilitatorClient } from "@x402/core/server";
const payTo = process.env.EVM_ADDRESS as `0x${string}`;
// Testnet facilitator. For mainnet, use a production facilitator such as Coinbase CDP.
const facilitator = new HTTPFacilitatorClient({ url: "https://x402.org/facilitator" });
const app = express();
app.use(
paymentMiddleware(
{
"GET /weather": {
accepts: [
{ scheme: "exact", price: "$0.001", network: "eip155:84532", payTo },
],
description: "Current weather data",
mimeType: "application/json",
},
},
new x402ResourceServer(facilitator).register("eip155:84532", new ExactEvmScheme()),
),
);
app.get("/weather", (_req, res) => {
res.json({ weather: "sunny", temperature: 21 });
});
app.listen(4021);
Networks use CAIP-2 identifiers (eip155:8453 is Base mainnet, eip155:84532 is Base Sepolia, Solana networks start with solana:). You can list several entries in accepts to take payment on more than one chain. Packages also exist for Fastify, Hono and Next.js.
And a client that pays automatically, adapted from the fetch example:
import { x402Client, wrapFetchWithPayment, x402HTTPClient } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const signer = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);
const client = new x402Client();
client.setSpendControls({ maxAmountPerPayment: "$1" });
client.register("eip155:*", new ExactEvmScheme(signer));
const fetchWithPayment = wrapFetchWithPayment(fetch, client);
const response = await fetchWithPayment("http://localhost:4021/weather");
const result = await new x402HTTPClient(client).processResponse(response);
console.log(result);
wrapFetchWithPayment catches the 402, picks a payment option the client supports, signs it and retries. setSpendControls is the line you must not skip in an agent: it caps what a single call can spend. For agents built on MCP, the @x402/mcp package lets tools charge per call in the same way.
In production, keep the agent's key in a smart account or a managed wallet with spending limits rather than a raw private key. Session keys and spending policies on smart accounts (ERC-4337 and EIP-7702) are a good fit, because they let you cap what an agent can spend per day and per counterparty without handing it the main wallet.
Facilitators, chains and fees
You can run your own facilitator, but most teams use a hosted one. Coinbase's CDP facilitator is the largest. Per its documentation:
- Mainnets: Base, Polygon, Arbitrum, Monad, World and Solana
- Tokens: any ERC-20 that supports EIP-3009 or Permit2 on the EVM side, and SPL tokens on Solana. In practice almost everyone uses USDC.
- Fees: the first 1,000 on-chain settlements per month are free, then $0.001 each. Verification is free. With
batch-settlement, one on-chain transaction can cover thousands of payments. - Compliance: payments involving sanctioned or high-risk addresses are declined through OFAC and KYT screening.
Other facilitators compete on chains and features, and the protocol is designed so a server can switch between them. Facilitator quality varies, so test settlement failures and timeouts before trusting one with production traffic.
How much is x402 actually used?
Less than the headlines suggest. Coinbase says CDP has processed more than 100 million x402 payments and $28 million in volume across Base and Solana. Trackers counted over 200 million x402 transactions across facilitators by June 2026.
But most of that isn't commerce. A Forkast analysis citing Artemis data found more than 95% of the volume was protocol signalling rather than buyer-seller payments, with wash trading and self-dealing a large share, and CoinDesk put real commercial volume around $28,000 a day in March 2026. Adjusted volume also fell sharply from its late-2025 peak, when token speculation around x402 inflated the numbers.
Our read: x402 is early infrastructure with unusually strong backing. The membership of the foundation, Cloudflare's products and the card networks' involvement are the signals to watch. Transaction counts aren't. If you build on it now, build because your product needs per-request payments, not because you expect agent traffic to arrive on its own.
Use cases
Paid APIs without accounts. Data feeds, search, inference, PDF conversion, on-chain analytics. A caller pays per request and skips signup, API keys and invoicing. This is the cleanest fit today.
Pay-per-crawl and content access. Cloudflare's Monetization Gateway, in closed beta since late September 2026, lets site owners charge AI agents per request for pages, APIs, MCP tools or datasets, settled in USDC on Base through Coinbase's facilitator. Cloudflare also proposed a deferred payment scheme where requests are signed per call and settled later in batches, aimed at its pay per crawl product.
Agent-to-agent payments. One agent buys a service from another: a research agent paying a specialised data agent, or an orchestrator paying tool providers. Google's agent protocols support this through the A2A x402 extension.
Micropayments for humans. Paying a few cents to read one article or run one query. The protocol works for people too, though wallet UX still decides whether they'll do it.
Agents that manage money in DeFi are a different and riskier use. Our DeFAI guide covers where AI agents handling yields make sense and where they don't.
x402 vs MPP vs AP2 vs L402
| Protocol | Backed by | Payment rails | How it works | Best fit |
|---|---|---|---|---|
| x402 | x402 Foundation (Linux Foundation), started by Coinbase | Stablecoins on EVM chains, Solana and others | HTTP 402 with signed on-chain payment, facilitator settles | Paid APIs, agent tools, crawl access |
| MPP (Machine Payments Protocol) | Stripe and Tempo | Stablecoins on Tempo, cards via Visa, Bitcoin via Lightspark | Sessions with spending limits, not one on-chain transaction per action | Businesses already on Stripe |
| AP2 (Agent Payments Protocol) | Cards, bank transfers, stablecoins via the x402 extension | Signed "mandates" that prove a user authorized an agent's purchase | Agent shopping on behalf of a person | |
| L402 | Lightning Labs | Bitcoin over Lightning | HTTP 402 with a Lightning invoice and a macaroon-style token | Bitcoin-native services |
MPP launched with Tempo's mainnet on March 18, 2026. Stripe businesses can accept MPP payments through PaymentIntents, which is the big draw: settlement lands in the same Stripe account as card revenue. AP2, announced by Google in September 2025, works at a different layer. It's about proving that a human authorized an agent to buy something, and it can use x402 for the stablecoin leg. L402 is the older Lightning approach, and Lightning Labs repositioned it for agents in 2026 with new client tooling.
They're not mutually exclusive. Stripe is a premier member of the x402 Foundation and co-authors MPP. If you're selling an API, supporting x402 is cheap and opens you to most crypto-native agent clients. Add MPP if your customers are Stripe merchants or you want card fallback.
How to integrate x402 into your product
- Decide what's priced per request. Endpoints with a clear unit of value and low marginal cost are good candidates. Keep subscriptions for heavy users.
- Pick chains and a facilitator. Base and Solana have the most clients today. Use a hosted facilitator unless you have a reason to run one.
- Set up receiving wallets. A multisig or custodial business account for treasury, plus accounting that can reconcile thousands of small on-chain payments with requests.
- Add the middleware to the routes you want to charge for, and publish them in discovery listings so agents can find them.
- Handle failure cases. Facilitator timeouts, payments that verify but fail to settle, refunds for failed work, and rate limits so an unpaid flood doesn't cost you compute.
- If you're building the agent side, give it a wallet with hard spending caps, an allowlist of payees, and logs a human can audit.
For the treasury and accounting side, including off-ramps, tax and the compliance obligations of receiving stablecoins, see our guide to stablecoin payments integration.
How much does an x402 integration cost?
| Scope | What's in it | Cost | Timeline |
|---|---|---|---|
| PoC | x402 middleware on a few endpoints, hosted facilitator, testnet, simple dashboard | $5,000 to $15,000 | 1 to 3 weeks |
| MVP | Mainnet on one or two chains, pricing config, payment logs and reconciliation, refunds, discovery listing | $20,000 to $50,000 | 4 to 8 weeks |
| Production platform | Multi-chain, upto or batch settlement, agent wallets with spending policies, MPP or card fallback, analytics, security review | $60,000 to $150,000+ | 2 to 5 months |
What moves the cost: whether you need custom smart contracts (escrow, batch settlement, spending policies) that require an audit, how many chains you support, how deep the accounting integration goes, and whether you're building the agent wallet side as well. Running costs are low: facilitator fees of $0.001 per settlement after the free tier, plus gas when batching isn't used. You can get a ballpark for your own scope from our cost calculator.
Frequently asked questions
Is x402 only for crypto users?
The payment itself is in stablecoins, so the payer needs a wallet with USDC or similar. The wallet can be an embedded or managed wallet the user never sees, and for agents it's usually a server-side wallet. Cloudflare's gateway and Stripe's involvement are pushing toward setups where the seller doesn't have to touch crypto directly.
Does the client need ETH or SOL for gas?
No. The client signs an authorization and the facilitator submits the transaction and pays the gas. The client only needs the token it pays with.
What's the difference between x402 v1 and v2?
The v2 specification, published on December 9, 2025, renamed the headers to PAYMENT-REQUIRED, PAYMENT-SIGNATURE and PAYMENT-RESPONSE, switched to CAIP-2 network identifiers and added support for extensions. The SDK was split into packages per chain and framework. If a tutorial uses X-PAYMENT, it's written for v1.
Is x402 secure for autonomous agents?
The protocol is sound: payments are signed for a specific amount, payee and time window, so a server can't take more than the agent approved. The risk is the agent paying for things it shouldn't. Cap spending per payment and per day, allowlist payees, and keep keys in a wallet with policies rather than a raw private key.
Can I charge for an MCP server with x402?
Yes. The @x402/mcp package lets MCP tools require payment per call, and Cloudflare's Monetization Gateway can charge for MCP tools behind its network. It's one of the more practical uses today.
How fast is x402 settlement?
Around two seconds on Base and Solana. With upto or batch settlement, the request can return before the final on-chain settlement, which lowers latency further.
Build it with us
We build dApps, wallets and payment flows on EVM chains and Solana, including agent-facing products like DeSwarm's AI DeFi terminal. If you want to charge agents for your API or give your agent a wallet that can pay safely, see our decentralized application development services or get in touch.
Keep reading

How to accept stablecoin payments: a 2026 integration guide
Processor or direct wallet integration, which chains to support, what MiCA and the GENIUS Act mean for merchants, and how to keep accounting and refunds sane.

How to create a stablecoin in 2026: models, rules, build and cost
How to create a stablecoin in 2026: fiat-backed, crypto-backed or white-label issuance, what the GENIUS Act and MiCA require, the contracts you need, and what each path costs.

The Stablecoin Revolution: How Digital Dollars Are Reshaping Global Finance
A $298B market led by USDT and USDC, yield-bearing stablecoins, payment use cases, and how MiCA and the US GENIUS Act now regulate digital dollars.