How to Accept Agent Payments on Your API (x402)
Turn any endpoint into something an AI agent can pay for — no cards, no accounts, no human in the loop. About an hour of work.
Turn any endpoint into something an AI agent can pay for — no cards, no accounts, no human in the loop. About an hour of work.
AI agents are starting to pay for data, tools, and APIs on their own — in stablecoins, over HTTP, using a protocol called x402. If you run an API, a scraper, a model endpoint, or any service, you can let agents pay you per call. Here's the whole thing, plainly.
X-PAYMENT header.That's it. You're adding a paywall machines can navigate by themselves.
https://x402.org/facilitator works on Base Sepolia + Solana devnet. To go live, use a mainnet facilitator such as Coinbase's CDP facilitator (free for Base, Solana, Stellar).x402 ships as one-line middleware for most stacks (Express, Hono, Next.js, plus Python and Go). Example in Express:
npm install x402-express
import express from "express";
import { paymentMiddleware } from "x402-express";
const app = express();
app.use(paymentMiddleware(
"0xYourReceivingWalletAddress", // where you get paid
{ "GET /premium": { price: "$0.01", network: "base" } }, // which routes cost what
{ url: "https://x402.org/facilitator" } // testnet; swap for a mainnet facilitator to go live
));
app.get("/premium", (req, res) => res.json({ data: "the paid thing" }));
app.listen(3000);
That's the whole integration: any request to /premium without payment gets a 402; with a valid payment, it passes through. (Exact package names and options evolve — always confirm against the official Quickstart for Sellers.)
Point the facilitator at https://x402.org/facilitator, use a Base Sepolia test wallet, and hit your endpoint with an x402-aware client (see our companion guide for the agent side). You should get a 402, then a paid 200.
Once real payments land, you can see them on-chain. The Agent Almanac Economy scoreboard measures exactly this — real settled volume per provider wallet — so you can watch your endpoint show up in the actual data.
Next: the other side — How to make your AI agent pay for things (x402). Or see the live state of the economy you're joining on the scoreboard.
Watch real settlement on the Economy scoreboard, see who's earning on the leaderboard, or query it all from your agent via the MCP server.