The HTTP 402 status code has been "reserved for future use" since 1999. Twenty-seven years later, that future arrived.
x402 transforms this dormant status code into a payment layer for the web. No OAuth flows. No API keys. No monthly invoices. Payments embedded directly into HTTP request/response cycles.
Why x402 Exists
Traditional payment infrastructure was designed for humans. Credit cards require fraud detection because humans commit fraud. Payment forms exist because humans need to enter information. Chargebacks exist because humans change their minds.
AI agents don't have these problems. They're deterministic, cryptographically authenticated, and operate at machine speed. But they're stuck using payment infrastructure optimized for human limitations.
Look at the overhead of a typical API monetization setup:
- User creates account
- User provides credit card
- Platform stores payment method
- API tracks usage
- Platform batches usage
- Monthly invoice generated
- Payment processed (2-3% fees)
- Potential chargebacks handled
- Reconciliation completed
This exists because processing individual transactions was historically expensive. Stripe charges $0.30 + 2.9% per transaction. For a $0.01 API call, that's a 3,000% fee.
x402 inverts this model. With Base L2 transaction costs around $0.0016 and payment verification in ~200ms (on-chain finality in ~2s), every request can carry its own payment. No accounts. No batching. No invoices.
The Protocol Specification
x402 extends HTTP with payment semantics. Server requires payment, responds with 402 and instructions. Client pays, retries.
The request-response flow
x402 payment flow
Initial request
Client sends GET /api/translate?text=hello
402 Payment Required
Server responds with payment headers: wallet address, amount, asset, network
Client pays
Client signs and broadcasts a USDC transaction on Base
Retry with proof
Client re-sends the same request with an X-Payment-Proof header attached
200 OK
Server verifies payment, executes the request, returns the result
Response headers (402)
X-Payment-Address
Recipient wallet address
0x742d35Cc6634C0532925a3b844Bc9e7595f...
X-Payment-Amount
Amount in atomic units
1000 (= $0.001 USDC)
X-Payment-Asset
Token identifier
USDC, ETH
X-Payment-Network
Blockchain network
base, base-sepolia
X-Payment-Timeout
Payment validity window (seconds)
300
Amount is specified in atomic units. For USDC (6 decimals), 1000 units = $0.001.
Request headers (retry with proof)
X-Payment-Proof
Transaction hash or signed payload
0xabc123...
X-Payment-Sender
Payer wallet address
0x8ba1f109...
The x402-hono Package
For production, x402-hono handles the heavy lifting:
import { Hono } from 'hono';
import { paymentMiddleware } from 'x402-hono';
import type { RoutesConfig } from 'x402-hono';
const app = new Hono();
const routes: RoutesConfig = {
'/api/translate': {
price: '$0.001', // $0.001 USDC
network: 'base',
config: { description: 'Translation service' }
}
};
app.use('/api/*', paymentMiddleware(process.env.WALLET_ADDRESS!, routes));
app.post('/api/translate', async (c) => {
const { text, target } = await c.req.json();
const translation = await translate(text, target);
return c.json({ translation });
});
export default app;
Network Selection
x402 works across EVM networks. Base is the current standard for production.
Why Base?
- Transaction costs: ~$0.0016 per transaction
- Settlement time: ~2 seconds
- Native USDC: Circle-issued, not bridged
- Coinbase backing: Enterprise-grade infrastructure
- x402 ecosystem: Most x402 tooling targets Base first
What's Next
You now have everything needed to implement x402 in production. The protocol is simple by design—HTTP plus blockchain verification.
Key takeaways:
- 402 response = payment requirements
- X-Payment-Proof header = payment verification
- Base network = optimal cost/speed tradeoff
- USDC = stable pricing for services
For hands-on implementation, check out x402 Tutorial: Your First Micropayment in 5 Minutes where we build a working payment flow from scratch.
The machine economy runs on x402. Time to build.
