Docs
The API speaks OpenAI Chat Completions. Change the base URL and the key, and keep the rest of your code.
Base URL and authentication
Every request goes to this base URL:
https://api.cheapllm.wtf/v1Send your API key as a bearer token in the Authorization header:
Authorization: Bearer wtf_...Your first request
The Python and JavaScript examples use the official OpenAI SDK, and the JavaScript one works in TypeScript too. Only the base URL and the key change.
from openai import OpenAI
client = OpenAI(
base_url="https://api.cheapllm.wtf/v1",
api_key="wtf_...",
)
response = client.chat.completions.create(
model="anthropic/claude-haiku-4.5",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)Streaming
Pass stream: true and the response arrives as Server-Sent Events, just like with OpenAI. To get token usage in the last chunk, set stream_options.include_usage to true.
from openai import OpenAI
client = OpenAI(
base_url="https://api.cheapllm.wtf/v1",
api_key="wtf_...",
)
stream = client.chat.completions.create(
model="anthropic/claude-haiku-4.5",
messages=[{"role": "user", "content": "Hello!"}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="", flush=True)
if chunk.usage:
print("\n", chunk.usage)What you get
Each event is a data: line with a chat.completion.chunk. With include_usage, the last one has empty choices and the usage. The stream ends with data: [DONE].
data: {"id":"chatcmpl-req_...","object":"chat.completion.chunk","created":1794268800,"model":"anthropic/claude-haiku-4.5","choices":[{"index":0,"finish_reason":null,"delta":{"role":"assistant","content":"Hel"}}]}
: keep-alive
data: {"id":"chatcmpl-req_...","object":"chat.completion.chunk","created":1794268800,"model":"anthropic/claude-haiku-4.5","choices":[{"index":0,"finish_reason":"stop","delta":{"content":"lo!"}}]}
data: {"id":"chatcmpl-req_...","object":"chat.completion.chunk","created":1794268800,"model":"anthropic/claude-haiku-4.5","choices":[],"usage":{"prompt_tokens":9,"completion_tokens":3,"total_tokens":12}}
data: [DONE]During long pauses, for example while a model reasons, you'll get : keep-alive comment lines. The SSE standard says to ignore them, and the SDKs already do.
Errors mid-stream
If the model fails after the stream has started, the HTTP status is already 200. The error arrives as one last chunk, with an error object and finish_reason: "error", followed by [DONE]. The OpenAI SDKs raise it as an APIError.
data: {"id":"chatcmpl-req_...","object":"chat.completion.chunk","created":1794268800,"model":"anthropic/claude-haiku-4.5","choices":[{"index":0,"finish_reason":null,"delta":{"role":"assistant","content":"Hel"}}]}
data: {"id":"chatcmpl-req_...","object":"chat.completion.chunk","created":1794268800,"model":"anthropic/claude-haiku-4.5","error":{"message":"The model failed while generating the response.","type":"upstream_error","code":"upstream_error"},"choices":[{"index":0,"delta":{},"finish_reason":"error"}]}
data: [DONE]Reasoning
Reasoning models send their reasoning in reasoning_content: in delta when streaming, in message when not. The OpenAI SDKs don't type it, but they don't drop it either: read it as an extra field.
Choosing a model
Each model has an ID in the form author/model, like anthropic/claude-haiku-4.5. That's what goes in model.
The catalog shows every model with its price and discount. From code, call GET /v1/models: it's public and doesn't need a key.
curl https://api.cheapllm.wtf/v1/modelsHow billing works
You pay per token from your prepaid credits, at each model's cheapllm.wtf price.
- We count the tokens the model reports in
usage:prompt_tokensat the input price andcompletion_tokensat the output price. Prices are per 1M tokens. - Reasoning tokens are output tokens: they're included in
completion_tokens. - Every request that gets a response costs at least $0.00001.
- If you cancel a stream, you pay for everything the model generated until it finished, not only what reached you. To cap it, set
max_tokens. - Cached input is billed as regular input, for now.
Errors
Errors use OpenAI's format, so the SDKs read them as usual. Messages are always in English: they're meant for programs, and that way you can search for them.
{
"error": {
"message": "Insufficient credits. Top up at https://cheapllm.wtf/dashboard/credits",
"type": "insufficient_credits",
"code": "insufficient_credits"
}
}| HTTP | code | When |
|---|---|---|
| 400 | invalid_request | Invalid JSON, model or messages missing, or the model rejected a parameter |
| 401 | invalid_api_key | The key is missing, malformed, doesn't exist or was revoked |
| 402 | insufficient_credits | Your workspace is out of credits |
| 402 | no_active_plan | The key only uses a plan and your workspace has none |
| 403 | key_limit_exceeded | The key reached its spending limit |
| 403 | account_suspended | The workspace is suspended, for example after a chargeback |
| 403 | model_not_allowed_for_key | The key isn't allowed to use that model |
| 404 | model_not_found | The model doesn't exist or isn't available to you |
| 410 | model_retired | The model was retired |
| 413 | request_too_large | The body is larger than 4.5 MB |
| 429 | rate_limit_exceeded | You hit the workspace rate limit (see retry-after) |
| 429 | usage_limit_reached | You used up your plan limit and overflow is off (see retry-after) |
| 502 | upstream_error | The model failed with an error |
| 503 | no_upstream_available | The model is temporarily unavailable |
| 504 | upstream_timeout | The model took too long to start responding |
Every response from /v1/chat/completions, errors included, has an x-request-id header. If you need help with a request, send us that ID.
Rate limit
By default, each workspace can make 60 requests per minute, across all its keys. Go over it and you get a 429 with a retry-after header: the seconds to wait before trying again. The OpenAI SDKs already retry and respect it.
Compatible tools
Anything that lets you change the OpenAI base URL should work.
| Tool | Status |
|---|---|
| OpenAI SDK (Python, JS/TS) | Works. It's the reference client. |
LangChain (ChatOpenAI with base_url) | Works. |
| Vercel AI SDK (OpenAI-compatible provider) | Works. |
| Editors that accept an OpenAI base URL | Should work. We haven't tested them one by one yet. |
| Claude Code | Not yet: it needs /v1/messages, which comes later. |