Skip to content

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/v1

Send your API key as a bearer token in the Authorization header:

Authorization: Bearer wtf_...
Call it from your server
The API doesn't accept calls from the browser: there's no CORS. A key in your frontend is a leaked key.

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/models

How 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_tokens at the input price and completion_tokens at 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"
  }
}
HTTPcodeWhen
400invalid_requestInvalid JSON, model or messages missing, or the model rejected a parameter
401invalid_api_keyThe key is missing, malformed, doesn't exist or was revoked
402insufficient_creditsYour workspace is out of credits
402no_active_planThe key only uses a plan and your workspace has none
403key_limit_exceededThe key reached its spending limit
403account_suspendedThe workspace is suspended, for example after a chargeback
403model_not_allowed_for_keyThe key isn't allowed to use that model
404model_not_foundThe model doesn't exist or isn't available to you
410model_retiredThe model was retired
413request_too_largeThe body is larger than 4.5 MB
429rate_limit_exceededYou hit the workspace rate limit (see retry-after)
429usage_limit_reachedYou used up your plan limit and overflow is off (see retry-after)
502upstream_errorThe model failed with an error
503no_upstream_availableThe model is temporarily unavailable
504upstream_timeoutThe 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.

ToolStatus
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 URLShould work. We haven't tested them one by one yet.
Claude CodeNot yet: it needs /v1/messages, which comes later.