What is x402?
x402 is an open payment protocol that enables HTTP-native micropayments. It repurposes HTTP status code 402 (“Payment Required”) — which has been reserved but unused since HTTP/1.1 (1999) — to create a standardized way for clients to pay for API access, content, or services on a per-request basis.
How x402 Works
The protocol defines a four-step flow:
- Client requests — A standard HTTP GET to a paid endpoint
- Server responds 402 — Returns a JSON body specifying the payment scheme, amount, asset, network, and recipient address
- Client pays — Signs a stablecoin transfer (typically USDC) matching the requirements, then retries the request with an
X-PAYMENTheader containing the signed payment - Server verifies & serves — Validates the cryptographic signature, settles the payment on-chain, and returns the requested data with HTTP 200
Key Properties
- No API keys: Authentication is replaced by payment. If you pay, you get the data.
- No accounts or signups: The client only needs a wallet with sufficient balance.
- Per-request pricing: Each endpoint can have different pricing. No subscriptions, no tiers.
- Cryptographic verification: Payments are signed using EIP-3009
transferWithAuthorization, allowing off-chain signature verification without an on-chain transaction per request. - Facilitator pattern: A neutral “facilitator” service handles payment verification and settlement, so the API provider doesn’t need to run their own payment infrastructure.
Use Cases
- Pay-per-request APIs: Risk scoring, data feeds, AI inference, file storage
- Content monetization: Pay-per-article, pay-per-download
- Agent-to-agent payments: AI agents paying for API access autonomously
Onchain Diary’s x402 Implementation
The Onchain Diary Risk API uses x402 for its premium tier:
| Endpoint | Price | Asset | Network |
|---|---|---|---|
/api/v1/risk/address/{address} | $0.01 | USDC | Base Sepolia (testnet) |
/api/v1/risk/token/{address} | $0.02 | USDC | Base Sepolia (testnet) |
/api/v1/gas | $0.005 | USDC | Base Sepolia (testnet) |
The implementation includes a self-hosted facilitator (/api/v1/facilitator/verify + /api/v1/facilitator/settle) that validates EIP-3009 signatures and settles payments on-chain.
For full integration details, see the Developer API documentation.