HTTP 402

x402 Protocol

Open Standard
Open Payment Protocol · Linux Foundation · Apache 2.0

The internet finally has a native payment layer.

x402 revives HTTP's forgotten status code to enable instant, permissionless payments between AI agents and APIs — no accounts, no API keys, no forms.

75.4M
Transactions (30 days)
$24.2M
Volume (30 days)
94K
Unique buyers
22K
Sellers
The Problem

Credit cards were designed for humans. Agents can't fill out forms.

The current API economy requires accounts, KYC, API keys, and subscriptions — a flow that barely works for humans and is completely broken for autonomous AI agents.

❌  The old way
1
Create an accountEmail verification, T&Cs, time-consuming setup
2
Complete KYCDelays access, requires human approval
3
Buy credits or a subscriptionPrepaid commitment — overpay or run out unexpectedly
4
Manage API keysSecurity risk — must store, rotate, and protect secrets
5
Make the actual paymentSlow settlement, chargebacks, interchange fees
VS
✓  With x402
1
Agent sends HTTP requestNo setup — the first request is also the onboarding
2
Server responds 402 + payment instructionsMachine-readable: amount, wallet address, network
3
Agent pays with stablecoin and retriesSub-second settlement, zero approval required
4
Access grantedNo keys to manage, no accounts to maintain
Interactive Flow

How an x402 payment works

Walk through a complete x402 exchange — from the first unauthenticated request all the way to settled payment and resource delivery.

Step 1 of 5
Quickstart

One line of middleware. Any language.

x402 ships first-class packages for Express, Next.js, Hono, Fastify, Go, and Python. Buyers get a drop-in fetch wrapper that handles the entire payment flow transparently.

server.ts — Express seller
import express from "express";
import { paymentMiddleware } from "@x402/express";

const app = express();

// Require payment on any route — that's it
app.use(
  paymentMiddleware({
    "GET /weather": {
      accepts: [{
        scheme: "exact",
        price:   "$0.001",
        network: "base-mainnet",
        payTo:   "0xYourWalletAddress",
      }],
      description: "Real-time weather data",
    },
  })
);

app.get("/weather", (req, res) => {
  res.json({ temp: 72, condition: "sunny" });
});

app.listen(3000);
middleware.ts — Next.js seller
import { paymentMiddleware } from "@x402/next";

// Drop this in middleware.ts at your project root
export default paymentMiddleware({
  "/api/data": {
    accepts: [{
      scheme:  "exact",
      price:   "$0.01",
      network: "base-mainnet",
      payTo:   "0xYourWalletAddress",
    }],
    description: "Premium dataset access",
  },
});

export const config = {
  matcher: ["/api/data"],
};
server.py — FastAPI seller
from fastapi import FastAPI
from x402.frameworks.fastapi import X402Middleware

app = FastAPI()

# Wrap with payment middleware
app.add_middleware(
    X402Middleware,
    routes={
        "/data": {
            "price":   "$0.001",
            "network": "base-mainnet",
            "pay_to": "0xYourWalletAddress",
        }
    }
)

@app.get("/data")
async def get_data():
    return {"result": "premium data"}
agent.ts — Buyer / AI Agent
import { wrapFetchWithPayment } from "@x402/client";
import { createWalletClient } from "viem";

// Give your agent a wallet
const wallet = createWalletClient({ /* your config */ });

// Wrap fetch — payments are handled automatically
const fetchWithPayment = wrapFetchWithPayment(fetch, wallet);

// Your agent calls APIs as normal
const res  = await fetchWithPayment("https://api.example.com/weather");
const data = await res.json();

// x402 handles the full payment flow transparently:
//  1. Receives 402 + payment instructions
//  2. Signs and submits payment payload
//  3. Retries with X-Payment header
//  4. Returns the 200 response to your code
Networks

Chain-agnostic, stablecoin-first

x402 is a neutral open standard — not tied to any chain or issuer. Today's primary networks are Base and Solana, with full support for any EVM chain and Algorand.

🔵
Base (Coinbase L2)
USDC ERC-20 EIP-3009
The primary production network. Ethereum L2 with <$0.01 transaction fees and ~1s finality. USDC on Base is the most common payment token. Batch settlement available for high-volume use cases.
🟣
Solana
USDC SPL
High-throughput alternative with near-zero fees. Solana USDC payments are fully supported via the @x402/svm package. ~400ms transaction finality, ideal for high-frequency small-value API calls.
Any EVM Chain
EIP-155 EIP-3009
x402 uses the EIP-155 chain ID format (eip155:<chainId>) — any EVM-compatible network works. Ethereum mainnet, Polygon, Arbitrum, Optimism, and others are all supported out of the box.
🔶
Algorand
USDC AVM
Algorand Virtual Machine support via @x402/avm. Sub-second finality with ultra-low fees. Supported alongside EVM and Solana in the same payment middleware — sellers accept all three from one config.
Use Cases

What you can build

Any digital resource served over HTTP can be monetized per-request — no subscriptions, no credit systems, no signup gates required.

🤖
AI Agent Commerce
Agents discover paid APIs, receive the 402, pay from their wallet, and get the resource — entirely without human involvement. The foundation of autonomous agent-to-agent economies.
API Pay-Per-Request
Monetize any endpoint at the per-call level. Price in fractions of a cent — $0.0001 per query, $0.001 per data point, $0.01 per image. No credits to manage, no subscriptions to worry about.
📄
Digital Content Paywalls
Gate articles, datasets, reports, and media behind x402 endpoints. Readers pay per piece — no monthly subscriptions needed. Works seamlessly for both humans and AI agent crawlers.
🔗
Proxy & Aggregator Services
Build paid proxy layers that aggregate third-party APIs. Pay upstream with x402, charge downstream callers a markup. Composable payment flows with zero infrastructure overhead.