x402 payments provide a standardized method for AI agents to pay for API services directly using cryptocurrency, primarily USDC. This system extends the traditional HTTP protocol by embedding payment requests within standard HTTP 402 responses, enabling a seamless integration of financial transactions into automated workflows. The core idea is to allow AI agents to encounter a payment requirement, evaluate it against predefined rules, and execute the payment autonomously if authorized, ensuring controlled and auditable microtransactions for various digital services.
What x402 adds to an HTTP request
x402 payments introduce a specific layer to the HTTP protocol, allowing service providers to request payment for an API call before delivering the requested data or service. When an AI agent attempts to access a paid API endpoint, the server responds with an HTTP 402 Payment Required status code, accompanied by specific x402 headers. These headers contain crucial information about the payment, such as the required amount, the cryptocurrency to be used (e.g., USDC), the blockchain network for the transaction, and the payee's address.
This mechanism transforms a simple data request into a conditional transaction. Instead of a hard-coded subscription or a manual payment, the AI agent receives a real-time payment offer. This allows for granular, per-request billing, which is particularly beneficial for services that vary in cost based on usage or data volume. For instance, an AI agent querying a large language model API might receive an x402 request for 0.05 USDC for a short query or 0.50 USDC for a more complex one. This dynamic pricing model ensures that payments are directly tied to the value received, promoting efficiency and transparency in AI-driven interactions.
Inspect the offer before authorizing payment
Before an AI agent can authorize any x402 payment, it must meticulously inspect the payment offer presented in the HTTP 402 response. This inspection is critical for maintaining financial control and preventing unauthorized spending. The agent's wallet policy, which operates outside the AI model's direct control, plays a pivotal role here. This policy acts as a gatekeeper, evaluating the payment request against a set of predefined rules and thresholds.
Key elements to inspect in an x402 offer include:
- Advertised Amount: The exact amount of cryptocurrency requested (e.g., 0.10 USDC).
- Blockchain Network: The specific blockchain where the transaction must occur (e.g., Base, Ethereum).
- Payee Address: The cryptocurrency wallet address of the service provider.
- Resource Identifier: The specific API endpoint or resource being paid for.
Let's consider a hypothetical example: an AI agent requests data from a weather API. The API responds with an HTTP 402, including x402 headers that specify a payment of 0.10 USDC on the Base network to a particular payee address for the `/weather/current` endpoint. The agent's wallet policy then checks if this request aligns with its budget, the approved service allowlist, and the permitted transaction thresholds. If the policy permits, it can then authorize the payment. This stringent verification process ensures that every payment is intentional and within established financial boundaries, which is a core principle of Coinstancy Agentic Bank's approach to autonomous spending.
How verification and settlement fit into the flow
The verification and settlement process in x402 payments is designed to be efficient and secure, leveraging blockchain technology. Once an AI agent's wallet policy authorizes a payment, the transaction is initiated on the specified blockchain network. The service provider typically monitors this network for incoming payments to their designated address, often looking for a specific transaction hash or other identifiers included in the initial x402 request.
Here’s a simplified flow:
- Payment Authorization: The AI agent's wallet, governed by its policy, signs and broadcasts the cryptocurrency transaction (e.g., 0.10 USDC) to the blockchain.
- Blockchain Confirmation: The transaction is processed and confirmed by the blockchain network. The time this takes can vary depending on the network's congestion and the gas fees paid.
- Service Provider Verification: The API provider's system detects the confirmed payment on the blockchain. They verify that the payment matches the request details (amount, payee, resource) and originated from the requesting agent.
- Service Delivery: Upon successful verification, the service provider delivers the requested data or API response to the AI agent.
This entire process, from request to service delivery, can happen in a matter of seconds, making it suitable for real-time AI agent interactions. The use of a stablecoin like USDC minimizes price volatility risks during the brief settlement period, ensuring that the value of the payment remains consistent. This contrasts with traditional payment methods that can involve delays or chargebacks, making blockchain-based microtransactions a more robust solution for automated systems. For a broader understanding of payment flows for AI agents, you can explore our guide on
AI Agent Payments: How to Choose a Controlled Payment Flow.
Check the response and the payment evidence
After an x402 payment is successfully processed and the API service is delivered, it is crucial for the AI agent to verify the integrity of the response and retain evidence of the payment. This dual verification ensures accountability and provides an audit trail for all autonomous transactions. The agent should confirm that the received data or service aligns with what was requested and paid for.
Payment evidence typically includes:
- Transaction Hash: A unique identifier for the blockchain transaction.
- Block Number and Timestamp: Details confirming when the transaction was recorded on the blockchain.
- Sender and Receiver Addresses: The wallet addresses involved in the transaction.
- Payment Amount: The exact cryptocurrency amount transferred.
This evidence is vital for reconciliation and troubleshooting. If, for example, the AI agent receives an incomplete or incorrect response, the payment evidence can be used to dispute the transaction or seek a refund from the service provider. Coinstancy Agentic Bank automatically records these details, providing a clear history of all agent-initiated payments and ensuring transparency in financial operations. This auditability is a key feature for both individual users and organizations managing multiple AI agents.
What wallet policy must control outside the model?
While AI models are adept at processing information and making decisions, the critical financial controls for x402 payments must reside outside the AI model itself, within a robust wallet policy. This separation of concerns is fundamental for security, accountability, and user control over autonomous spending. The AI model can propose a payment, but the final authorization rests with a predefined, immutable set of rules managed by the user or organization.
Key aspects a wallet policy must control include:
- Budget Limits: Setting daily, weekly, or monthly spending caps for individual agents or groups of agents. For example, an agent might be limited to spending no more than 10 USDC per day on API calls.
- Service Allowlists: Specifying which API services or providers an agent is permitted to pay. This prevents agents from interacting with unauthorized or malicious services.
- Price Thresholds: Defining the maximum amount an agent can pay for a single transaction. A policy might dictate that any single x402 payment exceeding 1 USDC requires explicit human approval.
- Transaction Simulation: Enabling a