-
Notifications
You must be signed in to change notification settings - Fork 12
Paying with x402
x402 is an open HTTP payment standard (the 402 Payment Required status, finally used). Settlement infrastructure exists from Coinbase (CDP facilitator — what this service uses) and Stripe.
- Client calls a paid endpoint.
- Server replies
402with a machine-readable quote: price, asset (USDC), network (eip155:8453= Base mainnet), and the pay-to address. - Client signs a USDC
transferWithAuthorizationfrom its own wallet (no gas needed — the facilitator sponsors it) and retries with the payment header. - Facilitator verifies + settles on-chain; the server serves the result. End-to-end this is seconds.
The payer needs only USDC on Base, Solana, Polygon, Arbitrum, Monad, Celo, Avalanche, Sei, Optimism, Stellar, or Algorand — no ETH, no account, no API key. (Sellers can also settle USDG on Robinhood Chain when the operator enables it.)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/api/extract", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ url: "https://example.com/article" }),
});
console.log(await res.json());Every paid endpoint also speaks MPP (Machine Payments Protocol — the
IETF-track Payment HTTP auth scheme from tempoxyz/mpp).
Same URL, same price, same on-chain USDC settlement; the only difference is the
HTTP dialect, and MPP responses add a signed Payment-Receipt header. With the
reference mppx client:
import { Fetch, evm } from "mppx/client";
import { privateKeyToAccount } from "viem/accounts";
const payFetch = Fetch.from({
methods: [evm.charge({
account: privateKeyToAccount(KEY),
currencies: [evm.assets.base.USDC],
maxAmount: "1.00",
})],
});
const res = await payFetch("https://agent402.tools/api/uuid"); // 402 -> sign -> paid retry -> 200
console.log(res.headers.get("payment-receipt")); // signed MPP receiptThe buyer's client picks the dialect: mppx prefers the native MPP challenge and
pays via Authorization: Payment; x402 clients keep using PAYMENT-SIGNATURE.
Both settle the identical EIP-3009 authorization.
Stripe's open-source purl ("curl for paid endpoints") works against Agent402 out of the box — our CI proves it on demand with a real settled payment:
purl wallet add --name me --type evm -k 0xYOUR_KEY -p yourpass --set-active=true
purl --dry-run "https://agent402.tools/api/dns?name=example.com&type=A" # see the quote
purl "https://agent402.tools/api/dns?name=example.com&type=A" # pay + get resultClient-side caps belong on the buyer:
-
purl:
PURL_MAX_AMOUNT(atomic units; 1000 = $0.001 USDC). -
agent402-mcp:
AGENT402_MAX_PER_CALL(refuse any single call above this USD price) andAGENT402_BUDGET(hard session cap) — both enforced before a payment is signed, so a confused model cannot drain the wallet.
Every settled call is an on-chain USDC transfer to agent402.base.eth (a Base name resolving to the public revenue wallet) — auditable by anyone at Basescan. The service also publishes served-call counters at /api/stats; the chain, not the counter, is the source of truth.
agent402.tools · synced from wiki/ in the main repo — edit there, not here.
Using it (for agents / buyers)
- Getting Started
- Paying with x402
- Robinhood Chain (USDG)
- Paying with Compute
- MCP Connector
- Adapters
- AWS Bedrock AgentCore
- Tool Catalog
- Skill Packs
- x402 Index and Router
- x402 Leaderboard
- LLM Gateway (OpenAI /v1)
- LLM Proxy Gateway
- Image Generation Gateway
- Code Execution Sandbox
- Text-to-Speech
- Speech-to-Text
- Text Embeddings
- Payments and x402
- Memory and Coordination
Tollbooth (for site owners)
- Pay-per-crawl — what it is, install, modes
- Pay-per-crawl Walkthrough — 5-min hands-on
- Tollbooth for Agencies — many-site playbook
- Try Tollbooth Cloud (managed)
Website & Developer
- Quickstart — first call in 60 seconds
- Playground — try tools in your browser
- SDK REPL — live code editor
- API Explorer — browse OpenAPI
- Adapter Docs — per-framework guides
- Workflows — chaining patterns
- Blog · Changelog
Under the hood