← agentwallet.md

x402 Protocol

by Coinbase — open standard · github.com/coinbase/x402
Payment Rail Open Source Official
Best for: Machine-to-machine pay-per-request payments; micropayments for API access without auth tokens
Not ideal for: User-to-agent payments; fiat currency; high-value single transactions

Key Signals

Payment Mechanism
HTTP 402 native
Currency
USDC
Client Requirement
Any HTTP client
Pricing
Free (open protocol)

Features

🔁
HTTP 402-Based Payment Protocol
Revives the long-dormant HTTP 402 "Payment Required" status code. Servers respond with 402 and payment details; clients attach payment proof and retry. No OAuth dance, no API keys — payment IS the authentication.
🔑
No Auth Tokens Needed
Eliminates credential management entirely for M2M scenarios. The cryptographic payment proof doubles as proof of authorization. AI agents can access paid APIs without pre-provisioned credentials or subscription accounts.
💵
USDC Per-Request Settlement
Each API request can carry a USDC micropayment settled on Base. Enables granular pay-per-call pricing that would be impractical with traditional invoicing. Fractions of a cent per call are economically viable.
🌐
Any Language / Framework
Works with any HTTP client in any language. Reference implementations available in JavaScript/TypeScript and Python. Middleware packages available for Express, Next.js, and FastAPI to add 402 support in minutes.

Ratings

Protocol Simplicity
4.8
Agent Compatibility
4.7
Ecosystem Maturity
3.2
Ease of Integration
4.3
Ratings based on documentation review, GitHub activity, and public developer reports. Not independently verified in production.

Integration

# 1. curl example — server returns 402, client retries with payment header curl -i https://api.example.com/data # HTTP/1.1 402 Payment Required # x-payment-required: {"scheme":"exact","network":"base","maxAmountRequired":"1000","resource":"https://api.example.com/data","description":"1 USDC per call","mimeType":"application/json","payTo":"0xSERVER_ADDRESS","maxTimeoutSeconds":60,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"} curl -H "x-payment: SIGNED_PAYMENT_PAYLOAD" https://api.example.com/data # 2. JS fetch with x402 client middleware npm install x402-fetch import { wrapFetch } from 'x402-fetch'; import { createWalletClient } from 'viem'; const wallet = createWalletClient({ ... }); const fetchWithPayment = wrapFetch(fetch, wallet); // Automatically handles 402 → sign payment → retry const res = await fetchWithPayment('https://api.example.com/data'); const data = await res.json();

Alternatives

Stripe Agent Toolkit
Traditional fiat rails with full Stripe ecosystem — better for user-facing checkout flows
Skyfire
Hosted agent payment service — managed alternative if you don't want to run your own x402 infrastructure
Payman AI
Human-in-the-loop payment approval — better when humans need to authorize agent spending