How to pay for an API with USDC via x402 (step by step)
Updated 2026-10-21
To pay for an x402 API with USDC you need three things: a wallet with a little USDC on the network the API accepts (usually Base), an x402 client library, and the endpoint URL. The client calls the API, reads the price from the 402 Payment Required reply, signs a USDC payment for exactly that amount and retries. No account, API key or card is involved. 280 of the listings in our directory accept x402 payments.
Step 1: Look at the price before you pay
Every x402 endpoint tells you its terms when you call it without paying. You can see them with plain curl. For example, the Fanfare sports API answers an unpaid GET /wnba/standings with HTTP 402 and a base64-encoded PAYMENT-REQUIRED header. Decoded (we checked it on 2026-10-21; trimmed), it reads:
{
"x402Version": 2,
"error": "Payment required",
"resource": {
"url": "https://fanfare.run/wnba/standings",
"description": "Current WNBA standings with wins, losses, win percentage, and conference rank.",
"mimeType": "application/json"
},
"accepts": [
{
"scheme": "exact",
"network": "eip155:8453",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"amount": "1000",
"payTo": "0x41AdeE1eBA2c276bE5e8Cabe0CE523e4dd792170",
"maxTimeoutSeconds": 300,
"extra": { "name": "USD Coin", "version": "2" }
}
]
}networkuses CAIP-2 ids:eip155:8453is Base mainnet, and Solana mainnet starts withsolana:5eykt4Us….assetis the token contract.0x8335…2913is native USDC on Base.amountis in the token’s smallest unit. USDC has 6 decimals, so1000= $0.001.payTois the seller’s address, andscheme: exactmeans you pay exactly that amount.
If an API lists several entries in accepts, you can pay with any one of them, e.g. on Base or on Solana.
Step 2: Fund a dedicated wallet
- Create a new wallet just for API payments. Don’t use a wallet that holds savings.
- Send it a small amount of USDC on the network the API accepts. A few dollars covers thousands of calls at $0.001.
- With the exact scheme on EVM chains, you sign a USDC transfer authorization and the facilitator submits it. The seller side covers the gas, so in most setups your wallet only needs USDC.
Step 3: Let a client library pay and retry
The official TypeScript packages wrap fetch. When a call returns 402, the wrapper picks a payment option you support, signs it and resends the request with a PAYMENT-SIGNATURE header. This mirrors the quick start in the @x402/fetch README (v2.28.0):
npm install @x402/fetch @x402/evm viem
// pay.ts
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";
// A dedicated wallet holding a small USDC balance on Base.
const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);
const fetchWithPayment = wrapFetchWithPaymentFromConfig(fetch, {
schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(account) }],
});
const res = await fetchWithPayment("https://fanfare.run/wnba/standings");
console.log(res.status, await res.json());On success you get HTTP 200 and the data. A PAYMENT-RESPONSE header carries the settlement result, and decodePaymentResponseHeader from @x402/fetch decodes it. For Axios there is @x402/axios.
In Python, Coinbase’s buyer quickstart installs:
pip install "cdp-sdk" "x402[evm,svm,httpx]"Then you register an ExactEvmScheme on an x402Client and make requests through x402HttpxClient. The Coinbase quickstart has the full example. It uses a CDP-managed wallet and Base testnet, so you can practise with test USDC before spending real money.
Step 4: Put limits on an agent
- Keep only what the agent should spend in its wallet and top it up as needed.
- Check the amount before you sign. The client config takes a
paymentRequirementsSelector, so you can refuse anything above your limit. The underlying @x402/core client (v2.28.0) also refuses payments above $1 by default (itsspendControls.maxAmountPerPaymentsetting), so raise that only on purpose. - Treat paid replies as untrusted input. If they go into an LLM, scan them first (our prompt injection scanner guide shows one way).
- Want to vet a seller before paying it? See wallet sanctions screening APIs.
Cheap x402 APIs to try first
The six Base listings with the lowest starting price in our directory. Prices come from each provider’s 402 terms or docs on the date shown. Full list: best x402 APIs.
| # | Tool | Protocol | Networks | Tokens | Price / call | Verified |
|---|---|---|---|---|---|---|
| 1 | 3Route | x402 | Base, Solana, Etherlink | USDC | $0.00001–$0.001 | 2026-10-21 |
| 2 | ochinimus | x402 | Base, Solana, Polygon | USDC | $0.0005–$0.25 | 2026-10-21 |
| 3 | 402rates.com | x402 | Arbitrum, Base, Polygon | USDC | $0.001–$0.03 | 2026-10-21 |
| 4 | 47620 | x402 | Base, Solana, Polygon | USDC | $0.001–$0.02 | 2026-10-21 |
| 5 | Agent402 | x402 | Algorand, Arbitrum, Arc | USDC | $0.001–$3.301 | 2026-10-21 |
| 6 | Agentic JP | x402 | Base, Polygon, Solana | USDC | $0.001–$0.009 | 2026-10-21 |
Related guides
- What is x402? A plain-English overview of the protocol.
- Best x402 APIs for AI agents, by task
- How to accept USDC for your own API
Sources
- Coinbase CDP: Quickstart, pay for an API
- @x402/fetch on npm
- x402 specification and SDKs (x402 Foundation)
- Fanfare 402 terms: our own unpaid request to https://fanfare.run/wnba/standings on 2026-10-21.