Count tokens before you call.

Updated November 22, 2026.

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.

Get a key

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

FieldTypeWhat it does
messagesarray, requiredThe conversation turns to count.
modelstringThe id the request names; it does not change the count, and a body without one answers 400.
systemstring or arrayA system prompt counted with the messages.
toolsarrayTool 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

shell
1curl https://api.uncensoredllm.ai/v1/messages/count_tokens \
2 -H "Authorization: Bearer sk-ullm-live-…" \
3 -H "Content-Type: application/json" \
4 -d '{"model": "glm-5.3-uncensored", "messages": [{"role": "user", "content": "Summarize this changelog."}]}'

Status codes

StatusCodeWhen
200noneThe count, as input_tokens.
400invalid_requestNo model, or messages is not a list.
401invalid_api_keyNo key, or one the organization does not recognize.
413invalid_requestThe 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.

Read next

Join on TelegramHelp