Let your bot pay per call with x402
Most data APIs want an account, an API key and a monthly plan before your bot can make a single call. With x402 your bot just calls the endpoint, gets a price back, pays it from its own wallet and gets the answer. This post walks through one paid rug-check, step by step.
Why pay per call
- No signup. There is no account to create and no key to store, rotate or leak. The wallet is the identity.
- No minimum. A bot that checks three tokens a day pays for three checks: 0.006 USDC.
- Agents can do it alone. An AI agent can find the price, decide whether a call is worth it and pay, without a human filling in a form.
The flow in three steps
- Your bot calls the endpoint as usual. Without payment the API answers
402 Payment Required, with the price in aPAYMENT-REQUIREDheader (base64 JSON). - Your x402 client picks one of the payment options and signs a payment for it. Nothing is sent on-chain yet.
- Your bot repeats the same request with the signed payment in the
PAYMENT-SIGNATUREheader. An x402 facilitator checks the payment, the API answers200with the data, and the payment is settled.
The payment is only settled when the call succeeds. A malformed request gets a 400 and costs nothing. AgentFuel never holds your funds: the facilitator moves them straight from your bot's wallet.
What is in the 402
Try it yourself; the first call is free because it only returns the price:
curl -si https://api.agentfuel.eu/v1/rugcheck/So11111111111111111111111111111111111111112 | grep -i payment-required
Decode the header value from base64 and you get the options. AgentFuel offers three, in this order:
| Option | Network | Rug-check costs |
|---|---|---|
| USDC | Solana | 0.002 USDC |
| $AFUEL | Solana | the same value minus 25% |
| USDC | Base | 0.002 USDC |
Each option says who gets paid (payTo), in which token (asset) and how much in base units (amount: 2000 means 0.002 USDC, because USDC has 6 decimals). On Solana the option also names the facilitator's fee payer, so your bot does not need SOL for fees. The full format is in the docs.
The code
The whole loop is a few lines. pay is your x402 client: it takes the requirements, signs a transfer for the option you want and returns the header value. Any x402 client library for your chain can fill that role; see x402.org for the current ones.
const API = "https://api.agentfuel.eu"; async function rugcheck(mint, pay) { const url = `${API}/v1/rugcheck/${mint}`; let res = await fetch(url); if (res.status === 402) { const required = JSON.parse(atob(res.headers.get("payment-required"))); res = await fetch(url, { headers: { "PAYMENT-SIGNATURE": await pay(required) } }); } if (!res.ok) throw new Error(`rugcheck failed: ${res.status}`); return res.json(); }
Older x402 v1 clients work too: the 402 body carries the same options in v1 form, and the API accepts a v1 payment in the X-PAYMENT header.
Tips before you go live
- Use a separate bot wallet with only a few dollars of USDC in it. x402 payments are small; the wallet does not need more.
- Set a ceiling. Let your client refuse any option above a price you choose, so a changed price never surprises you.
- Read the manifest.
GET https://api.agentfuel.eu/v1is free and lists every endpoint with its current price, so your bot can check prices before it calls. - Check the paywall itself. Before paying an API you do not know, x402 Doctor by Fizzl can check whether its 402 is set up correctly and who gets paid.
No wallet yet? Start with MCP
If your bot is an AI agent, you can skip payment while you try things out. The same checks are tools on our MCP server, with 10 free calls a day:
claude mcp add --transport http agentfuel https://api.agentfuel.eu/mcp