x402 Protocol
The x402 protocol enables pay-per-request access to CheapestInference. AI agents can make API calls and pay with USDC on Base L2 — no account, no subscription, no API key required.
How it works
Section titled “How it works”- Agent sends a request to
/v1/chat/completions(or any inference endpoint) without an API key - The server responds with
402 Payment Requiredincluding payment details - Agent pays the specified amount via the x402 facilitator
- Agent retries the request with an
X-Paymentheader containing the proof of payment - The server verifies the payment and forwards the request
402 response format
Section titled “402 response format”When a request arrives without an API key, the response looks like:
{ "error": "Payment Required", "x402": { "version": 1, "accepts": [ { "scheme": "exact", "network": "base", "maxAmountRequired": "0.002", "asset": "USDC", "payTo": "0x...", "maxTimeoutSeconds": 300, "extra": { "name": "CheapestInference", "facilitatorUrl": "https://..." } } ] }}Pricing
Section titled “Pricing”| Plan | x402 price per request |
|---|---|
| Standard | $0.002 |
| Pro | $0.001 |
Payment verification
Section titled “Payment verification”The X-Payment header is verified through the x402 facilitator:
- Server sends the payment proof to the facilitator’s
/verifyendpoint - Facilitator confirms the USDC transfer on Base
- If valid, the server authenticates and forwards the request
- The
x-x402-payerheader is set with the payer’s wallet address for tracking
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 use x402 for payment.
Use cases
Section titled “Use cases”- Autonomous agents — AI agents that need inference without human setup
- Agent-to-agent — One agent paying for another agent’s inference
- Micropayments — Pay exactly for each request, no commitment