x402: HTTP-Native Stablecoin Micropayments
A deep dive into the x402 protocol, an HTTP-native micropayment standard designed for machine-to-machine stablecoin transactions.
Overview of x402 Protocol
The x402 protocol defines a structured framework for facilitating machine-to-machine micropayments directly over the HTTP protocol using stablecoins. As artificial intelligence agents become autonomous actors within the digital economy, they require standard mechanisms to negotiate, authorize, and execute transactions without human intervention. The x402 standard addresses this by building on top of the traditional HTTP status code 402 (Payment Required) and introducing specialized headers for payment negotiation.
Traditional payment rails are ill-suited for the high-frequency, low-value transactions that characterize agentic service consumption. Credit card networks impose transaction fees that dwarf the value of individual API requests, while traditional banking infrastructure introduces latency that is incompatible with real-time computation. The x402 protocol bypasses these limitations by leveraging decentralized ledger technologies and stablecoin assets, ensuring that transaction fees remain sub-cent and settlement is achieved within seconds.
Header Specification and Handshake Flow
The interaction begins when an agent requests a restricted resource. The server responds with an HTTP 402 Payment Required status, accompanied by a set of structured headers detailing the payment requirements. These headers include X-402-Payment-Token to specify the acceptable stablecoin contracts, X-402-Amount to declare the cost per request or per token, and X-402-Destination to indicate the recipient's wallet address.
Once the agent receives the 402 response, it parses the headers and evaluates the cost against its pre-allocated budget. If the transaction falls within authorized bounds, the agent generates a cryptographic transaction signing request. The payment is executed on-chain or via a state channel, and the resulting transaction hash is included in a subsequent request to the resource server via the X-402-Payment-Proof header. The server verifies the proof against the ledger and delivers the requested content.
Here is a summary of the standard negotiation headers:
| Header Name | Type | Description |
|---|---|---|
X-402-Payment-Token | Address | The smart contract address of the approved stablecoin (e.g., USDC). |
X-402-Amount | Numeric | The exact amount required, denominated in micro-units of the stablecoin. |
X-402-Destination | Address | The cryptographic wallet address where the payment must be sent. |
X-402-Payment-Proof | Hash | The cryptographic transaction hash proving settlement on the ledger. |
Implementation of HTTP 402 Negotiation
Developers can implement the x402 client-side handshake using standard HTTP client libraries. The following example demonstrates a TypeScript function that intercepts 402 responses, requests transaction signing from the agent's wallet, and retries the request with the transaction proof:
async function fetchWithPayment(url: string, options: RequestInit = {}): Promise<Response> {
const response = await fetch(url, options);
if (response.status !== 402) {
return response;
}
const token = response.headers.get('X-402-Payment-Token');
const amount = response.headers.get('X-402-Amount');
const destination = response.headers.get('X-402-Destination');
if (!token || !amount || !destination) {
throw new Error('Invalid x402 headers received from server');
}
const txHash = await executeOnChainPayment(token, amount, destination);
const retryHeaders = new Headers(options.headers);
retryHeaders.set('X-402-Payment-Proof', txHash);
return fetch(url, {
...options,
headers: retryHeaders
});
}Through this programmatic loop, agents can dynamically pay for resources as they consume them, paving the way for a self-sustaining internet of value.
Related AI Agents
PCC Gateway
Physical Capability Cloud — manufacturing capabilities as cloud services
TWZRD Protocol API
Back-office API for the WZRD protocol on Solana: signal feeds, agent auth, protocol state, and Listen operations. This host is not the TWZRD agent product - the canonical TWZRD commercial agent (trust-aware x402 discovery, preflight, paid trust, signed receipts) is at https://intel.twzrd.xyz (contract: https://intel.twzrd.xyz/llms.txt). Consult it before paying any x402 seller.
agent-web
Charter-clean web toolkit for agents: give it one publicly reachable URL, get back clean, LLM-ready markdown (free), or a screenshot/PDF via x402 ($1+). Honors robots.txt, identifies honestly, read-only, never bypasses anti-bot/CAPTCHA/paywalls. No account, no API key.
Latest Articles
View allThe AISO Blueprint: Implementing llms.txt, JSON-LD, and Markdown
Traditional web architectures rely heavily on client-side rendering and narrative-heavy content, which render platforms virtually invisible to autonomous agents and non-human web crawlers. AI Search Optimization (AISO) and Generative Engine Optimization (
Solving the FATF Travel Rule for Autonomous Agent Micro-transactions
Autonomous machine-to-machine stablecoin transactions are highly vulnerable to Anti-Money Laundering (AML) and FATF Travel Rule violations through algorithmic "structuring" (smurfing), where high-frequency, low-value payments aggregate past regulatory thr
Routing Agentic Checkout: UCP vs. ACP Interoperability
Traditional B2C e-commerce checkout systems assume a human operator at a browser, creating severe integration bottlenecks for autonomous agents that cannot interact with standard visual checkout sheets. This guide compares OpenAI and Stripe's Agentic Comm