How can an AI agent pay for an API without signing up?
Your agent can pay per request from its own wallet, over x402 or MPP, with no account and no API key. 187 pure-CPU tools run free when the agent solves a short proof-of-work puzzle instead of paying. Agent402 serves 500+ tools this way, plus a model gateway on the OpenAI-compatible wire format (model-backed), and every price is in the 402 before anything is paid.
What the agent needs
- A wallet holding a little USDC or USDG on fourteen chains. The wallet is the identity: there is nothing to register.
- A client that pays a 402: agent402-client, the
open
@x402/fetchwrapper, an MPP client, or an MCP client pointed at the hosted connector. - No wallet yet? The pure-CPU tools take a proof-of-work solution instead of money, so the agent can start before it holds a cent.
One paid call, four steps
- Call. The agent sends the request with no payment. The route answers
402 Payment Requiredwith the price, the address it pays, and the chains and assets it takes. The same 402 carries an x402 offer (thePAYMENT-REQUIREDheader) and MPPWWW-Authenticate: Paymentchallenges, so a client pays whichever it speaks. A client whose User-Agent starts withpython-httpx/gets the x402 offer alone, with noWWW-Authenticate: Paymentchallenge, unless it sendsX-Payment-Offers: mppor anAccept-Paymentheader naming an MPP method. - Sign. The wallet signs an authorization for exactly that amount: an x402 payment, or an MPP credential.
- Send again. The same request goes back with the payment attached. The server checks it, runs the call and settles the payment.
- Read the receipt. A settled answer carries
PAYMENT-RESPONSEwith the settlement transaction. A settled 200 also carriesAgent402-Receipt: a receipt this server signs (EdDSA over Ed25519) over the method, path, request and answer digests, the price, rail, network, payer and settlement. The public keys are at /.well-known/agent402-receipt-key.json, andPOST /api/receipts/verifychecks a receipt against them for free. How to check a receipt.
An x402 payment settles only after a successful answer, so an x402 call that answers an error is not charged. Some calls are paid before they run; a failed one can be retried free with the same payment, or is refunded.
See a price (free)
curl -i -X POST https://agent402.tools/api/extract \
-H 'Content-Type: application/json' -d '{"url":"https://example.com"}'
# HTTP/2 402: the price, payTo, network and asset
This route costs $0.001 a call, and the 402 says so before anything is signed.
Pay it from code
import { Agent402 } from "agent402-client";
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.(false); // the cap below replaces the library default
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const a = new Agent402({ fetch: payFetch, x402Client: client, maxPerCallUsd: 0.05 });
const page = await a.call("extract", { url: "https://example.com/article" });
The same client with no wallet runs the free tools, solving the puzzle on its own:
import { Agent402 } from "agent402-client";
const free = new Agent402();
const out = await free.call("hash", { text: "hello", algo: "sha256" });
From an MCP client
Add https://agent402.tools/mcp as a connector. The free tools answer
straight away; the paid ones answer with their payment offer instead of a result (an x402 PaymentRequired beside the MPP challenges): an MCP client that pays x402 or MPP settles it in the same call.
Before the agent pays
- Find the tool:
GET /api/find?q=<task>answers the route, its input schema and its price, free. - Cap the spend: the client refuses any quote above
maxPerCallUsdbefore it signs. - Check the seller: how to tell an x402 seller is reliable.
- Pick a wire: x402 vs MPP: use both.