x402 Protocol
The x402 protocol enables AI agents to subscribe or purchase credits on CheapestInference autonomously — no human setup required. Agents pay with USDC on Base L2 and receive an API key instantly.
How it works
Section titled “How it works”- Agent sends a request to any inference endpoint without an API key
- The server responds with
402 Payment Requiredincluding a product catalog - Agent selects a product (subscription or credit package) and pays via USDC on Base
- Agent receives an API key and uses it for all subsequent requests
402 response format
Section titled “402 response format”When a request arrives without an API key, the response includes available products:
{ "error": "Payment Required", "message": "Subscribe or purchase credits to access AI inference. Use the endpoints below to get an API key.", "x402": { "version": 2, "network": "base", "asset": "USDC", "payTo": "0x...", "facilitator": "https://...", "products": [ { "type": "subscription", "plan": "standard", "name": "Standard", "price": "20", "currency": "USDC", "duration": "30 days", "limits": { "rpm": 60, "tpm": 3333 }, "agentCheckout": { "endpoint": "https://api.cheapestinference.com/api/agent/subscribe", "method": "POST", "body": { "txHash": "<USDC_TX_HASH>", "planSlug": "standard" } } }, { "type": "subscription", "plan": "pro", "name": "Pro", "price": "60", "currency": "USDC", "duration": "30 days", "limits": { "rpm": 200, "tpm": 13333 }, "agentCheckout": { "endpoint": "https://api.cheapestinference.com/api/agent/subscribe", "method": "POST", "body": { "txHash": "<USDC_TX_HASH>", "planSlug": "pro" } } }, { "type": "credits", "minAmount": "10.00", "currency": "USDC", "description": "Pay-as-you-go credits, never expire", "agentTopup": { "endpoint": "https://api.cheapestinference.com/api/agent/topup", "method": "POST", "body": { "txHash": "<USDC_TX_HASH>", "amount": "<AMOUNT_USD>" } } } ], "docs": "https://docs.cheapestinference.com/guides/x402" }}Products
Section titled “Products”| Product | Price | What you get |
|---|---|---|
| Standard subscription | $20 USDC | 30-day API key, 60 RPM, 3,333 TPM |
| Pro subscription | $60 USDC | 30-day API key, 200 RPM, 13,333 TPM |
| Credits | $10+ USDC | Pay-as-you-go balance, 60 RPM, never expires |
Agent flow
Section titled “Agent flow”# 1. Agent requests without key — gets 402 with product catalogcurl https://api.cheapestinference.com/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{"model": "deepseek-chat", "messages": [{"role": "user", "content": "Hello"}]}'→ 402 { "x402": { "version": 2, "products": [...], "payTo": "0x..." } }
# 2. Agent sends USDC to the payTo address on Base, then subscribescurl -X POST https://api.cheapestinference.com/api/agent/subscribe \ -H "Content-Type: application/json" \ -d '{"txHash": "0xabc...", "planSlug": "pro"}'→ { "success": true, "data": { "subscriptionId": "...", "keys": [...] } }
# 3. Agent uses key for inferencecurl https://api.cheapestinference.com/v1/chat/completions \ -H "Authorization: Bearer sk_live_..." \ -H "Content-Type: application/json" \ -d '{"model": "deepseek-chat", "messages": [{"role": "user", "content": "Hello"}]}'For credit top-ups, agents use a similar flow:
# Send USDC, then verifycurl -X POST https://api.cheapestinference.com/api/agent/topup \ -H "Content-Type: application/json" \ -d '{"txHash": "0xdef...", "amount": 50}'→ { "success": true, "data": { "credited": true, "newBalance": 50 } }Agent discovery (A2A)
Section titled “Agent discovery (A2A)”CheapestInference serves an agent card at:
GET /.well-known/agent.jsonThis follows the Google A2A protocol and advertises:
- Available skills (inference, model listing)
- Supported auth methods (bearer key, x402)
- Streaming capability
- API endpoint URL
Agents can discover CheapestInference and autonomously decide to subscribe or purchase credits.
Why not pay-per-request?
Section titled “Why not pay-per-request?”Pay-per-request doesn’t work for AI inference because request costs vary wildly depending on the model and token count. A flat $0.002 request to a model that costs $2/M tokens on a 100K prompt would lose money. Subscriptions and credits ensure sustainable pricing while giving agents full autonomy.