Back to Field notes

All field notes

How to

How an AI tollbooth works: the 402 handshake, step by step

4 min read /

We already wrote about the three ways to get paid by AI agents. This post covers the part that note skipped: what actually happens when an agent hits a tollbooth, and what is worth putting behind one.

What is an AI tollbooth?

It is a gate in front of a page, an API route or an MCP tool. If the caller has not paid, the gate answers with HTTP status 402, Payment Required, along with the price. The HTTP standard has reserved that status code for this kind of use for years (RFC 9110). With x402, an open standard for paying over HTTP, the agent does not need an account or an API key with you (x402.org).

The handshake

The x402 documentation describes three headers that carry the whole exchange, each holding Base64-encoded JSON (x402 docs).

  1. The agent asks. It sends a normal request with no payment.
  2. The server says 402. The reply includes a PAYMENT-REQUIRED header with the terms: price, currency, network and where to pay.
  3. The agent decides. It checks the price against its budget. An agent built with Cloudflare's Agents SDK can pay automatically or ask a person to confirm first (Cloudflare docs).
  4. The agent pays and asks again. It signs a payment and repeats the request with a PAYMENT-SIGNATURE header. The payment is in USDC, a stablecoin that Circle says is redeemable 1:1 for US dollars (Circle).
  5. The server checks the payment. A facilitator verifies the signed payment and settles it on the blockchain. The x402 docs call the facilitator optional but recommended, and say it does not hold funds (x402 docs).
  6. The answer comes back with a receipt in a PAYMENT-RESPONSE header.

Paid MCP tools work the same way. In Cloudflare's Agents SDK a server registers a tool with a price in US dollars, and a caller who has not paid gets a 402 (Cloudflare docs).

What is worth charging for?

This part is our opinion, based on building one. Charge for something an agent needs and cannot easily get elsewhere. A working tool is the clearest case, like a checker or a calculator. Fresh or original data is another, and so is any answer that costs you real compute or a third-party fee each time.

Be careful about charging the bots that send you visibility. If you sell services, being read and quoted by AI assistants is part of how people find you. Our note on which AI bots do what is worth reading before you touch robots.txt.

Habits that keep a tollbooth fair

None of these come from the x402 standard. They are rules we follow in our own build, and we think any seller should.

  1. Check before you charge. Rate limits, address checks and input checks run before the 402, so a refused request never costs the agent anything.
  2. Take the money after the work succeeds. If the site you were asked to audit is down, the agent pays nothing.
  3. Keep the route off if setup is wrong. A missing or malformed wallet setting should switch the paid route off, not send payments to the wrong place.
  4. Publish your prices. A free page that lists every paid route and says whether it is live lets agents and people check the terms.

Test it before real money moves

Run the whole thing on a test network first. The x402 docs say the public x402.org facilitator is for development and testnet use, not mainnet (x402 docs). Three results tell you the gate works. A request with no payment gets a 402 with the right price. A correctly signed payment from an empty test wallet is refused for insufficient balance. A funded test payment gets the answer and a receipt. We ran the first two on a local Worker on 13 November 2026, and the details are in our earlier note.

Per-call payments or prepaid credits?

Per-call payments suit small, frequent requests, because the agent pays for exactly what it uses. Prepaid credits suit bigger purchases and buyers who would rather pay by card: the agent holds a key, spends credits, and tops up through a checkout link. Many sellers offer both. Our WebDesk MCP server uses prepaid credits. Our GEO audit API for agents is built as pay-per-call over x402, and it stays off until its receiving wallet is set.

Mistakes to avoid

  • Charging for pages you want AI assistants to quote.
  • Settling the payment before the work is done.
  • Going live without a test-network run.
  • Hiding the price, so an agent cannot decide whether to pay.
  • Expecting a lot of income from crawlers. We would start with one useful tool and see what happens.

Want one built?

Our AI Tollbooth Setup covers the crawler policy, paid x402 endpoints you run yourself, and a test-network run before any real money moves. If you want to see how AI-ready your site is first, the GEO audit is free.

Edited

Sources

  1. RFC 9110: HTTP Semantics, 402 Payment Required, IETF
  2. x402: the payment protocol for the internet, x402.org
  3. HTTP 402 and the x402 headers, x402 docs
  4. The x402 facilitator, x402 docs
  5. Charge for MCP tools, Cloudflare
  6. Pay from the Agents SDK, Cloudflare
  7. What is USDC?, Circle
  8. Our test: the paid GEO audit on a local Worker against the x402.org test-network facilitator, 13 Nov 2026

More field notes