x402 List

x402 Protocol Service Directory

2026-04-12

How AI Agents Use X402 for Payments

Agentic payments are payments that AI agents make autonomously, with no human in the loop. Using x402, an agent pays for an API per request in stablecoins on-chain straight from its funded wallet, settling the charge over HTTP in seconds.

--------

The Challenge

AI agents are autonomous programs that take actions on behalf of users. They browse the web, call APIs, and chain services together to complete tasks. But most paid APIs require account creation, API keys, and billing setup -- steps that assume a human in the loop. An agent that needs a new API mid-task hits a wall.

X402 removes that wall. Because payment instructions are embedded in HTTP responses, an agent with a funded wallet can discover, evaluate, and pay for any X402 service without human intervention.

Step-by-Step Flow

Here is how an AI agent interacts with an X402-enabled API:

Step 1: Discovery. The agent finds a service endpoint, either from a directory like the x402 List service directory, a search engine, or a tool manifest. It sends a standard HTTP request.

Step 2: Payment Required. The server returns HTTP 402 with a JSON body describing the payment terms. Each entry in the accepts array is one accepted payment option: the scheme, the network, the amount in atomic units of the asset (USDC has 6 decimals, so 1000 means $0.001), the asset contract address, and the payTo address:

HTTP/1.1 402 Payment Required
Content-Type: application/json

{
  "error": "Payment required",
  "accepts": [
    {
      "scheme": "exact",
      "network": "eip155:8453",
      "amount": "1000",
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "payTo": "0xabc...def",
      "maxTimeoutSeconds": 300,
      "extra": { "name": "USD Coin", "version": "2" }
    }
  ]
}

Step 3: Evaluate. The agent parses accepts[] and picks an option it can pay: a network and asset its wallet holds. Then it checks its budget policy. Is the price within the per-request limit? Is the total spend for this task within budget? If so, it proceeds. If not, it skips the service or asks the user for approval.

Step 4: Sign. The agent constructs a signed payment payload for the chosen option. On EVM networks this is an EIP-3009 transferWithAuthorization signature: an off-chain authorization that lets the exact amount move from the agent's wallet to the payTo address. The agent does not broadcast a transaction itself.

Step 5: Retry with payment. The agent retries the original request with the signed payload, base64-encoded, in the X-PAYMENT header:

GET /api/translate?text=hello&lang=fr HTTP/1.1
Host: translate-402.example.com
X-PAYMENT: eyJzY2hlbWUiOiJleGFjdCIsIm5ldHdvcmsiOiJlaXAxNTU6ODQ1MyIs...

Step 6: Receive data. The server verifies the payload, settles the payment on-chain through its facilitator, and returns the requested data with a 200 response and an X-PAYMENT-RESPONSE header describing the settlement. The entire exchange completes in seconds.

Code Example

Here is a simplified agent loop in pseudo-code:

async function x402_request(url, options) {
  // 1. Make the initial request
  let response = await fetch(url, options);

  // 2. Check if payment is required
  if (response.status !== 402) {
    return response;
  }

  // 3. Parse the payment requirements from the JSON body
  let { accepts } = await response.json();

  // 4. Pick an option the wallet can pay (network + asset)
  let option = accepts.find((o) =>
    wallet.supports(o.network, o.asset)
  );

  // 5. Check agent budget policy (amount is in atomic units)
  if (!option || !budget.allows(option)) {
    throw new Error("No payable option within budget");
  }

  // 6. Sign the payment payload
  //    (EVM: EIP-3009 transferWithAuthorization)
  let payload = await wallet.signPayment(option);

  // 7. Retry with the signed payload, base64-encoded
  return await fetch(url, {
    ...options,
    headers: {
      ...options.headers,
      "X-PAYMENT": btoa(JSON.stringify(payload)),
    },
  });
}

Budget Controls

Responsible agent design includes spending limits. Agents should enforce per-request caps, per-task budgets, and per-session maximums. The X402 flow makes this straightforward because every cost is declared upfront in the 402 response, before any money moves. The agent always knows the price before it pays.

Why This Matters

X402 turns the web into a marketplace that machines can navigate autonomously. An agent can chain ten different paid APIs in a single task -- translation, image generation, code review, data lookup -- without any of them sharing an account system. Each interaction is an independent, atomic HTTP exchange. This composability is what makes X402 a foundational protocol for the agentic web. Developers can also integrate with the x402 List API to programmatically discover services.