How to accept USDC for your API (pay-per-call with x402)
Updated 2026-10-21
The simplest way to accept USDC for an API today is x402: you add middleware to the routes you want to charge for, set a price per call and an address to receive USDC, and a facilitator verifies and settles each payment. Callers pay per request with no account. This guide follows the official x402 seller quickstart; check it for the latest package names before you ship.
1. Decide what to charge for
Pick the routes that cost you money (model inference, scraping, data lookups) and a price per call. In our listings most x402 APIs charge between $0.001 and $0.01 per request; see real pay-per-call prices.
2. Get a receiving address
You need an address that can receive USDC on each network you accept. One EVM address covers Base, Polygon, Arbitrum and other EVM chains; Solana needs its own address. Use a wallet you control and test with a small amount first.
3. Add x402 middleware
The quickstart installs the x402 Foundation packages (@x402/express, @x402/core, @x402/evm, @x402/svm). Python (FastAPI, Flask), Go, Hono, Fastify and Next.js examples exist too. A minimal Express server:
// server.ts (Express + x402 testnet facilitator)
import express from "express";
import { paymentMiddleware, x402ResourceServer } from "@x402/express";
import { ExactEvmScheme } from "@x402/evm/exact/server";
import { HTTPFacilitatorClient } from "@x402/core/server";
const app = express();
const payTo = process.env.X402_PAY_TO; // your receiving address
// Testnet facilitator from the x402 docs (Base Sepolia, Solana devnet)
const facilitatorClient = new HTTPFacilitatorClient({ url: "https://x402.org/facilitator" });
app.use(
paymentMiddleware(
{
"GET /report": {
accepts: [
{ scheme: "exact", price: "$0.01", network: "eip155:84532", payTo }, // Base Sepolia, USDC
],
description: "Generate a concise research report",
mimeType: "application/json",
},
},
new x402ResourceServer(facilitatorClient).register("eip155:84532", new ExactEvmScheme()),
),
);
app.get("/report", (_req, res) => res.json({ report: "..." }));
app.listen(8402);Only the routes in the paymentMiddleware config are charged; everything else stays free. The x402.org facilitator is for testnet only. Some production facilitators need an API key from their provider (keep it in environment variables, never in code).
4. Test on testnet
Call the route without paying: curl -i http://localhost:8402/report should return HTTP/1.1 402 Payment Required with a PAYMENT-REQUIRED header. Then make a paid call with an x402 client on Base Sepolia and confirm you get 200.
Would rather not build it yourself? (Disclosure: these are ours.) The x402 Proxy Template is a $19 USDC Cloudflare Worker that puts an x402 paywall in front of an existing HTTP API from one config file, or we can x402-enable your API for you in 48 hours (from $150 USDC; no client deployments yet, our own live x402 APIs are the proof).
5. Go to mainnet
Point the facilitator client at a production facilitator and switch to the mainnet network IDs (eip155:8453 for Base), registering the matching scheme. Dollar prices like "$0.01" use each network’s default USDC. Make sure your pay-to address can receive funds on mainnet.
6. Know the costs
- Each production facilitator sets its own pricing (some include a free monthly allowance, then charge per settlement). Check its pricing page; the x402 docs list facilitators.
- Independent facilitators exist with their own terms; compare before you commit.
- Some facilitators screen payments (for example against OFAC lists) and decline sanctioned or high-risk addresses. Check what yours does.
7. Get discovered
- Endpoints that advertise discovery metadata can be picked up by x402 directories and indexers, and agents query those indexes for paid services. See where to list your x402 API.
- List your API on YourAITools for free, or fast-track or feature it ($19 to $49 USDC). Before you list it, run the free x402 endpoint check (unpaid: grade, score, networks and price). A Verified endpoint check is also available for $19 USDC one-off (real settlement test and dated report).
- Not showing up in x402 directories? See why an x402 endpoint isn’t indexed and how to fix it (includes x402fix, built by us, which grades a route without paying).
Not using x402?
You can also take USDC as a plain transfer and credit an account (several listed tools sell prepaid credits this way), use a hosted crypto checkout such as NOWPayments (referral link; see the disclosure on this page, and compare crypto payment gateways first), or look at other agent payment protocols. See AI agent payment protocols compared.
Sources
New to x402, the HTTP 402 payment standard these APIs use? Read what x402 is and how agents pay per call.
Liked this guide? Get new crypto-payable AI tools weekly
One short email a week with the x402 and pay-per-call tools we added and re-verified. No spam, unsubscribe any time.