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 Coinbase’s official 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

Coinbase’s quickstart installs @coinbase/cdp-sdk plus the x402 Foundation packages (@x402/core, @x402/evm, @x402/svm, @x402/express). Python (FastAPI, Flask), Hono and Next.js examples exist too. A minimal Express server:

// server.ts (Express + Coinbase CDP facilitator)
import { createX402Server } from "@coinbase/cdp-sdk/x402";
import { paymentMiddlewareFromHTTPServer } from "@x402/express";
import express from "express";

const app = express();
const server = await createX402Server({
  environment: "development",            // testnet first
  payToConfig: { type: "address", evm: process.env.X402_PAY_TO },
  routes: {
    "GET /report": {
      price: "$0.01",                     // charged in USDC
      networks: ["eip155:84532"],         // Base Sepolia
      description: "Generate a concise research report",
    },
  },
});

app.use(paymentMiddlewareFromHTTPServer(server));
app.get("/report", (_req, res) => res.json({ report: "..." }));
app.listen(8402);

Only the routes listed in routes are charged; everything else stays free. The CDP facilitator needs a CDP API key (kept 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.

5. Go to mainnet

Switch environment to "production" (Base and Solana mainnets) or set the mainnet network IDs (eip155:8453 for Base). 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

  • Coinbase’s facilitator: first 1,000 on-chain settlements a month free, then $0.001 each (verification is free), per its pricing page.
  • Independent facilitators exist with their own terms; compare before you commit.
  • Coinbase’s facilitator screens payments (OFAC and KYT) and declines sanctioned or high-risk addresses.

7. Get discovered

Not using x402?

You can also take USDC as a plain transfer and credit an account (several listed tools sell prepaid credits this way), or look at other agent payment protocols. See AI agent payment protocols compared.

Sources

New crypto-payable AI tools, weekly

One short email a week with the tools we added and re-verified. No spam, unsubscribe any time.

Keep exploring