Pay for LLM API calls with USDC, without an account or an API key
With OpenCheap, an AI agent pays for one LLM call in USDC on Base, with no account and no API key. It sends the request with no key, the API answers 402 Payment Required with the price of that completion, the agent signs the payment from its wallet and repeats the request, and the answer comes back in the same response. This is the open x402 protocol, so any x402 client works, and every chat model in the catalog can be paid this way.
How one call is paid
Three steps, in one request and its retry.
- 1Call with no keySend the chat completion with no Authorization header. Every chat model works.
- 2Read the 402The answer is
402with aPAYMENT-REQUIREDheader: schemeexact, networkeip155:8453(Base), the USDC asset, the payee and the amount in 6-decimal units.x-quote-modelandx-quote-max-tokenssay what the amount covers. - 3Sign and repeatThe agent signs an EIP-3009 authorization for that amount and repeats the request with
PAYMENT-SIGNATURE(the olderX-PAYMENTworks too). The completion is in that response; the transfer settles in the background.
An agent on Base, in TypeScript
@x402/fetch reads the 402, signs with the wallet you give it, and retries.
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";
const wallet = privateKeyToAccount(process.env.AGENT_PRIVATE_KEY);
const pay = wrapFetchWithPaymentFromConfig(fetch, { schemes: [{ network: "eip155:*", client: new ExactEvmScheme(wallet) }] });
// No Authorization header: the API answers 402 with the price, pay() signs and retries.
const res = await pay("https://api.opencheap.si/v1/chat/completions", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model: "claude-sonnet-5", max_tokens: 400, messages: [{ role: "user", content: "Summarise this page" }] }),
});
console.log((await res.json()).choices[0].message.content);# 1. Ask with no key
curl -i https://api.opencheap.si/v1/chat/completions -H "Content-Type: application/json" \
-d '{ "model": "kimi-k3", "max_tokens": 256, "messages": [{ "role": "user", "content": "Hello" }] }'
# HTTP/2 402
# payment-required: <base64 x402 v2 challenge: scheme exact, network eip155:8453,
# asset USDC, payTo, amount in 6-decimal units>
# x-quote-model: kimi-k3
# x-quote-max-tokens: 256
# 2. Sign an EIP-3009 USDC authorization for that amount, then repeat the same request
# with the header PAYMENT-SIGNATURE: <signed payload>. The completion is in that response.The catalog with every model's rate needs no key either: GET https://app.opencheap.si/api/v1/models. The full protocol, the quote rules and streaming are in the x402 docs.
Three ways an agent can pay
| Needs | Best for | |
|---|---|---|
| Per call with x402 | A Base wallet with USDC. No account, no key. | An agent that calls now and then, or that should never hold credentials. |
| A balance it tops up itself | An API key, and USDC on Base for the top-up. | Many calls: one balance, usage history, and a spend limit on the key. |
| Signed in with its wallet | A wallet that signs a Sign-In with Ethereum message. No email, no password. | An agent that runs its own account, keys and budgets from code or MCP. |
Questions, answered
Can an AI agent pay for LLM tokens without an account or an API key?
Yes. On OpenCheap an agent calls https://api.opencheap.si/v1/chat/completions with no key, gets a 402 Payment Required with the USDC price of that one completion, signs the payment from its own wallet and repeats the request. The answer comes back in that response. This is the open x402 protocol, on Base.
What does the agent need?
A wallet that can sign an EIP-3009 USDC authorization on Base (eip155:8453), such as a viem account, and an x402 client, such as @x402/fetch with ExactEvmScheme. The private key stays with the agent.
How is the price of one call set?
Before the first byte, from the model's catalog rates, the prompt (about four characters per token) and the output cap: max_tokens, 512 when you set none and 4,096 at most. The quote is at least $0.001. The agent pays the quote, and the provider is held to that cap.
Which models can it pay for?
Every chat model in the catalog, ranked the same way as a call with a key: the cheapest healthy provider for that prompt, then the next one if it fails before the first byte. Decision models need a key.
Is the agent charged if the call fails?
A 404, or a 503 before any provider accepts the request, is not settled. The USDC transfer is submitted once a provider accepts, through the Coinbase facilitator.
Does it stream?
Yes. "stream": true returns server-sent events, the same chunks as a call with a key. The amount is still fixed up front from the output cap.
What if the agent makes many calls?
It can hold a balance instead: an agent with a key adds USDC on Base from its own wallet (a 5.5 % fee), then every call draws from that balance and can carry a spend limit. It can also sign in with its wallet to hold an account of its own.
More guides
OpenCheap is an LLM router that sends every request to the cheapest healthy provider of the model you name, fails over to the next one before the first byte, and bills you that provider's price.
One OpenCheap key calls models from Anthropic, Google, OpenAI, DeepSeek, Moonshot, Qwen and more through the OpenAI SDK you already use: change the base URL and the key.
On OpenCheap every key can carry its own daily, weekly, monthly or lifetime limit that refuses requests once it is reached, so an agent left running overnight cannot spend more than you allow.
Point Claude Code at OpenCheap with three environment variables and pick the model per task: Claude at the provider's price, or open models that cost a fraction of it, all on one key with a spend limit.