Skip to content

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.

  1. Agent sends a request to any inference endpoint without an API key
  2. The server responds with 402 Payment Required including a product catalog
  3. Agent selects a product (subscription or credit package) and pays via USDC on Base
  4. Agent receives an API key and uses it for all subsequent requests

When a request arrives without an API key, the response includes available products:

{
"error": "Payment Required",
"x402": {
"version": 1,
"accepts": [
{
"scheme": "exact",
"network": "base",
"asset": "USDC",
"payTo": "0x...",
"maxTimeoutSeconds": 300,
"extra": {
"name": "CheapestInference",
"facilitatorUrl": "https://...",
"products": [
{ "type": "subscription", "plan": "standard", "price": "20", "duration": "30 days" },
{ "type": "subscription", "plan": "pro", "price": "60", "duration": "30 days" },
{ "type": "credits", "minAmount": "10", "description": "Pay-as-you-go credits" }
]
}
}
]
}
}
ProductPriceWhat you get
Standard subscription$20 USDC30-day API key, 60 RPM, 3,333 TPM
Pro subscription$60 USDC30-day API key, 200 RPM, 13,333 TPM
Credits$10+ USDCPay-as-you-go balance, 60 RPM, never expires
Terminal window
# 1. Agent requests without key
curl /v1/chat/completions
402 Payment Required
{ "products": [...], "network": "base" }
# 2. Agent subscribes with USDC
curl -X POST /api/billing/checkout
-d '{"planSlug": "pro", "method": "usdc"}'
{ "address": "0x...", "amount": "60" }
# 3. Agent sends USDC and verifies
curl -X POST /api/billing/verify-usdc
-d '{"txHash": "0xabc...", "planSlug": "pro"}'
{ "apiKey": "sk_live_..." }
# 4. Agent uses key for inference
curl /v1/chat/completions
-H "Authorization: Bearer sk_live_..."

CheapestInference serves an agent card at:

GET /.well-known/agent.json

This 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.

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.