x402 (HTTP 402)
Implement internet-native payments in minutes
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.
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.
x402 vs L402
L402 couples Lightning and macaroons for auth and payment in one flow. x402 is HTTP-native and rail-agnostic.
Choose L402 for Lightning-first ecosystems; choose x402 when you want chain/gateway flexibility and simple HTTP semantics.
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