What is x402?
The x402 protocol enables pay-per-call HTTP APIs using blockchain micropayments. It’s based on the HTTP 402 “Payment Required” status code, which was originally reserved but never standardized.Key Concept: Instead of subscriptions or API keys, services charge per-request. Users pay only for what they use.
How x402 Works
Standard HTTP 402 Flow
x402 in Arcana
Two Payment Layers
Arcana implements a two-tier payment system:User → Backend
Upfront Query PaymentUsers pay $0.03 USDC to the backend orchestrator before asking questions.This covers:
- AI orchestration (Gemini API)
- Multiple agent calls
- Response synthesis
- Infrastructure costs
Backend → Agents
Per-Call Agent PaymentsBackend pays each agent per-call using x402:
- Oracle: $0.01 per price lookup
- Scout: $0.01 per on-chain query
- News: $0.01 per news search
- Yield: $0.01 per yield search
- Tokenomics: $0.02 per analysis
- NFT: $0.02 per collection lookup
- Perp: $0.02 per market data
Protocol Versions
x402 supports two protocol versions:- Version 1 (Legacy)
- Version 2 (Current)
Payment requirement in response body
Used by older agent implementations. Still supported for backward compatibility.
Payment Schemes
Exact Scheme
The exact scheme requires precise payment amounts:- Payment must match the exact amount specified
- No overpayment or underpayment accepted
- Simplest and most predictable scheme
All Arcana agents currently use the exact scheme for predictable pricing.
Future Schemes
The x402 protocol supports extensible schemes:- Range: Accept payments within a range (min/max)
- Auction: Dynamic pricing based on demand
- Subscription: Time-based access passes
- Bundle: Bulk purchase discounts
Facilitator Service
The x402 Facilitator is a third-party service that simplifies payment verification:Facilitator URL
- Payment verification services
- Transaction settlement tracking
- Receipt generation
- Dispute resolution
How the Facilitator Works
Payment Verification
Payment Verification
- Checks transaction status on-chain
- Validates payment amount and recipient
- Generates cryptographic proof
- Returns settlement ID
Settlement Tracking
Settlement Tracking
- Tracks payment lifecycle
- Stores settlement metadata
- Enables refund/dispute resolution
- Provides audit trail
Receipt Generation
Receipt Generation
- Issues tamper-proof receipts
- Includes payment proof
- Links to on-chain transaction
- Supports accounting/tax reporting
Pinion Runtime Integration
Arcana uses Pinion (a Coinbase x402 runtime) to manage agent payments:Pinion Features
Automatic Wallets
Provisions CDP wallets for each agent automatically
Payment Flow
Handles preflight, payment, and retry logic
Spend Limits
Enforces session and daily spending caps
Receipt Logging
Persists all payment receipts to Supabase
Session Spend Limits
Pinion tracks spending per-session:Procurement & Provider Scoring
Arcana implements a procurement layer that ranks and selects the best agent provider:Provider Scoring Algorithm
Success Rate (35%)
Success Rate (35%)
Percentage of successful calls (status 200-299)Higher success rate = higher score
Schema Rate (15%)
Schema Rate (15%)
Percentage of responses that match expected schemaValidates that agents return well-formed data
Quality Score (20%)
Quality Score (20%)
Composite score based on:
- Data completeness
- Response structure
- Error rate
Latency Score (15%)
Latency Score (15%)
Response time normalized to 0-1 scaleFaster responses = higher score
Price Score (15%)
Price Score (15%)
Payment amount normalized to 0-1 scaleLower prices = higher score
Circuit Breaker
The procurement system includes a circuit breaker to prevent cascading failures:x402 vs Traditional APIs
Traditional API
Pros:
- Simple authentication
- No blockchain required
- Instant access
- Requires API key management
- Monthly subscriptions
- Vendor lock-in
- No micropayments
x402 Protocol
Pros:
- Pay per use
- No subscriptions
- Blockchain-verified payments
- Trustless verification
- Requires crypto wallet
- On-chain transaction fees
- More complex integration
Example: Oracle Agent Call
Here’s a complete x402 flow for calling the Oracle agent:Resources
x402 Specification
Official protocol specification and standards
Coinbase x402 Docs
Coinbase Developer Platform x402 documentation
Pinion Runtime
Pinion runtime library for x402 payments
Payment Flow
See the complete payment flow in Arcana