x402 (HTTP 402)
HTTP 402 commerce and x402 payments for machine-payable APIs
Overview
x402 brings payments back into the web’s native path: the request/response loop. Your API returns 402 Payment Required with a machine-readable hint. The client pays, presents a receipt, and retries.
A simple pattern: servers challenge with HTTP 402, clients pay and come back with a verifiable receipt. No accounts, no dashboards - just HTTP.
What is x402?
x402 standardizes the challenge and the proof so automated clients (including AI agents) can transact without out-of-band flows. HTTP 402 sat unused for decades. Today it’s being put to work for APIs and content: a first-class signal that payment is needed before the resource is returned.
Treat it like a capability, not a paywall - a programmable way to meter access fairly.
Getting Started with x402
Implementing x402 in your API takes three steps: return a 402 response with payment details, accept payment receipts, and verify those receipts before granting access. The protocol is designed to work with any payment rail - from traditional payment gateways to cryptocurrency wallets to stablecoins.
Start by protecting a single API endpoint with a 402 challenge. When clients request that endpoint without payment, return status code 402 with a JSON payload containing the amount, currency, and a unique reference ID. Clients use this information to complete payment off-band, then retry the request with a verifiable receipt.
For AI agents and autonomous systems, x402 enables fully automated payment flows. Agents can parse the 402 response, execute payment through their configured wallet or payment provider, and retry the request - all without human intervention. This makes x402 ideal for agent-to-agent commerce, API marketplaces, and usage-based pricing models in the agentic economy.
The Flow: Client → 402 → Pay → Receipt → Access
- Client requests a priced resource.
- Server responds
402with a payment hint (amount, currency, reference). - Client pays using the hinted rail, obtains a receipt/proof.
- Client retries with the receipt in headers or body.
- Server verifies the receipt and returns the resource with standard
2xx.
Keep the 402 payload small and explicit. Include a stable reference the server can match later.
Try it now:
curl -i https://www.originary.xyz/api/x402-demoMinimal 402 Response
A compliant 402 response with a JSON payment hint:
HTTP/1.1 402 Payment Required
Content-Type: application/json; charset=utf-8
Cache-Control: no-store
{
"detail": "Payment required to access this resource.",
"payment": {
"protocol": "x402",
"amount": "0.10",
"currency": "USDC",
"reference": "demo-402-abc123",
"instructions": "Pay using your client wallet and present a receipt in the follow-up request."
}
}Server Examples
Choose your stack and implement x402 in under 15 minutes:
- → Express (Node)
Add 402 to your Express API
- → Next.js / Edge Runtime
Route handlers with 402 challenges
- → Cloudflare Workers
Tiny Worker returning HTTP 402
- → FastAPI (Python)(coming soon)
Receipts: Structure & Verification
A receipt ties the payment to your resource request. Keep two checks:
- The cryptographic or gateway proof
- Your own ledger mapping
reference → entitlement
Return explicit errors for expired/insufficient proofs.
See Model Context Protocol (MCP), Agentic Commerce Protocol (ACP), and Agent-to-Agent (A2A) for receipt integration patterns.
Choosing Rails: x402 vs Arc vs Tempo
The right rail depends on your currency, fee model, and developer footprint. Start with what your customers already hold (e.g., stablecoins), then optimize for verification latency and dispute handling. We will maintain a running comparison as the space evolves.
Postman + OpenAPI
Frequently Asked Questions
What does HTTP 402 do here?
It signals that payment is required and supplies just enough machine-readable detail for a client to pay and retry.
Can I keep my existing auth?
Yes. 402 sits alongside your auth. You can charge only for specific routes or tiers.
Do I need stablecoins?
No. x402 is rail-agnostic. Stablecoins are common, but you can integrate any payment rail that issues a verifiable receipt.
Ready to implement x402?
Start with one of our stack guides above, or explore developer tools for x402 receipts and verification.
View Pricing