X402 Payment Protocol
X402 Payment Protocol
Section titled “X402 Payment Protocol”Agentis implements the X402 HTTP payment protocol, the emerging standard for AI agent payments.
Overview
Section titled “Overview”The X402 protocol enables:
- Standardized Payments - Consistent payment flow across all APIs
- Agent Compatibility - AI agents can automatically handle payments
- Micro-transactions - Support for very small payments per API call
- Global Accessibility - No KYC or traditional banking required
Protocol Flow
Section titled “Protocol Flow”- Initial Request - Client makes request to API endpoint
- Payment Required - Server responds with 402 status and payment details
- Payment Processing - Client processes payment using specified method
- Authenticated Request - Client retries request with payment proof
- Response Delivery - Server validates payment and returns data
Response Format
Section titled “Response Format”When payment is required, APIs return a 402 status with payment details:
HTTP/1.1 402 Payment RequiredContent-Type: application/json
{ "x402Version": 1, "error": "Payment required", "accepts": [{ "scheme": "eip712", "network": "base", "maxAmountRequired": "1000000", "resource": "/api/protected", "payTo": "0x742d35Cc6634C0532925a3b8D71E432BD78FE7", "asset": "USDC" }]}
Payment Schemes
Section titled “Payment Schemes”EIP-712 Signatures
Section titled “EIP-712 Signatures”The primary payment method uses EIP-712 typed signatures:
{ "scheme": "eip712", "network": "base", "maxAmountRequired": "1000000", "payTo": "0x742d35Cc6634C0532925a3b8D71E432BD78FE7", "asset": "USDC"}
Header Format (Legacy)
Section titled “Header Format (Legacy)”Some APIs may use the legacy header-based format:
HTTP/1.1 402 Payment RequiredX-Payment-Requirements: {"amount":"0.01","token":"USDC","recipient":"0x...","chain":1}
Implementation
Section titled “Implementation”When implementing X402 in your API:
- Detect payment requirement - Check if user has valid payment session
- Return 402 response - Include payment details in response body
- Validate payment proof - Verify payment signature on retry
- Process request - Handle the original request after payment validation
Benefits for AI Agents
Section titled “Benefits for AI Agents”- Automatic discovery - Agents can detect payment requirements
- Standardized flow - Consistent payment process across services
- Micro-payment support - Enable small, frequent payments
- No human intervention - Fully autonomous payment processing