Home / Guides / Sell your API to AI agents over x402 - no billing system required

Sell your API to AI agents over x402 - no billing system required

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.

The seller's side of the protocol

You return 402 Payment Required with a quote (price, USDC, network, your wallet address). The buyer signs a transfer authorization and retries; a facilitator verifies the signature, your handler runs, and the facilitator settles on-chain to your wallet. You never touch keys, cards, or PCI anything - your "billing system" is one HTTP header check.

Express example

import express from "express";
import { paymentMiddleware, x402ResourceServer } from "@x402/express";
import { HTTPFacilitatorClient } from "@x402/core/server";
import { ExactEvmScheme } from "@x402/evm/exact/server";

const facilitator = new HTTPFacilitatorClient({ url: "https://x402.org/facilitator" });
const server = new x402ResourceServer(facilitator).register("eip155:84532", new ExactEvmScheme());

const app = express();
app.use(express.json());
app.use(paymentMiddleware({
  "POST /api/summarize": {
    accepts: { scheme: "exact", price: "$0.005", network: "eip155:84532", payTo: "0xYOUR_WALLET" },
    description: "Summarize a document",
  },
}, server));
app.post("/api/summarize", (req, res) => res.json({ ok: true }));
app.listen(3000);

That example settles USDC on Base Sepolia (eip155:84532) through a public testnet facilitator. For mainnet, switch the network to eip155:8453 and point HTTPFacilitatorClient at a facilitator that settles Base mainnet. Test the buyer side yourself with Stripe's purl: purl http://localhost:3000/api/summarize.

What we learned operating one (the honest part)

agent402.tools runs ~500+ paid endpoints this way - fully open source. The lessons:

  1. x402 settles after your handler runs, and only on success. @x402/express verifies the payment, runs the handler, and settles only a response below 400; an error answer cancels settlement, so the buyer is not charged. You still paid for any upstream work that failed, so anything that can't be served reliably (upstreams that block datacenter IPs, flaky APIs) should be removed, not monetized.
  2. Discovery is half the product. Publish a machine-readable catalog (/api/pricing, OpenAPI, llms.txt) and register with the x402 Bazaar - agents browse it by pay-to address.
  3. Trust is provable, so prove it. Your revenue wallet is public; link it. Run your test suite against your own documented examples in CI. Anonymous sellers are the default in this economy - a named maintainer and an auditable repo are differentiation.
  4. Offer a free taste. Pure-CPU endpoints can accept a proof-of-work instead of money - it converts wallet-less agents into integrated users who fund a wallet later.
  5. Expose it over MCP too. A hosted connector (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.

Packages for this guide

Back to guides