What is x402? HTTP 402, finally used

For thirty years the HTTP spec has reserved one status code that browsers never really used: 402 Payment Required. x402 is the protocol that finally gives it a job. A server answers a request with a price; the client pays it with stablecoins on-chain and retries; the second request succeeds. No account, no API key, no checkout page — payment becomes a normal part of the request/response cycle. That is exactly the primitive an autonomous AI agent needs to buy things.

The problem x402 solves

Paying for something on the web assumes a human: you create an account, store a card, click through a checkout, and the merchant keys all future charges to that identity. An AI agent has none of it. It has an HTTP client and, increasingly, a crypto wallet. Until recently there was no standard way for software to say "this call costs money, here is how to pay it" inside the protocol itself. Every paid API reinvented keys, billing portals, and rate plans. x402 collapses that into one status code.

The handshake, in two requests

Make the request with no payment. If it costs money, the server replies 402 with a machine-readable accepts array describing exactly what it wants — asset, amount, network, and the address to pay:

response · 402
HTTP/1.1 402 Payment Required
{
  "x402Version": 2,
  "accepts": [{ "scheme": "exact", "network": "eip155:8453",
    "asset": "0x8335…", // USDC on Base
    "amount": "1200000", // $1.20, atomic 6dp
    "payTo": "0x7c…e1", "maxTimeoutSeconds": 120 }]
}

The client builds a payment that satisfies one of the accepts entries, encodes it into an X-PAYMENT header, and sends the same request again. A facilitator verifies the payment and settles it, and the server returns the real 200/201 response it was guarding:

retry · with X-PAYMENT
$ curl -s -X POST https://api.agentmetal.dev/v1/servers \
    -H "X-PAYMENT: <base64 payment payload>" \
    -d '{"plan":"nano","days":1}'
HTTP/1.1 201 Created

Why stablecoins on Base

x402 is rail-agnostic, but the common deployment pays USDC on Base (an Ethereum L2). Three properties matter for agents: settlement is final in seconds, fees are fractions of a cent, and every payment is a public transaction you can verify on a block explorer. The amount is quoted in atomic units — USDC has six decimals, so 1200000 means $1.20. The payment itself is a signed EIP-3009 transfer authorization, which lets the facilitator move the funds and pay the gas, so the agent never needs a gas token at all.

Who does the cryptography

You do not hand-roll any of this. A client library such as @x402/fetch reads the 402, signs the authorization with your wallet key, and retries — turning the two-step dance into a single fetch(). For agents inside Claude or another MCP host, the @agentmetal/mcp server wraps the whole flow as tools, so the model just calls provision_server and the payment happens underneath. See giving your agent a server for that path.

What it unlocks

Once payment lives in the protocol, "an agent buys X" stops being a special integration and becomes an ordinary HTTP call. At AgentMetal the X is a real Linux server: an agent asks for one, gets a 402, pays $1.20 for a day of nano, and has SSH on a running box — with no signup and the paying wallet as the owner. That is the whole pitch of agent-native infrastructure: the same keyless, pay-as-you-go pattern x402 brings to any API, applied to compute.

Try the free side first

You can explore the protocol without spending anything. GET https://api.agentmetal.dev/v1/catalog returns the live plans and prices for free, and adding "dry_run": true to a provision call validates your entire payment pipeline at no cost. The full agent manual is at llms.txt; the human reference is in the docs.

All posts ↗