Paste one line: endpoint, price, description. AI agents pay you in USDC every time they call it. No API keys to issue, no billing to build.
// app/api/my-api/route.ts
// npm i @x402/next @x402/core @x402/evm
import { NextRequest, NextResponse } from "next/server";
import { withX402 } from "@x402/next";
import { HTTPFacilitatorClient, x402ResourceServer } from "@x402/core/server";
import { ExactEvmScheme } from "@x402/evm/exact/server";
const server = new x402ResourceServer(
new HTTPFacilitatorClient({ url: "https://x402.org/facilitator" }),
).register("eip155:84532", new ExactEvmScheme()); // Base Sepolia
const handler = async (req: NextRequest) => {
return NextResponse.json({ data: "your response" });
};
// Unpaid calls get HTTP 402. Paid calls run, then settle (only if status < 400).
export const POST = withX402(
handler,
{
accepts: [{ scheme: "exact", price: "$0.002", network: "eip155:84532", payTo: "0xYourWallet" }],
description: "My paid API",
},
server,
);Official Coinbase x402 v2 packages (@x402/*). Swap eip155:84532 for eip155:8453 to go live on Base mainnet.
How it works
1. Agent calls your API → gets HTTP 402 + price + your wallet.
2. Agent signs a USDC authorization, retries with PAYMENT-SIGNATURE.
3. Facilitator verifies, you serve data, payment settles on-chain → PAYMENT-RESPONSE.
Don't want to touch your code? List it here and NOKEY fronts it with an x402 gateway.