---
title: "Count tokens: a free input-token estimate before you call"
canonical: https://uncensoredllm.ai/docs/count-tokens
generated: 2026-11-23T06:12:14.499Z
source: https://uncensoredllm.ai/docs/count-tokens
base_url: https://api.uncensoredllm.ai/v1
---

# 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](https://app.uncensoredllm.ai/console)

## 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

```bash
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](https://uncensoredllm.ai/docs/budgets) 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

- [MCP servers](https://uncensoredllm.ai/docs/mcp-servers)
- [Log export](https://uncensoredllm.ai/docs/exports)
- [Invoices](https://uncensoredllm.ai/docs/invoices)
- [Billing details](https://uncensoredllm.ai/docs/billing-details)
- [Statement signing key](https://uncensoredllm.ai/docs/statements-public-key)
- [Keys](https://uncensoredllm.ai/docs/keys)
- [Requests and receipts](https://uncensoredllm.ai/docs/requests)
- [Balance and spend limits](https://uncensoredllm.ai/docs/budgets)
- [Batches](https://uncensoredllm.ai/docs/batches)
- [Files](https://uncensoredllm.ai/docs/files)
- [App usage stats](https://uncensoredllm.ai/docs/stats-apps)
- [Auth keys](https://uncensoredllm.ai/docs/auth-keys)
- [Webhook deliveries](https://uncensoredllm.ai/docs/webhooks-deliveries)
- [Docs: connect in two minutes](https://uncensoredllm.ai/docs)
