Count tokens before you call.
Weigh a request before you send it. POST /v1/messages/count_tokens at https://api.uncensoredllm.ai/v1 takes the same body as an Anthropic-format Messages call and answers with its input-token count, computed on the gateway without reaching any model and without charging anything. Any API key on the organization may call it.
How the gateway counts
Roughly four characters make a token, a few tokens are added for each message, and every image in the body adds about 1,600. The method leans high on purpose, so a prompt that fits under a model’s context window by this count usually fits at call time; the model’s own tokenizer has the last word.
Request
| Field | Type | What it does |
|---|---|---|
messages | array, required | The conversation turns to count. |
model | string | The id the request names; it does not change the count, and a body without one answers 400. |
system | string or array | A system prompt counted with the messages. |
tools | array | Tool definitions, counted toward the input like any other text. |
Streaming, routing and preset fields are accepted because the body is a Messages body, and they change nothing here. The response is one field, input_tokens, an integer.
Example
curl https://api.uncensoredllm.ai/v1/messages/count_tokens \ -H "Authorization: Bearer sk-ullm-live-…" \ -H "Content-Type: application/json" \ -d '{"model": "glm-5.3-uncensored", "messages": [{"role": "user", "content": "Summarize this changelog."}]}'Status codes
| Status | Code | When |
|---|---|---|
| 200 | none | The count, as input_tokens. |
| 400 | invalid_request | No model, or messages is not a list. |
| 401 | invalid_api_key | No key, or one the organization does not recognize. |
| 413 | invalid_request | The body is too large to count; trim it or count it in parts. |
To cap what a key may spend once the real call goes out, set the limits described on the balance and spend limits page.
Count tokens: questions
Does counting tokens touch my balance?
No. The figure is computed on the gateway and nothing is forwarded to a model, so the call is free and no hold is placed on the balance.
How close is the estimate to what I will be billed?
It is deliberately high. Billing uses the count the model itself reports at call time, and this number usually sits a little above it. It is an estimate, not a guarantee, so leave headroom under a context window.
Does the model id change the count?
No. The estimate is a byte and structure approximation that is the same for every id you pass, abliterated or not; only the live call reflects a model’s own tokenizer.