Skip to content
0%

What is x402? The payment protocol for AI agents and onchain APIs

Author: Uttam Singh

Last updated: April 10, 20267 min read
x402 payment protocol diagram

AI agents need to pay for things: API calls, data feeds, compute. But they don't have credit cards. They can't fill out signup forms. The standard billing model assumes a human on the other end. When the client is software, that model breaks.

x402 is an open-source protocol built to fix this. It embeds cryptocurrency payments directly into HTTP using the 402 "Payment Required" status code, which has been in the spec since the 1990s but was never put to use. A client sends a request, gets payment terms back, pays in crypto, and retries. No API keys. No subscriptions. No billing dashboards.

Since launching in May 2025, x402 has processed over 100 million payments. In December 2025, x402 V2 shipped with multi-chain support, wallet-based sessions, and an extensible architecture. In April 2026, Coinbase contributed the protocol to the Linux Foundation, which launched the x402 Foundation with over 20 founding members including Google, Visa, Stripe, AWS, Mastercard, Circle, Microsoft, and Shopify.

Diagram showing the x402 payment flow
Source: https://x.com/jarrodWattsDev/status/1982036553481568512

How does the x402 payment flow work?

The whole thing happens in five steps:

  1. A client requests a resource from the server.
  2. If the resource requires payment, the server returns a 402 Payment Required response with payment terms: amount, currency, and destination address.
  3. The client reads the terms, sends the payment (typically USDC), and retries the request with a payment header.
  4. The server verifies the payment, either locally or through a facilitator.
  5. The server delivers the resource with a 200 OK.

That's it. Any HTTP endpoint becomes a paid service, and any client with a crypto wallet becomes a paying customer. The payment happens inside the request cycle, not through a separate billing system.

x402 is in production today. You can explore live transactions on x402scan.com.

Screenshot of x402scan showing live payment transactions

What is HTTP 402, and why was it never used?

If you've built anything on the web, you know status codes. 200 means the request worked. 404 means the page doesn't exist. And 402? Payment required.

Most developers have never seen a 402 in the wild. The code has been in the HTTP spec since the 1990s, but the original authors reserved it "for future use" without defining how payments should work. So developers built other billing models: sign up for an account, attach a credit card, get an API key, pay based on usage.

x402 fills that gap. Instead of API keys and billing dashboards, payment happens within the HTTP request itself. The server responds with 402, the client pays with crypto, the server delivers the resource. HTTP and blockchain in one interaction.

What's new in x402 V2?

x402 V2 shipped in December 2025 after six months of production use. Four changes matter most.

Multi-chain and multi-rail payments

V1 only worked with USDC on Base. V2 supports tokens across Base, Solana, Ethereum, Polygon, Starknet, and Injective, with more chains coming. It also works with legacy payment rails (ACH, SEPA, card networks) through pluggable facilitators.

If you're building a marketplace or multi-tenant API, dynamic "payTo" routing lets you distribute payments to different addresses or roles per request.

Wallet-based sessions

V1 required a full on-chain payment for every request. That's fine for one-off API calls, but it falls apart for high-frequency workloads. V2 introduces wallet sessions: authenticate once, then make subsequent requests using session tokens. The server settles accumulated usage periodically rather than verifying every call on-chain.

If you're building an LLM inference pipeline, a real-time data feed, or a multi-step agent workflow, sessions are what make micropayments practical. Lower latency, lower per-request costs, fewer on-chain transactions.

Extensible architecture

V2 splits the protocol spec from the SDK and facilitators. New chains, payment schemes, and facilitators plug in as standalone packages without touching the core protocol. The SDK uses CAIP standards for chain and asset identification, so adding a new network requires no custom logic.

Automatic API discovery

Services expose structured metadata that facilitators crawl automatically. Pricing, routes, and endpoints stay in sync without manual updates or hardcoded catalogs. You publish your service once and every facilitator in the network discovers it. No registrations, no partner integrations, no catalog maintenance.

What role do facilitators play in x402?

If you're an API developer, you probably don't want to write blockchain settlement logic. Facilitators handle that for you. Think of them as payment processors for the open web: they confirm a client's authorization, execute the transaction on-chain, and return confirmation to your server.

Diagram showing the workflow of x402 facilitators
Source: https://medium.com/@christianobi98/x402-awakening-http-402-for-autonomous-web-payments-2fd944cb703a

With a facilitator, you can accept x402 payments without writing any blockchain code. V2 supports multiple facilitators at once, and the SDK picks the best match based on chain, asset, and your preferences.

Who is x402 for?

If any of these sound like your problem, x402 was built for you:

  • You're an API provider and want pay-per-use monetization without forcing users to create accounts or manage subscriptions
  • You're building AI agents or bots that need to pay for services without a human in the loop
  • You work with coding agents (Cursor, Claude Code, ChatGPT) that need to access paid APIs, data, or compute on their own
  • You're building agent-to-agent (A2A) commerce, machine-to-machine payments, or autonomous service marketplaces

x402 fits anywhere software needs to pay for resources on its own: AI inference APIs, micropayments for data access, gated content, compute billing. For purchases outside the crypto ecosystem, projects like AgentCard give agents their own credit cards with configurable spending limits and real-time tracking.

