If you run an API, the next wave of customers can't sign up for it. Autonomous agents don't have credit cards, can't pass captchas, and won't wait for a sales call — but they hold funded wallets and speak HTTP. x402 lets you charge them per call with about as much code as adding a middleware.
You return 402 Payment Required with a quote (price, USDC, network, your
wallet address). The buyer signs a transfer authorization and retries; a
facilitator (Coinbase's is free; Stripe also operates x402 infrastructure)
verifies the signature and settles on-chain to your wallet. You never touch
keys, cards, or PCI anything — your "billing system" is one HTTP header check.
import express from "express";
import { paymentMiddleware } from "@x402/express";
const app = express();
app.use(paymentMiddleware({
payTo: "0xYOUR_WALLET", // USDC lands here, on Base
routes: { "POST /api/summarize": { price: "$0.005" } },
}));
app.post("/api/summarize", (req, res) => res.json({ ok: true }));
Set Coinbase CDP facilitator keys (free at portal.cdp.coinbase.com) and you're
settling real money on mainnet. Test the buyer side yourself with Stripe's
purl: purl http://localhost:3000/api/summarize.
agent402.tools runs ~1,083 paid endpoints this way — fully open source. The lessons:
https://agent402.tools/mcp is ours) puts your tools one paste away from
every Claude user, and an npm MCP server with client-side spend caps makes
paid adoption safe for buyers.The entire stack described here — paywall, PoW tier, MCP servers, CI, even the on-chain customer detector — is in one repo you can fork.
← All guides · agent402.tools — 1,000+ pay-per-call tools for AI agents.