What is x402?
x402 is a micropayment protocol built on top of HTTP 402 (Payment Required). It enables instant, trustless micropayments for API access without complex blockchain interactions or gas fees for every request. Think of it as βpay-per-useβ for APIs, perfect for AI agents and automated trading.How It Works
1
Request
Client makes an API request to a protected endpoint.
2
402 Response
Server responds with
HTTP 402 Payment Required and payment details:- Cost in USDC
- Facilitator information
- Nonce for signature
3
Authorization
Client creates an EIP-3009 authorization signature:
- No gas fees
- Offline signing
- Single nonce per payment
4
Retry with Payment
Client retries request with payment signature in headers.
5
Verification
Facilitator verifies the signature and forwards request to server.
6
Settlement
After 300ms delay (anti-race condition), facilitator settles payment on-chain.
Key Features
Instant
Payments verified in milliseconds, no waiting for block confirmations
Trustless
EIP-3009 signatures are cryptographically secure
Gasless
Client doesnβt pay gas - facilitator handles settlement
Micropayments
Payments as low as $0.0001 are economically viable
EIP-3009: Transfer With Authorization
x402 uses EIP-3009 for gasless USDC transfers:Standard Transfer (Traditional)
EIP-3009 (x402)
Authorization Structure
x402 V2 (Current)
Network Format: CAIP-2
Version 2 uses CAIP-2 network identifiers:eip155:84532- Base Sepolia (testnet)eip155:8453- Base (mainnet)
Payment Header
Backward Compatibility
x402 V2 servers still accept V1 payments viaX-PAYMENT header for compatibility.
Facilitators
402.cat uses round-robin across multiple facilitators for reliability:| Facilitator | URL | Status |
|---|---|---|
| PayAI | facilitator.payai.network | Primary |
| httpcat | httpcat-facilitator.fly.dev | Secondary |
| x402.org | www.x402.org/facilitator | Tertiary |
| Railway | ts-2-facilitator-production.up.railway.app | Backup |
| Dexter | x402.dexter.cash | Backup |
| Coinbase CDP | api.cdp.coinbase.com | Optional (requires API key) |
Payment Flow
Example: Buying a Token
Cost Structure
Free Endpoints
No payment required:GET /healthGET /tokens(list all)GET /tokens/:id(token info - some details)GET /positionsGET /api/*(read-only endpoints)
Paid Endpoints
Require x402 payment:POST /tokens($0.01 - create)POST /entrypoints/token_buy_*(variable)POST /entrypoints/token_sell($0.01)POST /entrypoints/token_info($0.0001)POST /entrypoints/*(various costs)
Referral System
Earn 10% of all fees by setting theX-402-Referrer header:
- 10% of all fees from referred users
- Includes both x402 and trading fees
- Passive income from successful referrals
- Claimable once minimum threshold reached
Implementation
httpcat-cli Handles This Automatically
The CLI abstracts away all x402 complexity:Building Your Own Client
If building a custom client:Security
Nonce Protection
Nonce Protection
Each payment uses a unique nonce:
- Prevents replay attacks
- Cannot reuse signatures
- Validated on-chain
Signature Verification
Signature Verification
EIP-3009 signatures are:
- Cryptographically secure (ECDSA)
- Tied to specific parameters
- Verifiable on-chain
- Cannot be forged
Amount Limits
Amount Limits
Safety limits prevent accidents:
- Testnet: Max $0.20 per tx
- Mainnet: Max $200 per tx
- Client-side validation
- Server-side enforcement
Facilitator Trust
Facilitator Trust
Facilitators cannot:
- Steal funds (authorization is specific)
- Change amounts (signature validation)
- Reuse signatures (nonce tracking)
- Delay settlement (but not prevent)
- See payment details (transparent)
Benefits for AI Agents
Why x402 is Perfect for AI
- No Wallet UI: Agents canβt interact with MetaMask/wallet UIs
- Programmatic: Simple HTTP signatures
- Instant: No waiting for confirmations
- Gasless: Agents donβt manage gas fees
- Micropayments: Pay exactly for what you use
Example: AI Trading Agent
Comparison to Alternatives
| Feature | x402 | Traditional API Keys | On-Chain Only |
|---|---|---|---|
| Setup | Wallet only | Account registration | Wallet + gas |
| Cost | Pay per use | Subscription | Gas per tx |
| Speed | Instant | Instant | Block confirmation |
| Micropayments | β $0.0001+ | β Not economical | β Gas too high |
| Trustless | β Crypto signatures | β API key trust | β Blockchain |
| AI-Friendly | β Programmatic | β Programmatic | β Complex |