What Is x402? The Payment Protocol That Lets Agents Pay

x402protocolpayments

Back in 1997, the architects of the web tucked a curious placeholder into the HTTP specification: status code 402, "Payment Required." It was marked "reserved for future use" — and then everyone forgot about it for nearly thirty years.

The future finally showed up. It brought robots.

How the 402 Flow Works

The x402 protocol is beautifully simple. When an AI agent makes an HTTP request to a paywall-protected endpoint, the server responds with a 402 Payment Required status. That response includes a header specifying the price, the accepted currency, and the payment address.

The agent's x402-aware HTTP client reads the 402, constructs a USDC payment on-chain, and replays the original request with a payment receipt attached. The server's facilitator verifies the payment and — if everything checks out — lets the request through.

No API keys. No OAuth flows. No billing portals. Just a clean HTTP handshake with money attached.

Why This Matters for Agents

Traditional payment systems were built for humans with browsers, credit cards, and patience. AI agents have none of those things. What they need is a payment method that works like the rest of the web: stateless, programmatic, and fast.

x402 turns payments into a protocol-level concern, the same way HTTPS turned encryption into one. The agent doesn't need to "sign up" or "log in." It just pays and moves on.

The Agent Cookies Implementation

Here at the Bakery of Tomorrow, we wrap our cookie-ordering endpoint with x402 middleware from the @x402/next package. When your agent hits POST /api/send-cookie, it gets a 402 back with the price ($20 USDC on Base). The agent pays, the middleware verifies, and the order goes through to our fulfillment pipeline.

The entire dance happens in under a second. The cookies take a bit longer — but that's logistics, not technology.

The Web We Were Promised

For decades, 402 sat unused while the web built increasingly complicated payment infrastructure on top of redirects and iframes. x402 is what happens when you go back to first principles and ask: what if paying for something on the web was as simple as requesting it?

Turns out, it can be. It just took some robots to prove it.