All protocols

x402

x402 is a payment protocol for HTTP. The server sends the payment terms in a response header.

x402 lets a server ask for payment before it gives a resource. The server answers with HTTP status 402. The payment terms are in the PAYMENT-REQUIRED header.

Version 2 puts the challenge in a header. Version 1 put the challenge in the body. A version 2 client that reads a version 1 response finds an empty header. It cannot see the price, and it cannot give a good reason to stop.

What people use it for

An agent buys one API call

A research agent needs one search result. The API answers 402 and asks for 0.001 USDC. The agent pays and reads the result. It keeps no account and no API key.

A site sells one article

A reader opens an article behind a paywall. The server answers 402 and names the price. The reader pays for that article, and not for a month of them.

A tool bills each run

An agent calls a code-analysis tool. The tool charges 0.01 USDC for each run. The bill matches the work, so an idle agent pays nothing.

How a payment works

  1. 1The client asksThe client requests the resource. It sends no payment.
  2. 2The server refusesThe server answers 402. The PAYMENT-REQUIRED header holds the challenge as base64 JSON.
  3. 3The client paysThe client signs the payment. It sends the request again with a PAYMENT-SIGNATURE header.
  4. 4The server agreesThe server answers 200. The PAYMENT-RESPONSE header holds the result.

On the wire

Status
402 Payment Required
Challenge header
PAYMENT-REQUIRED
Credential header
PAYMENT-SIGNATURE
Receipt header
PAYMENT-RESPONSE
Challenge encoding
base64 JSON
Network format
CAIP-2, such as eip155:84532
Version field
x402Version, a number, must be 2
Facilitator
Named by the challenge

What the challenge holds

The challenge is a JSON object. It has a version, a resource, and a list of payment options in the accepts array.

Each option in accepts names a scheme, a network, an amount, an asset, and a recipient. The amount is in atomic units, and it is a string. A number loses precision above 2 to the power of 53.

Where clients break

The version field causes the most trouble. Some servers send no version. Some send the version as a string. A client that assumes a version can read the wrong wire shape.

The network name causes the next most trouble. Version 2 uses CAIP-2 identifiers. A server that sends the old short name, such as base-sepolia, gives the client a chain it cannot match.

A challenge can also offer more than one payment option. A client that pays the first option, and not the cheapest one, pays too much.

x402 tests you can point a client at

21 ready-made x402 endpoints. Each one is a link. Testnets only, and nothing is stored.

Browse all x402 tests

How this differs from MPP

Both protocols answer 402 and both settle on a blockchain. They differ in the headers they use, who verifies the payment, and whether they send a version at all.

Compare x402 and MPP

Read the specification