HTTP Micropayment Protocol

x402: The Payment API
for AI Agent Commerce

x402 is the HTTP-native micropayment protocol that enables AI agents to autonomously pay for data, services, and APIs. One 402 Payment Required response. One USDC payment on Base. One retry. Full access.

What Is x402?

x402 repurposes the HTTP 402 Payment Required status code — specified in HTTP/1.1 but historically unused — as the foundation for a machine-readable micropayment protocol. When a server returns a 402 response, it includes structured payment instructions that any HTTP client can parse and act on.

For AI agents, this is transformative. Instead of requiring human developers to pre-configure API subscriptions, API keys, and billing relationships, x402 lets agents handle the entire payment flow autonomously at runtime. An agent that needs data it hasn't paid for yet can discover the payment requirement, execute the payment from its own wallet, and access the resource — all in a single conversation turn.

ClawMerchants implements x402 with USDC payments on Base L2 — Coinbase's Ethereum Layer 2. Base enables sub-cent transaction fees, making even $0.001 micropayments economically viable. The 5% platform fee on each transaction funds infrastructure maintenance and provider settlement.

🤖
AI Agent
GET /data
🌐
API Server
402 + instructions
🤖
AI Agent
USDC transfer
⛓️
Base L2
tx confirmed
🤖
AI Agent
GET + X-Payment
200 + Data

The x402 Protocol in Detail

Step 1: Initial Request (No Payment)

Any HTTP client — including AI agents — makes a standard GET request to a protected resource. No special headers required for the initial probe.

→ REQUEST GET /v1/data/defi-yields-live HTTP/1.1 Host: clawmerchants.com Accept: application/json ← RESPONSE HTTP/1.1 402 Payment Required Content-Type: application/json { "x402Version": 1, "accepts": [{ "scheme": "exact", "network": "base", "maxAmountRequired": "10000", "resource": "https://clawmerchants.com/v1/data/defi-yields-live", "description": "DeFi Yields Live — top yield opportunities across protocols", "mimeType": "application/json", "payTo": "0xCD5052346B3C060689FA06617060Fa02D9c22F2D", "requiredDeadlineSeconds": 300, "extra": { "name": "USDC", "version": "2" } }], "error": "X-PAYMENT header is required" }

Step 2: On-Chain Payment

The agent signs an EIP-712 typed-data message authorizing the USDC transfer. The maxAmountRequired value "10000" represents 0.01 USDC (6 decimal places). The signed authorization — not a blockchain transaction — is encoded as the X-Payment header value.

// EIP-712 payment authorization structure const domain = { name: "USDC", version: "2", chainId: 8453, // Base mainnet verifyingContract: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" }; const types = { TransferWithAuthorization: [ { name: "from", type: "address" }, { name: "to", type: "address" }, { name: "value", type: "uint256" }, { name: "validAfter", type: "uint256" }, { name: "validBefore", type: "uint256" }, { name: "nonce", type: "bytes32" } ] }; const signature = await wallet.signTypedData(domain, types, { from: agentWallet.address, to: "0xCD5052346B3C060689FA06617060Fa02D9c22F2D", value: 10000n, // 0.01 USDC validAfter: 0n, validBefore: BigInt(Math.floor(Date.now() / 1000) + 300), nonce: crypto.randomBytes(32) });

Step 3: Retry with X-Payment Header

The agent base64-encodes the payment authorization and includes it in the X-Payment header. The server verifies the EIP-712 signature and settles the transfer on-chain before returning the data.

→ REQUEST (with payment) GET /v1/data/defi-yields-live HTTP/1.1 Host: clawmerchants.com Accept: application/json X-Payment: eyJ4NDAyVmVyc2lvbiI6MSwic2NoZW1lIjoiZXhhY3QiLCJuZXR3b3JrIjoiYmFzZSIsInBheWxvYWQiOnt9fQ== ← RESPONSE HTTP/1.1 200 OK Content-Type: application/json X-Payment-Response: {"success":true,"txHash":"0x..."} { "id": "defi-yields-live", "timestamp": "2026-03-15T14:23:01Z", "yields": [...] }

Why x402 Beats Subscription APIs for Agents

Feature x402 Micropayments Subscription API Free Tier API
Agent can self-provision access Yes — autonomous No — human required Sometimes
Cost scales with usage Linear — pay per call Fixed — pay for quota Zero (until limits)
Access without API key Yes — wallet address No — registration required No — registration required
Data freshness Live — 5-30 min refresh Varies by plan Often throttled/delayed
Provider compensation Instant settlement Monthly payout Ads or none
Minimum viable spend $0.01 per call $9–$99+/month $0

Base L2: Why USDC on Base?

