x402 — payments for AI agents
HTTP has had a payment status code since 1996. 402 Payment Required was reserved for future use and never formally defined. In 2025, the AI agent ecosystem defined it.
x402 is an emerging standard for machine-to-machine payments over HTTP. When a server needs payment before responding, it returns a 402 with a signed payment request. The client pays automatically — signs a USDC transfer on Base — and retries. No out-of-band payment flow. No human approval. The agent pays for what it uses, when it uses it.
DPX is a reference implementation of x402 for settlement infrastructure.
Why agents need this
Section titled “Why agents need this”Current options for an agent that needs to pay for something:
| Approach | Problem |
|---|---|
| Pre-authorized credit card | Requires account setup, billing cycle, chargebacks — not designed for per-call micropayments |
| API key with billing | The developer pays, not the agent — no cost-per-call granularity |
| Manual wallet transfer | Requires human approval; breaks autonomous loops |
| x402 | Agent pays autonomously, per call, in USDC, on-chain |
x402 is designed for the case where the agent is the economic actor — not a proxy for a human with a credit card.
How it works
Section titled “How it works”The protocol
Section titled “The protocol”- Agent makes a normal HTTP request
- Server returns
402 Payment Requiredwith a payment payload in the response body - Client library reads the payload, signs a USDC transfer via EIP-3009, and retries with a
X-Paymentheader - Server verifies the payment on-chain and returns the resource
The whole flow takes one round trip on a warm connection. From the agent’s perspective: call the URL, get the data.
The payment payload (402 response)
Section titled “The payment payload (402 response)”{ "x402Version": 1, "accepts": [{ "scheme": "exact", "network": "base", "maxAmountRequired": "1000", "resource": "https://intelligence.untitledfinancial.com/v1/intelligence/macro-stress", "description": "Live macro-stress signal", "mimeType": "application/json", "payTo": "0x...", "maxTimeoutSeconds": 300, "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "extra": { "name": "USD Coin", "version": "2" } }]}maxAmountRequired is in USDC atomic units (6 decimals). 1000 = $0.001.
Client implementation (TypeScript)
Section titled “Client implementation (TypeScript)”import { createSigner, wrapFetchWithPayment } from 'x402-fetch';
const signer = await createSigner('base', process.env.PRIVATE_KEY);const fetchX402 = wrapFetchWithPayment(fetch, signer, BigInt(1 * 10 ** 6)); // $1 max per call
// Pays automatically if server returns 402const data = await fetchX402( 'https://intelligence.untitledfinancial.com/v1/intelligence/macro-stress').then(r => r.json());Set a per-call max (BigInt(1 * 10 ** 6) = $1.00). The library refuses to sign any payment above that ceiling — your agent can’t be drained by a misconfigured server.
Client implementation (Python)
Section titled “Client implementation (Python)”# x402-py is not yet stable; use httpx and handle 402 manually:resp = httpx.get(url)if resp.status_code == 402: payment_payload = resp.json() # Sign EIP-3009 transferWithAuthorization with your wallet signed = sign_transfer_authorization(payment_payload, private_key) resp = httpx.get(url, headers={'X-Payment': signed})What DPX exposes via x402
Section titled “What DPX exposes via x402”| Endpoint | What you get | Price |
|---|---|---|
/v1/intelligence/macro-stress | Live macro-stress score + AI reasoning | ~$0.001 |
/v1/intelligence/fx-settlement | FX corridor risk + optimal settlement timing | ~$0.001 |
/vop/verify | Legal entity verification + FATF R16 compliance check | ~$0.001 |
These endpoints gate on payment. No account required — any wallet with a USDC balance on Base can call them.
Wallet requirements
Section titled “Wallet requirements”x402 payments use EIP-3009 transferWithAuthorization — a gasless signed transfer on Base. Your wallet needs:
- A small USDC balance on Base mainnet (~$0.01 covers dozens of calls in testing)
- The private key available to your agent at runtime
Coinbase Wallet, Rainbow, or any EIP-3009-compatible wallet works. Generate a dedicated agent wallet and fund it separately from your main holdings.
x402 and settlement
Section titled “x402 and settlement”The DPX settlement step (/settle) does not use x402 — you pay the settlement amount directly through the on-chain settlement flow, not through the 402 mechanism. x402 is used for intelligence and verification endpoints: small, per-call, autonomous.
The split is intentional. Intelligence calls are micropayments ($0.001 range) that should be fully autonomous. Settlement calls move real value and require explicit agent authorization with a signed quote.
Security model
Section titled “Security model”| Risk | Mitigation |
|---|---|
| Rogue server drains wallet | Per-call max (set in wrapFetchWithPayment) — library refuses above the ceiling |
| Replay attack | EIP-3009 includes validAfter/validBefore timestamps; each signature is single-use |
| Server pockets payment without responding | Payment goes to an on-chain address; if server misbehaves, payment is visible on-chain for dispute |
| Agent overspends | Set maxAmountRequired ceiling + monitor wallet balance with alerts |
Receiving x402 payments (server side)
Section titled “Receiving x402 payments (server side)”If you want to expose x402-gated endpoints from your own service, DPX provides a facilitator:
import { createFacilitator } from 'x402-next'; // or express, hono
const facilitator = createFacilitator({ payTo: '0x...', // your wallet network: 'base', assets: ['USDC'],});
// Middleware: gating a route at $0.001app.use('/api/premium', facilitator.gate({ amount: '1000' }));Any x402-compatible client can then pay and access your route — no accounts, no billing setup, no API keys issued.
Status
Section titled “Status”x402 is an evolving standard. The spec is stable enough to build on; the tooling (client libraries, facilitator middleware, wallets) is maturing rapidly. DPX tracks the spec and updates its endpoints as the standard firms up.
- Coinbase introduced the CDP Facilitator as a reference implementation
x402-fetch(npm) handles the TypeScript/JS client flow- Base is the primary settlement network; other EVM chains are in progress
Related
Section titled “Related”- Add payments to your agent — full 5-step working example
- MCP tools — 76 tools including x402-gated intelligence endpoints
- Intelligence worker — what the macro-stress and FX signals contain