How x402 brings real-time crypto payments to the web
Author: Uttam Singh

x402 is an open-source protocol that revives the long-dormant HTTP 402 “Payment Required” status code to enable internet-native payments.
This protocol allows AI agents or bots to pay for services in real time using crypto.
Instead of relying on API keys or subscriptions, an agent sends a request, receives a 402 response with payment terms, settles the payment in USDC (on Base), and retries the request to access the resource. x402 is chain-agnostic and designed for seamless integration across services.

With x402, autonomous agents can access paid services directly, unlocking premium resources by responding to real-time payment prompts, without human intervention or pre-configured credentials.
This is in production, and agents are transacting today. You can explore live transactions and integrations on x402scan.com →

The fundamentals: APIs & status codes
Before diving deeper into x402, let’s quickly cover the basics for anyone without a developer background.
Every app or AI agent communicates with servers using APIs (Application Programming Interfaces). These servers respond to API calls with a status code and some data.
For example, some common status codes include:
- 200 → OK (request successful)
- 404 → Not Found
- 402 → Payment Required
The interesting part? The 402 code has existed in HTTP since the 90s, but has never been actively used. Most developers hadn’t even heard of it.
Usually, developers sign up on a platform, attach a credit card, get an API key, and are charged based on usage. x402 completely changes that model.
Instead of API keys and billing dashboards, payments happen directly within the API call. A request can trigger a 402 Payment Required, and the client can pay with crypto (like USDC) as part of the same interaction.
This is what makes x402 so powerful: it merges HTTP and blockchain into one flow, letting the web itself become a payment rail.
Who is x402 for?
- Developers & API providers who want pay-per-use monetization without accounts or subscriptions.
- AI agents, bots, or IoT devices that need to make payments autonomously.
- Builders exploring A2A (Agent-to-Agent) or machine commerce flows.
x402 is perfect for AI inference APIs, micropayments for data access, token-gated content, and real-time agent interactions.
Architecture & core components
Client–server model
- A client requests a resource from the server.
- If payment is needed, the server returns a 402 Payment Required response containing payment instructions.
- The client reads the payment details, sends a transaction, and retries the request with the X-PAYMENT header.
- The server verifies the payment (locally or via a facilitator).
- Once verified, the server returns the requested resource with a 200 OK.
Facilitators
Facilitators are services that make adoption easier for developers. They handle verification and on-chain settlement, meaning an API developer doesn’t have to write blockchain logic themselves.
Think of facilitators as payment processors for the decentralized web: they confirm a user’s authorization, execute the transaction on-chain, and return confirmation to the API in milliseconds.

How to get started
You can get started with A2A x402 Extension Code that brings cryptocurrency payments to the Agent-to-Agent (A2A) protocol, enabling agents to monetize their services through on-chain payments. This extension revives the spirit of HTTP 402 "Payment Required" for the decentralized agent ecosystem.
Let’s start with the TypeScript implementation of it built by @dabit3, which enables your AI agents to request, verify, and settle crypto payments seamlessly.
1. Clone the repo
git clone <https://github.com/dabit3/a2a-x402-typescript.git>
cd a2a-x402-typescript2. Copy env file
cp .env.example .env3. Set environment variables
Update your .env for both client and merchant:
- ALCHEMY_API_KEY → Alchemy Dashboard
- GOOGLE_GEMINI_KEY → Google AI Studio
- WALLET_PRIVATE_KEY and WALLET_ADDRESS → your dev wallet credentials
Need testnet funds?
- Base Sepolia ETH (for gas): Alchemy Faucet
- USDC test tokens (for payments): Circle Faucet
4. Install & build
cd x402_a2a
npm install
npm run build5. Run merchant server
cd merchant
npm install
npm run dev6. Run client app
cd ../client
npm install
npm run webNow your client and merchant agents can communicate using x402 — exchanging HTTP requests that include real-time on-chain payments.
Once you’ve tested the demo, you can go further build your own agent & extend it to build apps that can sell digital goods (e-books, music, courses) via a simple API call where each download triggers a 402 Payment Required flow.
What can you build with x402?
- Pay-per-API-call endpoints for AI inference or data APIs
- Micropayments for content like images, videos, or research papers
- Autonomous A2A (Agent-to-Agent) - Let AI agents buy data, compute, or API access from other agents.
- Usage-based compute/storage billing: Pay-as-you-go access to data, API endpoints, or resources.
- Freemium APIs that unlock premium tiers via crypto payments
Next steps
If you want to learn more about x402 and start building, here are some helpful resources to get you started:
- Explore live x402 data on x402scan.com
- Read the full spec at x402.org
- Check the reference repo coinbase/x402
- Get your Alchemy RPC endpoints
- Start building your own agent-to-agent payment flow!
Frequently asked questions
What is x402?
x402 is an open-source protocol that uses the HTTP 402 "Payment Required" status code to enable real-time crypto payments for APIs, webpages, and content without requiring API keys or subscriptions.
How does the x402 payment flow work?
A client requests a resource, the server responds with a 402 status and payment terms, the client sends payment with the X-PAYMENT header, the server verifies it, and then delivers the resource with a 200 OK response.
What role do facilitators play in x402?
Facilitators handle verification and on-chain settlement so API developers don't have to write blockchain logic themselves, acting as payment processors for the decentralized web by confirming authorization and executing transactions.
Who should use x402?
x402 is designed for developers and API providers wanting pay-per-use monetization, AI agents or bots that need autonomous payments, and builders exploring agent-to-agent or machine commerce flows.
Is x402 limited to specific blockchains?
No, x402 is chain-agnostic and supports multiple networks including Base, Solana, and other blockchains for seamless integration across services.
What are some practical use cases for x402?
You can build pay-per-API-call endpoints for AI inference, micropayments for digital content, autonomous agent-to-agent commerce, and usage-based compute or storage billing.
Do I need a facilitator to use x402?
No, facilitators are optional but recommended as they simplify integration by handling blockchain verification and settlement, allowing developers to avoid writing complex blockchain logic.
How do I get started building with x402?
Clone the a2a-x402-typescript repository, set up your environment variables including an Alchemy API key, install dependencies, and run both the merchant server and client app to test payment flows.
Alchemy Newsletter
Be the first to know about releases
Sign up for our newsletter
Get the latest product updates and resources from Alchemy
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.
Related articles
Stablecoin treasuries: from dead capital to yield-generating infrastructure
Most corporate stablecoin balances earn nothing while issuers capture yield on reserves. Learn where onchain yield comes from, what blocks enterprise deployment, and how infrastructure like gasless transactions and multi-chain RPC closes the gap.

The enterprise stablecoin guide
A practical guide to using stablecoins in enterprise payments—covering why legacy rails fail, which stablecoin types and chains to choose, privacy considerations, and when (not) to issue your own.

Deposit tokens for banks: a practical playbook
Major banks are quietly processing $10B+ daily in tokenized deposits. Here's how deposit tokens could capture $140 trillion by 2030 and a playbook to integrate for banks.