← All posts

How would an AI agent pay? x402, charging without accounts or cards

A program can't fill in a checkout form or wait for a text message. How x402 works, the protocol that lets a service charge an AI agent inside the same HTTP request, and what you would need to keep in mind to use it.

Hernán Díaz Rodríguez··4 min read

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:

  1. The agent asks for something paid and the server answers 402 with a PAYMENT-REQUIRED header: how much it costs, in which currency, on which network and to which address.
  2. 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.
  3. It repeats the same request with the signature in the PAYMENT-SIGNATURE header.
  4. 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:

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:

  1. Check the signature with the facilitator, without moving anything.
  2. Do the work.
  3. 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:

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 →