What is x402?
x402 turns HTTP's long-dormant 402 Payment Required status into a real payment layer. A service can quote a price; an agent can pay it — in stablecoins, per request, with no account.
The exchange
Four messages over plain HTTP. The price is quoted in a header, the payment is a signed authorization, and settlement rides along in the same round-trip.
- Agent → Service
GET /resourceA plain HTTP request. No API key, no account, no session — the agent just asks.
- Service → Agent
402 Payment RequiredPAYMENT-REQUIRED: { amount, asset, payTo, network }The service quotes a price: the exact amount, the asset (USDC), where to pay, and on which chain.
- Agent → Service
GET /resourcePAYMENT-SIGNATURE: <signed authorization>The agent signs an authorization to move exactly that amount from its wallet, and resends.
- Service → Agent
200 OKPAYMENT-RESPONSE: { settled, txHash }A facilitator verifies and settles on-chain — sponsoring the gas — and the resource comes back.
Header names follow x402 v2 (PAYMENT-SIGNATURE), which replaced the deprecated v1 X-PAYMENT.
x402 vs. the account model
API keys and checkout flows were built for humans with accounts. x402 is built for software that shows up once, pays, and leaves.
| Account-based APIs | x402 | |
|---|---|---|
| Onboarding | Sign up, create an account, generate keys | None — the wallet is the identity |
| Credentials | A long-lived secret to store, rotate, and leak | A fresh signed authorization, per request |
| Billing | Subscriptions, seats, prepaid tiers | The exact amount, charged per call |
| Who can pay | A human with a card at a checkout | An agent, on its own, mid-request |
| Settlement | Invoices, chargebacks, net-30 | On-chain, in the same round-trip |
What agents can pay for
- Paid APIs & data — Web reads, scraping, and extraction like AgentScout — metered by the call instead of by the month.
- Compute & inference — Run a model or a job and pay for the run, with no plan to provision first.
- Storage & state — Durable, private state like AgentKV — paid per read and write, isolated per wallet.
- Agent-to-agent — One agent can charge another for a service, settling value without a human in between.
Getting started
Your agent needs two things: a funded wallet and an x402-aware HTTP client. Then it can pay any x402 endpoint — automatically.
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(process.env.WALLET_KEY);
const pay = wrapFetchWithPaymentFromConfig(fetch, {
schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(account) }], // Base
});
// any 402 is handled for you — pay, then retry:
const res = await pay("https://api.example.com/paid"); The client watches for a 402, signs the payment, and retries. That's the whole integration.
Common questions
Do I need to know crypto?
No. Fund a wallet once, then point an x402-aware HTTP client at any paid endpoint. The 402 → pay → retry happens automatically; your code just sees the response.
Is it volatile like crypto?
Payments are in stablecoins — USDC, pegged to the US dollar. An AgentKV read quoted at $0.003 costs $0.003; there's no token to speculate on.
Who pays the gas?
A facilitator settles the payment on-chain and sponsors the network fee. The agent pays only the price the service quoted — nothing on top.
Is it secure?
Every request carries a signature authorizing one exact amount. There's no shared API key to leak or over-scope, and the agent authorizes each payment itself.
Which networks does it use?
x402 spans the ecosystem — Base, Polygon, Solana, and more, with many independent facilitators. Our own services — AgentKV, AgentRAG, and AgentScout — settle in USDC on Base.
Bigger than any one vendor
x402 is an open protocol — created by Coinbase, stewarded by the x402 Foundation, with independent facilitators, explorers, and services across Base, Polygon, and Solana — and the ecosystem directory points you to all of it. The spec lives at x402.org.