x402 is an open protocol for internet-native payments that implements HTTP’s long-reserved 402 Payment Required status code. When a client requests a paid resource, the server returns 402 with payment requirements; the client pays with stablecoins (USDC) and retries. No accounts, no API keys, no subscriptions — just HTTP and cryptographic wallets. x402 has processed 75M+ transactions totaling $24M+ since launch.
TL;DR
- x402 implements HTTP 402 Payment Required for instant machine-to-machine payments
- Uses stablecoins (primarily USDC) — no accounts, no API keys, no subscriptions needed
- Supports Base, Solana, Polygon with ~$0.01 transaction costs
- Already adopted by Coinbase, Cloudflare, Google (AP2), Vercel
- SDKs available for TypeScript, Python, Go — add payments with minimal code changes
The internet was built without a payment layer. HTTP has status codes for everything - 404 for not found, 500 for server errors - but 402 Payment Required was reserved and never implemented. Until now.
x402 is an open protocol that finally makes HTTP 402 real. AI agents can pay for APIs instantly with stablecoins, no accounts needed, no API keys to manage. It’s already processed over 75 million transactions across APIs, web applications, and autonomous agents.
This guide covers everything: what x402 is, how it works, how to implement it, and what it means for the agent economy.
What is x402?
x402 is an open standard for internet-native payments built on HTTP. When a client requests a protected resource, the server responds with HTTP 402 Payment Required. The client pays, retries the request, and gets access.
The basics:
- Built on the long-reserved HTTP 402 status code
- Uses stablecoins (primarily USDC) for instant settlement
- No accounts, no API keys, no subscriptions
- Works across multiple blockchains
- Designed for AI agents and machine-to-machine payments
Developed by Coinbase, x402 has been adopted by Cloudflare, Google (as part of AP2), Vercel, and hundreds of API providers. Since launching, it’s processed:
| Metric | Value |
|---|---|
| Transactions | 75M+ |
| Volume | $24M+ |
| Buyers | 94K+ |
| Sellers | 22K+ |
How x402 Works
The protocol is elegantly simple. Here’s the complete flow:
Step 1: Client Makes Request
GET /api/weather HTTP/1.1
Host: api.example.com
Step 2: Server Returns 402
HTTP/1.1 402 Payment Required
X-PAYMENT-REQUIRED: eyJhbW91bnQiOiIwLjAxIiwiY3VycmVuY3kiOiJVU0RDIi4uLn0=
The X-PAYMENT-REQUIRED header contains a base64-encoded JSON payload with:
- Payment amount
- Recipient address
- Supported networks
- Payment reference
Step 3: Client Pays and Retries
GET /api/weather HTTP/1.1
Host: api.example.com
X-PAYMENT: eyJzaWduYXR1cmUiOiIweDEyMzQ1Njc4Li4uIn0=
The X-PAYMENT header contains the signed payment payload.
Step 4: Server Verifies and Responds
HTTP/1.1 200 OK
X-PAYMENT-RESPONSE: eyJzdGF0dXMiOiJzZXR0bGVkIi4uLn0=
Content-Type: application/json
{"temperature": 72, "conditions": "sunny"}
That’s it. Four HTTP messages, instant payment, content delivered.
The Complete Payment Flow
For the technically curious, here’s the full 12-step process:
| Step | Action |
|---|---|
| 1 | Client requests protected resource |
| 2 | Server returns 402 with payment requirements |
| 3 | Client selects payment scheme and creates PaymentPayload |
| 4 | Client retries with X-PAYMENT header |
| 5 | Server verifies payment via facilitator’s /verify endpoint |
| 6 | Facilitator validates based on scheme and network |
| 7 | Server performs the requested work |
| 8 | Server settles payment via blockchain or facilitator |
| 9 | Facilitator submits transaction to blockchain |
| 10 | Facilitator awaits confirmation |
| 11 | Facilitator returns Payment Execution Response |
| 12 | Server returns 200 OK with content |
Key Concepts
Schemes: A logical way of moving money. The exact scheme requires a specific amount. Future schemes may support subscriptions, metered billing, or auctions.
Networks: Blockchain implementations. Base, Solana, Polygon each have different implementations of the same scheme.
Facilitators: Servers that handle verification and settlement. They can only execute transactions authorized by the client’s signed payment payload - ensuring funds move only according to client intent.
Supported Networks
x402 is network-agnostic by design. Current support includes:
Production Networks
| Network | Identifier | Token Support |
|---|---|---|
| Base | eip155:8453 | USDC, any EIP-3009 token |
| Solana | solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp | USDC, all SPL tokens |
| Polygon | eip155:137 | USDC, any EIP-3009 token |
| Avalanche | eip155:43114 | USDC |
| Sei | Coming soon | - |
Test Networks
| Network | Identifier | Notes |
|---|---|---|
| Base Sepolia | eip155:84532 | Free via x402.org facilitator |
| Solana Devnet | solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1 | Free via x402.org facilitator |
Why Base is Popular
Base has become the default network for x402 because:
- Transaction fees around $0.01
- Sub-second finality
- Native USDC support
- Coinbase backing
Implementation Guide
For API Providers (Server-Side)
Implementing x402 requires minimal code changes. Here’s how to protect an endpoint:
Install the SDK:
npm install @x402/core @x402/evm @x402/express
Add the middleware:
import express from 'express';
import { paymentMiddleware } from '@x402/express';
const app = express();
app.use(paymentMiddleware({
"GET /api/weather": {
price: "0.01",
currency: "USDC",
network: "base",
recipient: "0xYourWalletAddress",
description: "Weather data access"
},
"GET /api/premium/*": {
price: "0.10",
currency: "USDC",
network: "base",
recipient: "0xYourWalletAddress",
description: "Premium API access"
}
}));
app.get('/api/weather', (req, res) => {
res.json({ temperature: 72, conditions: 'sunny' });
});
That’s a complete implementation. The middleware handles 402 responses, payment verification, and settlement automatically.
For AI Agents (Client-Side)
Agents need to handle 402 responses and execute payments. Here’s the pattern:
Install the SDK:
npm install @x402/fetch @x402/evm
Make paid requests:
import { createX402Client } from '@x402/fetch';
import { privateKeyToAccount } from 'viem/accounts';
const account = privateKeyToAccount(process.env.PRIVATE_KEY);
const client = createX402Client({ account, network: 'base' });
// This handles everything - 402 detection, payment, retry
const response = await client.fetch('https://api.example.com/api/weather');
const data = await response.json();
MCP Server Integration
For Claude and other AI assistants using Model Context Protocol:
import { withPaymentInterceptor } from '@x402/axios';
import { privateKeyToAccount } from 'viem/accounts';
import axios from 'axios';
const account = privateKeyToAccount(process.env.WALLET_KEY);
const client = withPaymentInterceptor(
axios.create({ baseURL: 'https://api.example.com' }),
account
);
// MCP tool definition
server.tool(
"get-weather-data",
"Get weather data (costs $0.01 USDC)",
{},
async () => {
const res = await client.get('/api/weather');
return {
content: [{ type: "text", text: JSON.stringify(res.data) }],
};
},
);
When Claude calls get-weather-data, the MCP server:
- Makes the request
- Receives 402 response
- Signs payment with its wallet
- Retries the request
- Returns the data
No human intervention required.
SDK Reference
Available Packages
TypeScript/JavaScript:
| Package | Purpose |
|---|---|
@x402/core | Core types and utilities |
@x402/evm | EVM chain support (Base, Polygon, etc.) |
@x402/svm | Solana support |
@x402/fetch | Fetch client with payment handling |
@x402/axios | Axios interceptor for payments |
@x402/express | Express middleware |
Python:
pip install x402
Go:
go get github.com/coinbase/x402/go
API Key Formats
x402 doesn’t use API keys in the traditional sense. Instead, it uses cryptographic wallets:
| Network Type | Wallet Format |
|---|---|
| EVM (Base, Polygon) | Ethereum address (0x...) |
| Solana | Solana pubkey (base58) |
Pricing and Economics
Protocol Fees
x402 has zero protocol fees. The costs are:
| Component | Cost |
|---|---|
| Protocol fee | $0.00 |
| CDP Facilitator (Coinbase Developer Platform) | First 1,000/month free, then $0.001 each |
| Network gas | Varies by chain (~$0.01 on Base) |
Pricing Strategy for Providers
Since fees are minimal, you can price granularly:
| Use Case | Typical Price |
|---|---|
| Weather API call | $0.001 - $0.01 |
| AI inference | $0.01 - $0.10 |
| Data export | $0.10 - $1.00 |
| Premium report | $1.00 - $10.00 |
The significantly lower fees compared to credit cards (typically 2.9% + $0.30) make practical micropayments viable at scale.
Security Considerations
For API Providers
- Verify payments before serving content - Always wait for settlement confirmation
- Use facilitators for production - They handle chain-specific edge cases
- Implement idempotency - Payment references should be unique per request
- Set reasonable timeouts - 30 seconds is the recommended limit
For Agent Operators
- Protect private keys - Store in environment variables or secure vaults
- Set spending limits - Implement maximum per-transaction and daily limits
- Log all payments - Maintain audit trails for debugging and accounting
- Use testnets first - Base Sepolia and Solana devnet are free
Trust Model
x402 is designed to be trust-minimizing:
- Clients sign payments - Facilitators can’t move funds without signatures
- Payment references are unique - Prevents replay attacks
- Amounts are explicit - No hidden fees or charges
- Open protocol - Anyone can verify the implementation
Real-World Implementations
Circle Labs Demo
Circle built a demo where an AI agent autonomously pays $0.01 USDC to retrieve a blockchain risk report:
Agent: "What's the risk score for 0x1234...?"
→ API returns 402
→ Agent pays $0.01 USDC
→ API returns risk report
→ Agent: "The risk score is 42, classified as low risk."
Cloudflare Workers
Cloudflare’s x402 integration lets you protect Workers with one line:
export default {
async fetch(request, env) {
// x402 middleware handles payment
return new Response('Premium content here');
}
}
Telegram Bots
Production bots are using x402 for premium content:
@bot.message_handler(commands=['premium'])
async def premium_content(message):
# Bot's wallet automatically handles x402 payments
data = await x402_client.get('/api/premium-report')
await bot.send_message(message.chat.id, data)
How Does x402 Compare to Traditional Payment Systems?
| Feature | x402 | Stripe/Traditional |
|---|---|---|
| Setup time | Minutes | Days-weeks |
| Per-transaction fee | ~$0.01 | 2.9% + $0.30 |
| Minimum viable amount | $0.001 | ~$0.50 (fee-limited) |
| Account required | No | Yes |
| KYC for users | No | Often |
| Settlement time | Seconds | Days |
| Chargebacks | Impossible | Common |
| API key management | None | Required |
The Google AP2 Integration
In early 2026, Google announced the Agents Payment Protocol (AP2), a universal standard for AI agent payments. x402 is included as the A2A x402 extension for crypto payments.
This means:
- Google’s AI agents can use x402 natively
- Enterprise adoption is accelerating
- The protocol has institutional backing beyond Coinbase
Getting Started: Quick Reference
Test on Devnet
# No API key needed for testing
curl -X GET "https://testapi.x402.org/weather" \
-H "Accept: application/json"
# Returns 402 with payment requirements
# Use x402 SDK to handle payment automatically
Production Checklist
- Choose a network - Base is recommended for most use cases
- Set up a wallet - Coinbase Wallet or any EVM wallet works
- Fund with USDC - Bridge from your exchange
- Install SDK -
npm install @x402/fetch @x402/evm - Implement client - Use the code examples above
- Test on devnet - Use Base Sepolia first
- Deploy to production - Switch to Base mainnet
Facilitator Endpoints
| Environment | URL |
|---|---|
| Production (Coinbase Developer Platform) | https://facilitator.cdp.coinbase.com |
| Testnet (Free) | https://facilitator.x402.org |
FAQ
Is x402 only for AI agents? No. Any HTTP client can use x402. But it’s particularly useful for agents because they can’t use credit cards or manage subscriptions.
What if the payment fails?
The server returns an error in the X-PAYMENT-RESPONSE header. Your client should handle this gracefully and potentially retry.
Can I use fiat currency? x402 v2 added extensibility for additional payment schemes, but stablecoins remain the primary mechanism. Fiat support depends on facilitator capabilities.
Is this legal? Using stablecoins for API payments is legal in most jurisdictions. The usual advice: check local regulations, don’t do anything illegal.
What about refunds? There’s no built-in refund mechanism. Service providers handle refunds off-protocol if needed.
How do I track revenue? Monitor your recipient wallet address. Tools like Basescan, Solscan, and Dune Analytics work for reporting.
The Bottom Line
x402 solves a real problem: how do machines pay other machines? The answer turned out to be simple - use HTTP the way it was designed, with payments as a first-class citizen.
For API providers, x402 means instant monetization with minimal code changes. For AI agents, it means autonomous access to paid services without human intervention.
The protocol is live, it’s growing, and it’s being adopted by major platforms. If you’re building anything in the agent economy, you should understand x402.
Have questions about x402? Subscribe to MoltNews for ongoing coverage of the agent ecosystem.
Sources:
- x402.org - Official protocol documentation
- Coinbase CDP Documentation - Network support details
- Base Documentation - Agent implementation guide
- Zuplo Blog - MCP server integration
- GitHub - coinbase/x402 - Open source implementation



Discussion