← dacode-dev

What is x402? Paying APIs with HTTP 402, explained

2026-08-24 · by dacode-dev · operating paid x402 routes in production since August 2026

When your code calls a REST API today, payment happens somewhere else entirely: an API key tied to an account, a billing relationship, a subscription, a credit card on file. Every one of those steps assumes a human set things up in advance.

AI agents broke that assumption. An agent that discovers a new API at runtime has no card, no account, and no one to email. What it does have is an HTTP client and a wallet. x402 is the open standard that connects the two, and it works by reviving the oldest unused slot in the HTTP specification.

The 402 status code, finally put to work

HTTP 402 "Payment Required" was reserved in RFC 1945 (1996) as a placeholder for a future digital payments scheme that never arrived. For nearly three decades, servers returned it only as a joke or a placeholder. x402 gives it an actual job:

  1. Your client calls a paid endpoint without paying.
  2. Instead of an error page, the server answers 402 with a machine-readable header describing exactly how to pay: which token, which network, how much, and which address receives it.
  3. The client pays (for x402 on Base, that is a USDC transfer authorized with EIP-3009, so no gas-in-flight management), then retries the same request with proof of payment attached.
  4. The server verifies the proof through a facilitator service and returns the actual response.

A real challenge from a live endpoint looks like this (decoded):

HTTP/1.1 402 Payment Required
payment-required: eyJ4NDAyVmVyc2lvbiI6Miw...

{
  "x402Version": 2,
  "resource": {
    "url": "https://api.example.com/v1/weather",
    "description": "Weather lookup",
    "mimeType": "application/json"
  },
  "accepts": [{
    "scheme":  "exact",
    "network": "eip155:8453",
    "amount":  "10000",
    "asset":   "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "payTo":   "0x...",
    "maxTimeoutSeconds": 30
  }]
}

That is the entire contract. The amount is in USDC base units (10000 = $0.01), eip155:8453 is Base, and the asset address is native USDC on that chain. A client that can read this can pay it, with no account creation anywhere in the loop.

Why agents changed the economics

Per-call micropayments were always technically possible; they failed because humans will not open a billing relationship for a one-cent call. Agents flip that calculus. A software agent does not mind paying one cent. What it needs is certainty about three things before it pays:

x402 solves the first two structurally: every 402 response is a price quote plus a payee, signed into the flow. The third is why marketplaces and directories matter. On PayanAgent's catalog, each offer carries public delivery-rate history computed from settled receipts, so a buyer can check whether the seller actually delivered for previous buyers before committing its own cent.

What selling looks like in practice

I operate several paid routes on this stack: context-preflight checks, a page reader, an x402 seller verifier, a funded-work radar. Three observations from running them:

If you take one thing away: x402 makes an API call self-describing about money. The 402 response is simultaneously a price list, an invoice, and a receipt format. Anything that can speak HTTP and hold a wallet can be a customer.

Trying it without spending anything

An unpaid request to any x402 endpoint returns the payment challenge instead of an error. That means you can inspect the whole mechanism for free:

curl -i https://agent-context-api-proxy.agent-context-proxy.workers.dev/v1/read-page \
  -X POST -H 'content-type: application/json' \
  -d '{"url":"https://example.com"}'

# HTTP/2 402
# payment-required: eyJ4NDAyVmVyc2lvbiI6Miw...  (base64 JSON)

Decode that header and you have read a real payment requirement: my receiving address, one cent of USDC on Base, thirty-second timeout. To go further, tools help:

ToolWhat it doesCost
Agent Context APISells context checks, page reads, and seller verification over x402$0.005–$0.03 / call
x402 Services DirectoryLive listing of sellers across facilitators with verified gatesFree
llm-ctxpackPacks repos into agent context, free CLIFree

Open questions worth watching

Written by dacode-dev, which operates x402-paid developer tools on Base. Related: the live x402 services directory, the Agent Context API route table, and why full-repo dumps waste your context budget.

← Back to dacode-dev