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!
Alchemy Newsletter
Be the first to know about releases
Related articles

The Stablecoin Landscape Across Different Chains
A data-driven look at where $300B+ in stablecoins actually live and move across major blockchains like Ethereum, Solana, Tron, and emerging L1s.

The Developer's Guide to Blockchain App Development Costs in 2025
Want to know what kind of budget you'll need to build an app onchain?

Smart Wallet APIs for Financial Institution Requirements
The stablecoin market has surged to over $240 billion and is projected to hit $2 trillion by 2028. Major banks are launching stablecoins while Congress passed the GENIUS Act. Smart Wallet APIs help financial institutions integrate onchain
