The x402 Protocol Explained: How AI Agents Pay for Things on the Internet

x402 is an open, neutral payment protocol enabling AI agents to make autonomous payments for APIs, compute resources, and services without human intervention. The protocol, named after the HTTP 402 "Payment Required" status code that was planned but never implemented in traditional web infrastructure, has processed over 50 million transactions since launch, powering machine-to-machine commerce at code speed with per-transaction costs measured in cents.

What You'll Learn

  • What x402 is and why it's essential for autonomous AI payments
  • How the x402 transaction flow works from payment request to settlement
  • Why x402 solves problems credit cards and traditional banking cannot
  • Major platforms adopting x402 (Cloudflare, Google, Vercel)
  • Getting started with x402 for your AI agent applications

What Is x402?

x402 is a payment protocol built for machine-to-machine transactions on the internet. Traditional payment systems (credit cards, bank transfers, PayPal) were designed for human-to-human or human-to-business transactions with manual approval workflows. x402 enables software to pay software programmatically, instantly, and economically.

Named after HTTP 402: The protocol references status code 402, which was reserved in the HTTP specification for "Payment Required" but never implemented. While the web standardized authentication (401 Unauthorized) and forbidden access (403 Forbidden), native payment capabilities were left out. x402 fills this decades-old gap.

Core capabilities:

  • API paywalls: Agents authenticate with x402 credentials and pay per request for premium APIs
  • Compute metering: Agents rent GPU/CPU resources and pay per second of usage
  • Data streams: Agents subscribe to real-time data feeds with programmatic payments
  • Agent-to-agent commerce: AI systems transact with each other for services

How the x402 Transaction Flow Works

Step 1: Client Requests Protected Resource

An AI agent attempts to access a resource (API endpoint, compute instance, data feed) protected by x402.

Example HTTP request:

GET /api/premium-data HTTP/1.1
Host: api.provider.com

Step 2: Server Returns 402 Payment Required

The server responds with status code 402 and payment instructions in the response body.

Example response:

HTTP/1.1 402 Payment Required
Content-Type: application/json

{
"payment_amount": "0.001",
"payment_currency": "USDC",
"payment_recipient": "0x1234...abcd",
"payment_reference": "req_abc123xyz",
"expires_at": "2026-02-15T10:35:00Z"
}

