More and more API requests don't come from a person but from an agent: a program driven by a language model that gets a task ("turn these contracts into Word") and looks for the tools to do it. If the service is free, there's no problem. But if it has to pay, the agent hits the usual wall: create an account, confirm the email, enter a card, get past the bank's text message. All designed for a person.
How could an agent pay on its own, on the spot and without signing up? That is what x402 is meant for. Here I explain how it works and what a service like ours would need to keep in mind if it ever wanted to use it.
The status code that waited 30 years
Since the nineties HTTP has had a 402 Payment Required code marked "reserved for
future use". x402 is an open protocol, backed by Coinbase, that finally puts it to work:
- The agent asks for something paid and the server answers
402with aPAYMENT-REQUIREDheader: how much it costs, in which currency, on which network and to which address. - The agent signs a payment authorisation for that amount with its wallet. Signing moves no money and costs no fee: it's a signed promise, valid for a few minutes.
- It repeats the same request with the signature in the
PAYMENT-SIGNATUREheader. - The server passes it to a facilitator, which checks that the signature is good and the funds are there, then carries out the transfer. The response carries what was asked for and the transaction receipt.
Payment is usually in USDC, a digital currency worth one dollar, on networks such as Base. The agent doesn't need another currency to pay the network fee: the facilitator sends the transfer. No account, no password, no personal data: the payment is the identification.
POST /convert HTTP/1.1
HTTP/1.1 402 Payment Required
PAYMENT-REQUIRED: eyJ4NDAyVmVyc2lvbiI6Mi...
Two ways to charge
A service could offer two, because agents aren't all used the same way:
- Pay per use. One request, one payment, at the same moment. Ideal for the agent that does one job and leaves.
- Prepaid balance. One payment returns an API key with a balance, and each job spends its share. For heavy users: no payment round trip per request and fewer transactions.
Charge only if it works
If we did it, the most important rule would be never charge for a job that fails. With a card, charging and refunding is awkward; on a payment network like this one, a transfer can't be undone. So the order would have to be:
- Check the signature with the facilitator, without moving anything.
- Do the work.
- Only if it worked, execute the payment. If it fails, the authorisation simply expires.
Each authorisation also carries a unique number. By keeping the ones already used, the same signature couldn't be used twice even if someone resent it.
The details the guides leave out
Trying it on the test network, with play money, a few details come up that are worth knowing:
- You can't pay yourself. If the paying wallet is the same one that receives, the facilitator rejects it. It makes sense, but worth knowing before you test with your own wallet.
- Facilitator keys can be restricted by IP address, and if the server goes out to the internet over IPv6, that address has to be allowed too.
- You can test without money. Test networks have play USDC and free facilitators, so you can build the whole thing and check it with a test agent before touching real money.
- Getting found. An agent doesn't search Google: it reads
/llms.txt, the OpenAPI schema or service directories. Each one wants the data in a different shape.
Not for people
For someone who uses a website now and then, a crypto wallet is more of an obstacle than a help. Our website is, and will stay, free for people. A system like this would only make sense where the user is a program.
What I take away
The interesting part of x402 isn't the currency, it's that the payment fits inside an HTTP request. No sign-up, no session, no subscription: an agent that has never heard of a service could discover it, see the price, pay a few cents and take the result. It's a missing piece for agents that work on their own, and worth following closely.
Comments or ideas? Message me on LinkedIn. LinkedIn →