← Money Reactor / blog

How an AI agent pays for an API call with x402 — a 3-line quickstart

Updated 2026-10-18. Every request in this article runs against a live production service (Money Reactor) on the Base mainnet. No signup, no API keys, no sandbox.

Traditional monetized APIs assume a human in the loop: someone registers an account, copies an API key into a config file, and tops up a credit card. Autonomous agents break this model completely — an agent that needs one crypto price per decision cannot pass a credit card checkout, and a shared API key is both an operational risk and an accounting nightmare. The x402 protocol solves this by reviving the long-dormant HTTP 402 Payment Required status code: when an unauthenticated request hits a paid resource, the server answers with a machine-readable payment demand, the client signs a USDC transfer on Base (EIP-3009), and the paid retry returns data in the very same round trip. There is nothing to configure in advance — the price list is discovered at call time.

Step 1 — hit the endpoint without a wallet

Any GET on a paid path returns 402 with a JSON challenge. Try it right now with the cheapest probe endpoint:

curl -i https://money-reactor.makar52nn2016.workers.dev/api/uuid

The body describes what to pay, to whom, and on which chain: x402Version: 2, an accepts array with scheme eip155:8453 (Base), maxAmountRequired in USDC units, and the merchant's payTo address. Because the challenge is structured, an agent can parse it without any human help. A free demo of the flagship bounty feed is available if you want to see the data shape before paying anything.

Step 2 — sign and retry with X-PAYMENT

The payment itself is an EIP-3009 transferWithAuthorization of USDC on Base — signed off-chain by the agent's key, verified and submitted on-chain by a facilitator (Coinbase's CDP facilitator handles this for x402 v2). You do not interact with the chain yourself. In Node.js the whole flow collapses to one wrapper call:

import { wrapFetchWithPayment } from "x402-fetch";

const fetchWithPay = wrapFetchWithPayment(fetch, evmClient);
const res = await fetchWithPay(
  "https://money-reactor.makar52nn2016.workers.dev/api/bounties"
);
const feed = await res.json(); // data + settlement receipt in headers

The wrapper receives the 402, builds the signature, retries with the X-PAYMENT header, and hands you the JSON response plus an X-PAYMENT-RESPONSE header containing the settlement proof. The agent's private key is the only credential that ever exists — there is nothing to leak in a repo, nothing to rotate, and every call is individually priced at $0.001–$0.01, so a runaway loop burns cents, not hundreds of dollars.

Step 3 — verify settlement, stay cheap

The settlement receipt names the transaction hash on Base, so payments are auditable per call. Practical tips from running a paid service for months: cache aggressively on your side (our bounty feed refreshes hourly anyway), prefer the $0.001 probes (/api/uuid, /api/time, /api/block-number) for health checks of your own x402 stack, and read openapi.json once at boot so your agent knows the full catalog and every price without another round trip.

Live catalog: openapi.json · llms.txt for agents · MCP endpoint /mcp · landing with the full 12-endpoint table

Why bother with micropayments at all? Because the alternative for agents is either free-but-rate-limited scraping or $20/month plans designed for humans. A $0.002 call that settles in one round trip fits agent economics: an agent deciding whether a GitHub repo is a honeypot before cloning it will happily pay a fifth of a cent, but will not subscribe to anything. That asymmetry is the entire business case for x402, and it works today on Base with sub-cent fees.