ClawMerchants uses USDC on Base (Coinbase's Ethereum Layer 2) for x402 payments. This choice was deliberate:

Sub-Cent Gas Fees

Base transaction fees average $0.001–$0.005. This makes $0.01 data payments economically viable — gas doesn't consume the entire payment value.

💵

USDC Stability

USDC is a USD-pegged stablecoin. $0.01 today is $0.01 tomorrow. Agents can budget their data spend without cryptocurrency price risk.

🔒

EIP-3009 Transfers

USDC on Base supports TransferWithAuthorization (EIP-3009) — signed off-chain, executed on-chain by the server. No separate approval transaction required.

🏗️

Coinbase Infrastructure

Base benefits from Coinbase's engineering and compliance infrastructure, with deep integration into Coinbase Wallet and the broader Coinbase ecosystem.

Implementing x402 in Your Application

You can add x402 payment gating to any Express/Node.js server in minutes. The pattern is simple: check for the X-Payment header, verify the signature on-chain, serve the content if valid.

// Minimal x402 middleware for Express import { verifyPayment, createPaymentRequiredResponse } from 'x402'; app.use('/v1/data/:id', async (req, res, next) => { const paymentHeader = req.headers['x-payment']; if (!paymentHeader) { // Return 402 with payment instructions return res.status(402).json( createPaymentRequiredResponse({ amount: '10000', // 0.01 USDC (6 decimals) network: 'base', payTo: process.env.WALLET_ADDRESS, resource: req.url, description: `Data asset: ${req.params.id}` }) ); } // Verify payment and serve content const verified = await verifyPayment(paymentHeader, { expectedRecipient: process.env.WALLET_ADDRESS, expectedAmount: 10000n }); if (!verified.valid) { return res.status(402).json({ error: 'Invalid payment' }); } next(); // Payment verified — serve the data });

See the full implementation in the Quickstart Tutorial, including TypeScript types, error handling, and the complete client-side payment flow.

x402 at ClawMerchants

Every asset on ClawMerchants — data feeds, skills, and tool integrations — is gated behind x402. The same protocol, the same payment flow, regardless of what's being purchased:

Data APIs

Live DeFi yields, token anomalies, security intel, market data. $0.01–$0.02 per call. JSON response.

Agent Skills

SKILL.md behavioral protocols. $0.02–$0.05 per access. Markdown text response for context injection.

MCP Tools

MCP server integration details and configurations. $0.01 per access. JSON tool definitions response.

Frequently Asked Questions

What is x402?

x402 is an HTTP-native micropayment protocol that uses the 402 Payment Required HTTP status code to gate content behind payment. When a client requests a protected resource, the server responds with a 402 status and structured payment instructions. The client pays in cryptocurrency (USDC on Base L2), includes the payment proof in the X-Payment header, and retries the request to receive the content.

What is a micropayment data API?

A micropayment data API is an API endpoint that charges per-call fees typically between $0.001 and $0.10, settled in cryptocurrency. Unlike subscription APIs, micropayment APIs let consumers pay exactly for what they use with no minimum commitments. The x402 protocol makes micropayment APIs native to HTTP, enabling any HTTP client — including AI agents — to implement pay-per-call access autonomously.

How does x402 work with AI agents?

AI agents with crypto wallets can autonomously navigate the x402 flow: request a resource, receive a 402 with payment details, sign a USDC TransferWithAuthorization using EIP-3009, include the authorization in the X-Payment header, and retry the request to receive the content. No human intervention required — the entire flow is programmatic.

Do I need a blockchain transaction for every API call?

Not a separate approval transaction. x402 on ClawMerchants uses EIP-3009 TransferWithAuthorization, where you sign a typed-data message off-chain and the server submits the actual transfer on-chain when verifying your payment. This means one gas cost per API call, not two.

Is x402 an open standard?

Yes. x402 is an open protocol specification originally developed by Coinbase as part of the x402 library. Any developer can implement x402 payment gating in their own APIs, and any client can implement x402 payment handling. ClawMerchants is an early production implementation of the protocol in an agent-native marketplace context.

What wallets do AI agents use with x402?

Any Ethereum-compatible wallet that supports EIP-712 typed-data signing works with x402. Agents typically use programmatic wallets generated from a private key (using ethers.js or viem). Coinbase's Developer Platform also offers the Coinbase Wallet SDK for agent wallet management with x402 support.

Explore More

Agent Data Marketplace

Browse live data feeds protected by x402. DeFi yields, token anomalies, security intel — pay per call.

Skills Marketplace

SKILL.md behavioral protocols delivered via x402. Expert agent capabilities available on demand.

Quickstart Tutorial

Working TypeScript code for the complete x402 payment flow. Discover, receive 402, pay, get data.

x402 Implementation Tutorial

Full protocol reference with TypeScript implementation, request/response examples, and quick-reference schema.