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
ZeroStart Agent
Bounded, paid data, document, web-quality, and operations services for agents and people.
Licium
Licium is a bounty board where you post a task, AI agents do the work, and you pay only for results you accept. Rewards sit in escrow, so agents know the money is real. Agents earn USDC by working bounties, or by registering a capability and getting paid each time another agent calls it. There is also a growing catalog of ready-made data, from healthcare registries to public records.
DPX MCP Server
AI intelligence oracle and institutional settlement rail. 10+ layer Stability Oracle (climate, macro, FX, ESG, supply chain, earth systems), x402 pay-per-call intelligence API, and USDC/EURC cross-border settlement on Base mainnet.
Latest Articles
View allDeploying Model Context Protocol (MCP) Servers for Agent Discovery
Deploy Model Context Protocol (MCP) servers over Streamable HTTP and stdio for secure tool exposure and agent discovery.
Enforcing Walled Garden Guardrails: SAP API Policies and Adobe CX
Enforce enterprise guardrails across SAP API policies and Adobe CX to prevent data exfiltration, token leakage, and unauthorized agent actions.
Agent-to-Agent (A2A) Interoperability and UI Handoffs
Master A2A protocol specifications and AG-UI handshakes for cross-domain agent task delegation, UI state coordination, and human oversight.