← All posts
x402micropaymentstechnical

How x402 Micropayments Work for AI Agents

A technical walkthrough of the x402 payment protocol — how AI agents discover, authorize, and pay for API calls without API keys or signups.

Most APIs require a signup, a billing account, and an API key before you can make a single call. That model works fine for humans. It breaks completely for AI agents.

An agent spinning up to complete a task can't sign up for an account, enter a credit card, or manage rotating API keys. It needs to pay for what it needs, call the API, and move on — in milliseconds, without human intervention.

That's exactly what x402 enables.

The x402 Protocol

x402 is an HTTP-based payment protocol built on the HTTP 402 Payment Required status code — a status that's existed since 1991 but was never widely implemented until now.

The flow is simple:

  1. Agent calls an API endpoint — no authentication header, no API key
  2. Server returns HTTP 402 with a X-Payment-Required header describing the price, currency, and accepted payment methods
  3. Agent constructs a payment — signs a USDC transfer on Base using its wallet
  4. Agent retries the request with the signed payment in the X-Payment header
  5. Server verifies the payment on-chain, executes the call, and returns the result

No account. No signup. No API key. The wallet is the identity.

What the Headers Look Like

A 402 response from a Proxagora API looks like this:

HTTP/1.1 402 Payment Required
X-Payment-Required: {
  "scheme": "exact",
  "network": "base",
  "maxAmountRequired": "1000",
  "resource": "https://proxagora.com/api/weather",
  "description": "Live weather data",
  "mimeType": "application/json",
  "payTo": "0xProxagoraWalletAddress",
  "maxTimeoutSeconds": 300,
  "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  "extra": {
    "name": "USDC",
    "version": "1"
  }
}

The agent parses this, signs a USDC EIP-3009 transfer for exactly 1000 units (= $0.001 USDC), and includes it in the retry:

GET /api/weather?q=London HTTP/1.1
X-Payment: {
  "x402Version": 1,
  "scheme": "exact",
  "network": "base",
  "payload": {
    "signature": "0x...",
    "authorization": { ... }
  }
}

Why Base?

Base is Coinbase's L2 — fast, cheap, and EVM-compatible. A micropayment on Base costs fractions of a cent in gas and settles in ~2 seconds. That's fast enough to be invisible in an API call.

The asset is USDC on Base — a dollar-denominated stablecoin. Agents don't need to manage price volatility. $0.001 is $0.001.

What This Means for Agents

For an AI agent, x402 turns any API into a tool it can use autonomously:

  • Discovery: Agent finds an API via Proxagora's /api/discover endpoint
  • Payment: Agent pays per call from its wallet balance
  • No state: No sessions, no tokens, no refresh flows

This is why we built Proxagora around x402. The goal is an API marketplace where agents can find and pay for any data service without human setup — the same way a human uses a search engine.

Try It

If you want to see x402 in action, the Proxagora MCP package lets any MCP-compatible AI client (Claude, Cursor, etc.) call Proxagora APIs directly. The MCP server handles the x402 flow — your agent just calls a tool.

npx proxagora-mcp

Or explore the API catalogue at proxagora.com.

The Agent API Economy: Why API Keys Are DeadAPI Keys Are Dead (For Agents)