x402 Protocol
The x402 protocol enables AI agents to subscribe 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 subscription 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 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", "pool": "frontier", "name": "Frontier Pool — Kimi K2.7, Kimi K2.6, GLM 5.2, MiniMax M3", "models": ["kimi-k2.7", "kimi-k2.6", "glm-5.2", "minimax-m3"], "currency": "USDC", "duration": "30 days", "blocks": [ { "block": "asia", "hoursUtc": "00:00-08:00 UTC", "priceUsdc": "52.00", "status": "limited" }, { "block": "europe", "hoursUtc": "08:00-16:00 UTC", "priceUsdc": "61.00", "status": "limited" }, { "block": "americas", "hoursUtc": "16:00-24:00 UTC", "priceUsdc": "59.00", "status": "sold-out" } ], "agentCheckout": { "endpoint": "https://api.cheapestinference.com/api/agent/subscribe-pool", "method": "POST", "body": { "txHash": "<USDC_TX_HASH>", "poolSlug": "frontier", "blocks": ["asia"], "signature": "<WALLET_SIGNATURE>" } } } ], "docs": "https://docs.cheapestinference.com/guides/x402" }}Products
Section titled “Products”Pool subscriptions are billed per 8-hour daily time block. Each visible pool appears as one product in the catalog — pick a pool, then reserve one or more of its blocks (all three = full 24/7). Prices are returned live in the 402 catalog — the values below are illustrative (Frontier Pool shown; Core Pool blocks are ~$6.99 USDC each); always read blocks[].priceUsdc from the response and send the summed amount of your chosen blocks.
| Product | Price (illustrative) | What you get |
|---|---|---|
| Pool block (Asia-Pacific) | ~$52 USDC | 30-day unlimited key for that 8h daily window, no token caps |
| Pool block (Europe) | ~$61 USDC | 30-day unlimited key for that 8h daily window |
| Pool block (Americas) | ~$59 USDC | 30-day unlimited key for that 8h daily window |
| All three blocks | sum of the three | Full 24/7 unlimited access |
Agent flow
Section titled “Agent flow”# 1. Agent requests without key — gets 402 with the live product catalogcurl https://api.cheapestinference.com/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{"model": "kimi-k2.7", "messages": [{"role": "user", "content": "Hello"}]}'→ 402 { "x402": { "version": 2, "products": [...], "payTo": "0x..." } }
# 2. Agent sends the summed USDC price of its chosen blocks to payTo on Base.## 3. Agent SIGNS a claim message with the SAME wallet it paid from, proving it# controls that wallet — without this, anyone who sees the public txHash on# Base could claim the key. Message (exact):# CheapestInference: claim pool subscription for transaction <txHash>## 4. Agent subscribes with txHash + poolSlug + blocks + signaturecurl -X POST https://api.cheapestinference.com/api/agent/subscribe-pool \ -H "Content-Type: application/json" \ -d '{"txHash": "0xabc...", "poolSlug": "frontier", "blocks": ["asia"], "signature": "0x<sig>"}'→ { "success": true, "data": { "apiKey": "sk-...", "pool": "frontier", "blocks": ["asia"], "amountUsdc": "52.00", "expiresAt": "..." } }
# The call is idempotent: resend the same signed request to safely retry — if a# key mint transiently failed, the retry delivers it (the payment is never# double-charged, and the txHash is bound to the paying wallet).
# 3. Agent uses key for inferencecurl https://api.cheapestinference.com/v1/chat/completions \ -H "Authorization: Bearer sk-..." \ -H "Content-Type: application/json" \ -d '{"model": "kimi-k2.7", "messages": [{"role": "user", "content": "Hello"}]}'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.
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 ensure sustainable pricing while giving agents full autonomy.