What can you build with x402?

  • Pay-per-call API endpoints for AI inference, data feeds, or compute
  • Micropayment systems for digital content: images, videos, research papers, datasets
  • Autonomous agent-to-agent commerce where AI agents buy data, compute, or API access from each other
  • Usage-based billing for storage, bandwidth, or any metered resource
  • Freemium APIs with crypto-gated premium tiers
  • Multi-chain data pipelines that pay per request at sub-cent rates using V2 sessions

These aren't hypothetical. AI agents are already querying blockchain data to manage DeFi positions, monitoring token prices and executing trades without human oversight, and running multi-chain indexing pipelines end to end. Some are buying compute and deploying smart contracts through x402-enabled services.

For a detailed comparison of x402 with the Machine Payments Protocol (MPP), see x402 vs MPP: comparing agent payment protocols.

How does Alchemy support x402?

We built an agentic gateway that lets AI agents access blockchain infrastructure through x402 with zero human setup.

Here's what that looks like in practice: an agent shows up with its onchain wallet. No API key, no dashboard account. It calls our APIs directly. If payment is required, we return a 402 with payment terms. The agent pays in USDC on Base, and we process the request. Subsequent requests draw from the funded balance until it runs out, then the gateway issues a new 402 and the agent tops up on its own.

Available APIs

Agents get access to the same production APIs used by teams at Coinbase, Visa, and Stripe, across 100+ blockchains:

  • Core RPC across 100+ blockchains
  • NFT APIs for ownership and metadata queries
  • Portfolio APIs for multi-chain wallet views
  • Prices APIs for spot and historical token pricing

Agents can start with as little as $1 in compute credits, equivalent to $1 of CUs in our pay-as-you-go tier. No contracts. No approval queues.

Alchemy Skills

We also publish Alchemy Skills: structured, machine-readable documentation designed for agents rather than humans. Skills tell an agent what we offer, which endpoints are available, and how to call them, so agents can discover and integrate our products without reading human docs.

Alchemy CLI

Our CLI gives you a command-line interface for the platform. Create projects, generate API keys, query RPC endpoints, and check network status without leaving the terminal. For x402 development, the CLI handles the setup so you can focus on the agent logic: initialize a project, configure your target chains, and start making authenticated requests in minutes.

How to start building with x402

Ready to try it? Four paths depending on where you want to start:

  • Read the full spec and explore the reference SDK at x402.org
  • Clone the coinbase/x402 repo on GitHub and run the examples
  • Build agents that pay for blockchain data through our agent platform, which supports x402 natively: no API key required, just a wallet and an HTTP call
  • Use our CLI to set up your project, create keys, and start querying endpoints from the terminal

For testnet development, get Base Sepolia ETH from the Alchemy Faucet and USDC test tokens from the Circle Faucet.

Frequently asked questions

What is the x402 protocol?

x402 is an open-source protocol that uses the HTTP 402 "Payment Required" status code to embed cryptocurrency payments directly into web requests. It lets AI agents, apps, and bots pay for API calls and digital services in real time without API keys, subscriptions, or manual billing setup.

How does the x402 payment flow work?

A client sends an HTTP request. The server responds with a 402 status and payment terms. The client pays (typically in USDC) and retries with a payment header. The server verifies the payment and returns the resource with a 200 OK.

What blockchains does x402 support?

x402 V2 supports Base, Solana, Ethereum, Polygon, Starknet, and Injective, with plans to expand to all L1s and L2s that support stablecoin transactions. It also supports legacy payment rails like ACH, SEPA, and card networks through pluggable facilitators.

What is the x402 Foundation?

The x402 Foundation launched in April 2026 under the Linux Foundation as a vendor-neutral body governing the x402 protocol. It has over 20 founding members including Google, Visa, Stripe, AWS, Mastercard, Circle, Microsoft, Shopify, and American Express.

What is the difference between x402 and MPP?

x402 embeds stablecoin payments directly into HTTP. MPP (Machine Payments Protocol) extends the same 402 pattern with payment-method-agnostic rails, session-based billing, MCP transport support, and standardized protocol primitives like idempotency and replay protection. MPP is backwards compatible with x402. Read the full comparison.

Do I need to write blockchain code to use x402?

No. Facilitators handle payment verification and on-chain settlement, so API developers can accept x402 payments without writing blockchain logic. V2 supports multiple facilitators that plug in as standalone packages.

Can AI agents use Alchemy with x402?

Yes. Alchemy runs an agentic gateway that supports x402 natively. An agent authenticates with its onchain wallet, pays in USDC on Base, and accesses Core RPC (100+ chains), NFT, Portfolio, and Prices APIs. No API key, dashboard, or human setup required. Start at alchemy.com/agents.

What cryptocurrency does x402 use for payments?

x402 primarily uses USDC, a dollar-denominated stablecoin, for payments. V2 expanded support to tokens across multiple chains and networks. The protocol also supports legacy payment rails (ACH, SEPA, cards) through pluggable facilitators, though stablecoins remain the primary payment method.

How do I get started building with x402?

Start with the x402.org spec and reference SDK, the coinbase/x402 GitHub repo, or Alchemy's agent platform for building agents that access blockchain data using x402. The Alchemy CLI provides a fast path from setup to querying endpoints.

Alchemy Newsletter

Be the first to know about releases

Sign up for our newsletter

Get the latest product updates and resources from Alchemy

A
O
D
+
Over 80,000 subscribers

By entering your email address, you agree to receive our marketing communications and product updates. You acknowledge that Alchemy processes the information we receive in accordance with our Privacy Notice. You can unsubscribe anytime.