The response includes:

  • Amount (example: 0.001 USDC, roughly $0.001)
  • Currency (typically USDC or other stablecoin)
  • Recipient address (server's payment address)
  • Reference ID (links payment to specific request)
  • Expiration (payment valid for limited time, typically 60 seconds)

Step 3: Client Executes Payment

The AI agent's agentic wallet executes the required payment transaction on-chain (Base, Ethereum, or Solana depending on configuration).

Payment transaction:

  • Sends 0.001 USDC from agent wallet to recipient address
  • Includes payment_reference in transaction metadata
  • Completes in seconds on Base (gasless for agentic wallets)

Step 4: Client Re-Requests with Payment Authorization

The agent retries the original request, now including proof of payment in the authorization header.

Authorized request:

GET /api/premium-data HTTP/1.1
Host: api.provider.com
Authorization: x402 txhash=0xabcd...1234

The authorization header contains the blockchain transaction hash proving payment.

Step 5: Payment Facilitator Verifies Payment

The server's x402 payment facilitator:

  1. Looks up the transaction hash on the blockchain
  2. Verifies the transaction sent the correct amount to the correct address
  3. Confirms the payment_reference matches the request
  4. Checks the transaction was mined (confirmed) and not pending

Verification typically takes 1-3 seconds for confirmed Base transactions.

Step 6: Server Grants Access

If payment verification succeeds, the server processes the original request and returns the protected resource.

Success response:

HTTP/1.1 200 OK
Content-Type: application/json

{
"data": [premium content],
"payment_verified": true
}

The entire flow (steps 1-6) completes in under 10 seconds for Base transactions.

Why x402 Instead of Credit Cards?

Traditional payment rails fail for autonomous machine-to-machine transactions.

Problem 1: Minimum Costs Too High

Credit card processing: Stripe charges 2.9% + $0.30 per transaction. For a $0.01 API call, this means $0.30 in fees, 30x the actual cost.

x402 on Base: Transaction fee is $0.00 (gasless), making micro-payments economically viable.

Payment Size Credit Card Fee x402 Fee (Base) Viable?
$0.001 $0.30 $0.00 ✓ x402 only
$0.01 $0.30 $0.00 ✓ x402 only
$0.10 $0.30 $0.00 ✓ x402 only
$1.00 $0.33 $0.00 ✓ Both (x402 superior)
$10.00 $0.59 $0.00 ✓ Both (x402 superior)

Problem 2: Human Approval Required

Credit cards require human confirmation for each purchase. An AI agent cannot programmatically approve transactions without storing credit card numbers (massive security risk) or requiring constant human intervention (eliminating autonomy).

x402 enables programmatic payment: agent wallets execute transactions autonomously within pre-set spending limits.

Problem 3: Settlement Delays

Credit card processing: 2-3 business days for funds to settle with merchants. Not suitable for real-time resource access.

x402: Settlement is blockchain finality. On Base, this means 2-second blocks with instant confirmation. Resources are granted immediately upon payment verification.

Problem 4: Geographic Restrictions

Credit card networks have complex rules about cross-border payments, supported countries, and currency conversion fees.

x402 is borderless by design. An agent in Japan paying for compute from a provider in Germany executes the same transaction as domestic payments. No currency conversion, no international fees, no geographic restrictions.

Problem 5: Integration Complexity

Accepting credit cards requires PCI compliance, merchant accounts, fraud prevention systems, chargeback management, and complex SDKs.

x402 integration is simpler: generate payment address, return it in 402 responses, verify transactions on-chain. No merchant accounts, no compliance burdens, no chargeback risk (blockchain transactions are final).

Ecosystem Adoption

Major internet infrastructure platforms have integrated x402 support.

Cloudflare: The CDN and edge compute provider enables x402 payments for Workers (serverless compute) and R2 (object storage). AI agents can rent compute and storage on-demand, paying per millisecond of execution time.

Google: Google Cloud supports x402 for select services, allowing agents to pay for API calls (Maps, Translation, Vision AI) programmatically without enterprise contracts.

Vercel: The hosting platform accepts x402 payments for edge functions and bandwidth overages, enabling agents to scale infrastructure on-demand.

Open-source implementations: x402 client libraries exist for JavaScript, Python, Go, and Rust. Server-side facilitators are available for Express, FastAPI, and other web frameworks.

Developer adoption: As of February 2026, over 50 million x402 transactions have been processed, with 2,000+ registered service providers accepting x402 payments.

Getting Started with x402

For AI Agent Developers (Paying for Services)

If you're building an AI agent that needs to pay for APIs or resources:

1. Deploy an agentic wallet (see "How to Set Up an Agentic Wallet in Under 2 Minutes" guide)

2. Use an x402 client library:

// JavaScript example
const { X402Client } = require('@x402/client');

const client = new X402Client({
wallet: agenticWallet, // Your CDP agentic wallet
defaultCurrency: 'USDC'
});

// Make payment-protected request
const response = await client.get('https://api.provider.com/premium-data');
// Client automatically handles 402 response, pays, and retries

3. Monitor spending: Track x402 payments through CDP Portal dashboard alongside other wallet transactions

For Service Providers (Accepting Payments)

If you're running APIs or services that agents should pay for:

1. Generate a payment address: Create a wallet address to receive payments (can be traditional wallet or agentic wallet)

2. Implement x402 responses:

// Express.js example
app.get('/api/premium-data', async (req, res) => {
// Check for valid payment authorization
const paymentAuth = req.headers.authorization;

if (!paymentAuth) {
// Return 402 with payment instructions
return res.status(402).json({
payment_amount: '0.001',
payment_currency: 'USDC',
payment_recipient: '0xYourAddress',
payment_reference: req.id,
expires_at: new Date(Date.now() + 60000).toISOString()
});
}

// Verify payment on-chain
const verified = await verifyX402Payment(paymentAuth, req.id);

if (!verified) {
return res.status(402).json({ error: 'Invalid payment' });
}

// Payment verified, return protected resource
res.json({ data: premiumData });
});

3. Use a payment facilitator library:

const { X402Facilitator } = require('@x402/facilitator');

const facilitator = new X402Facilitator({
paymentAddress: '0xYourAddress',
blockchain: 'base',
verificationTimeout: 30000 // 30 seconds
});

app.use(facilitator.middleware()); // Auto-handles 402 flow

Frequently Asked Questions

Q: How does x402 differ from Bitcoin's Lightning Network? Lightning Network enables fast, low-cost Bitcoin payments but requires channel management and is optimized for peer-to-peer transfers. x402 is protocol-agnostic (works with any blockchain), focuses on HTTP-native payment flows, and integrates with standard web APIs. Many implementations use Ethereum/Base for settlement, though Lightning support exists.

Q: Can x402 payments be reversed or refunded? No. Blockchain transactions are final. Service providers can choose to issue refunds as new transactions, but the original payment cannot be reversed. This eliminates chargeback fraud but requires careful implementation of refund policies.

Q: What prevents agents from making payments to malicious services? Agentic wallet spending limits cap maximum exposure. Additionally, developers can configure allowlists of approved payment recipients. KYT screening in agentic wallets blocks payments to sanctioned addresses.

Q: How does x402 handle currency fluctuations? Most x402 implementations use stablecoins (USDC) to avoid volatility. Service providers specify payment amounts in stablecoin denominations, ensuring predictable pricing regardless of crypto market fluctuations.

Q: Can x402 work with traditional fiat currency? Not directly. x402 requires blockchain settlement for instant, borderless payments. However, on-ramps and off-ramps can convert between fiat and stablecoins if needed for accounting purposes.


{
"@context": "https://schema.org",
"@type": "TechArticle",
"headline": "The x402 Protocol Explained: How AI Agents Pay for Things on the Internet",
"description": "Comprehensive guide to the x402 payment protocol enabling machine-to-machine autonomous payments for AI agents accessing APIs, compute, and services.",
"datePublished": "2026-02-15"
}