What is x402?
x402 is a machine-to-machine payment protocol built around HTTP402 Payment Required. It enables AI agents to automatically pay for API access without human intervention. AgentWallex implements x402 v2 with EIP-3009 authorization payloads.
x402 v2 Headers
The protocol uses three HTTP headers:Payment Flow
1
Agent requests a resource
The agent sends a standard HTTP request to a paid API endpoint.
2
Server returns 402
The API responds with HTTP 402 and a
PAYMENT-REQUIRED header containing pricing details (amount, token, chain, payTo address).3
Agent pays via AgentWallex
The agent sends the payment details to
POST /x402/pay. AgentWallex evaluates policies and signs the payment.4
Agent retries with payment proof
The agent retries the original request with the
PAYMENT-SIGNATURE header attached.5
Server verifies and responds
The API verifies the payment signature (via the AgentWallex facilitator) and returns the resource.
Using x402 APIs
Check if a URL Supports x402
Create a Session Budget
Sessions let you pre-authorize a spending budget for repeated API calls:Trigger Payment Negotiation
payment_info with:
SDK Integration
Automatic HTTP Interceptor
The TypeScript SDK provides an interceptor that handles the full x402 flow automatically:Manual Flow
For Service Providers
If you expose paid APIs, your server should return an x402 v2 challenge when payment is missing.Return 402 with PAYMENT-REQUIRED
Encode a JSON challenge (base64) into thePAYMENT-REQUIRED header: