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:| Header | Direction | Purpose |
|---|---|---|
PAYMENT-REQUIRED | Server to Client | 402 challenge with pricing info |
PAYMENT-SIGNATURE | Client to Server | Signed payment payload |
PAYMENT-RESPONSE | Server to Client | Settlement confirmation |
Payment Flow
Server returns 402
The API responds with HTTP 402 and a
PAYMENT-REQUIRED header containing pricing details (amount, token, chain, payTo address).Agent pays via AgentWallex
The agent sends the payment details to
POST /x402/pay. AgentWallex evaluates policies and signs the payment.Agent retries with payment proof
The agent retries the original request with the
PAYMENT-SIGNATURE header attached.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:
| Field | Description |
|---|---|
ledger_id | Internal ledger entry ID |
amount | Payment amount |
fee_amount | Platform fee deducted |
fee_rate | Fee percentage applied |
token | Token used (e.g., USDC) |
chain | Chain used for settlement |
status | Payment status |
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:
Verify and Settle
Use the AgentWallex facilitator endpoints:Operational Defaults
| Parameter | Value |
|---|---|
| Settlement interval | 300 seconds |
| Settlement threshold | $10.00 |
| Max settlement delay | 3,600 seconds |
| Supported chains | eip155:84532, eip155:8453, eip155:1, eip155:137 |