What is x402? How AI agents pay for APIs
The web has had a status code reserved for payments since 1997: HTTP 402 Payment Required. It sat unused for 25 years because there was no fast, cheap, programmatic way to pay. Stablecoins changed that. x402 revives 402 so that any API can charge a few cents per call and any program, especially an AI agent, can pay it automatically. This guide explains how it works and how to use it.
What is x402?
x402 is an open protocol that lets software pay for a web request with a stablecoin. A server answers an unpaid request with HTTP status 402 Payment Required and a small machine-readable body that states the price, the token (USDC), the chain (usually Base), and the address to pay. The client pays on-chain and retries. No account, no API key, no invoice, no human.
How do AI agents pay for APIs?
An autonomous agent hits an endpoint, receives the 402 with the price, signs a USDC transfer authorization with its own wallet, and retries with a payment header. A facilitator verifies the payment and settles it on-chain. The whole exchange takes one round trip and needs no human, which is why x402 is the payment layer many agent frameworks are adopting.
Is x402 free to use?
The protocol is free and open. You pay only the per-call price a service sets, typically $0.001 to $0.01 in USDC, plus on-chain gas, which many facilitators sponsor. There is no subscription and no platform fee to call a service.
x402 vs L402 vs Google AP2
L402 (Lightning) pairs a 402 with a Lightning invoice and a macaroon token, settling in bitcoin over Lightning. Google's AP2 (Agent Payments Protocol) is a broader mandate-and-intent framework for agent commerce. x402 is the simplest of the three for pay-per-call APIs: a plain HTTP 402 settled in USDC on an EVM chain, which is why it has the most live pay-per-call services today.
What can I actually buy with x402?
Mostly things agents consume: web search, data feeds (weather, markets, crypto, social), inference, enrichment, and specialized tools. Browse the thousands of services in the directory, each with copy-paste code.
How do I start?
Read the 5-minute quickstart: create any EVM wallet, hold a few dollars of USDC on Base, install an x402 client, and call your first paid API. To search the registry from your own agent, use the x402hub API.
See it in practice
x402hub indexes every public x402 service with live pricing and ready-to-run code. Browse the directory, read the quickstart, or query the registry programmatically through the x402hub API.