Skip to content

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.


Current options for an agent that needs to pay for something:

ApproachProblem
Pre-authorized credit cardRequires account setup, billing cycle, chargebacks — not designed for per-call micropayments
API key with billingThe developer pays, not the agent — no cost-per-call granularity
Manual wallet transferRequires human approval; breaks autonomous loops
x402Agent 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.


  1. Agent makes a normal HTTP request
  2. Server returns 402 Payment Required with a payment payload in the response body
  3. Client library reads the payload, signs a USDC transfer via EIP-3009, and retries with a X-Payment header
  4. 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.

{
"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.

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 402
const 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.

# 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})

EndpointWhat you getPrice
/v1/intelligence/macro-stressLive macro-stress score + AI reasoning~$0.001
/v1/intelligence/fx-settlementFX corridor risk + optimal settlement timing~$0.001
/vop/verifyLegal 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.


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.


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.


RiskMitigation
Rogue server drains walletPer-call max (set in wrapFetchWithPayment) — library refuses above the ceiling
Replay attackEIP-3009 includes validAfter/validBefore timestamps; each signature is single-use
Server pockets payment without respondingPayment goes to an on-chain address; if server misbehaves, payment is visible on-chain for dispute
Agent overspendsSet maxAmountRequired ceiling + monitor wallet balance with alerts

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.001
app.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.


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