0%

How x402 Brings Real-Time Crypto Payments to the Web

Author: Uttam Singh

Last updated: 31 October 20253 min read
x402 payment flow

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 →

A screenshot of x402scan

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

  1. A client requests a resource from the server.

  2. If payment is needed, the server returns a 402 Payment Required response containing payment instructions.

  3. The client reads the payment details, sends a transaction, and retries the request with the X-PAYMENT header.

  4. The server verifies the payment (locally or via a facilitator).

  5. 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

text
Copied
git clone <https://github.com/dabit3/a2a-x402-typescript.git> cd a2a-x402-typescript

2. Copy Env File

text
Copied
cp .env.example .env

3. Set Environment Variables

Update your .env for both client and merchant:

Need testnet funds?

4. Install & Build

text
Copied
cd x402_a2a npm install npm run build

5. Run Merchant Server

text
Copied
cd merchant npm install npm run dev

6. Run Client App

text
Copied
cd ../client npm install npm run web

Now 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:

Alchemy Newsletter

Be the first to know about releases