What is X402?
X402 is an HTTP payment protocol that uses the402 Payment Required status code to enable machine-to-machine payments. It allows servers to request payment from clients using standardized headers and payload formats.
Think of it as “Stripe for the programmable internet” - agents, robots, and autonomous systems can pay for API access, compute time, or any HTTP resource.
Payment Schemes
X402 v2 supports multiple payment schemes:exact
Immediate settlement - payment happens instantly when request is made.Best for: Simple purchases, low-value transactions, trusted services
escrow
Deferred settlement - funds locked until conditions are met.Best for: High-value transactions, usage-based billing, long-running tasks
Why Escrow?
Theexact scheme works well for immediate-delivery payments, but creates friction for:
High-Value Transactions
Problem: No recourse if service fails after paymentVariable Pricing
Problem: Usage-based billing requires estimating upfront Consider an LLM agent making API calls:- Unknown final cost (depends on tokens used)
- Can’t pay exact amount in advance
- Server needs guarantee of payment
Long-Running Tasks
Problem: Work takes hours or days to completeMulti-Request Sessions
Problem: Signing 1,000 individual requests is impracticalHow x402r Extends X402
x402r provides the escrow scheme implementation for x402:-
Base Commerce Payments Integration
- Audited escrow contracts from Base
- Auth/capture pattern for deferred settlement
- On-chain safety guarantees
-
Operator Contracts
- Conditional release logic
- Dispute resolution
- Fee distribution
- Time-based release
-
Payment Facilitator
- Validates ERC-3009 signatures
- Settles authorizations on-chain
- Tracks payment state
-
Developer Tools
- TypeScript SDK
- Deployment scripts
- Example implementations
Payment Flow
Use Cases
AI Agent API Access
AI Agent API Access
LLM agent needs to call external APIs with variable token costs.Flow:
- Agent authorizes $20 max
- Makes 50 API calls totaling $12.50
- Server captures $12.50
- Agent reclaims unused $7.50
Compute Marketplace
Compute Marketplace
Client needs GPU cluster for training job.Flow:
- Client authorizes $500 for 48-hour job
- Training completes in 36 hours ($375)
- Client verifies results
- Operator releases 125
Data Access Sessions
Data Access Sessions
Application needs access to real-time data feed.Flow:
- App authorizes $100 for monthly access
- Provider streams data
- Provider captures $3.33 daily (30-day billing)
- Automatic refund if service interrupted
Freelance Services
Freelance Services
Client hires developer for project work.Flow:
- Client authorizes $2000 in escrow
- Developer completes milestones
- Arbiter verifies each milestone
- Operator releases payment on approval
- Dispute resolution if disagreement
Key Concepts
Authorization
Lock funds in escrow without immediate transfer. Client signs an ERC-3009 authorization allowing the escrow contract to pull tokens.Capture
Release authorized funds to the receiver. The operator contract decides when and how much to release based on configured conditions.Void
Return funds to payer before capture. Used for full refunds during the escrow period.Reclaim
Safety valve for payer. If authorization expires without capture, payer can reclaim funds directly from escrow.Operator
Smart contract that controls capture/void logic. Different operators enable different payment patterns:- Time-locked: Release after period expires
- Arbiter-controlled: Third party decides release
- Usage-based: Capture proportional to consumption
- Immediate: Behaves like
exactscheme
