> ## Documentation Index
> Fetch the complete documentation index at: https://docs.otamd.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Count input tokens

> Estimate a Messages payload before generating an answer.

`POST /v1/messages/count_tokens` accepts `model` and `messages`, plus Messages input fields such as `system`, `tools`, `thinking`, and image blocks. It returns `input_tokens` without generating a completion.

```python theme={null}
import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ["LIMITLESS_API_KEY"],
    base_url=os.environ["LIMITLESS_API_ORIGIN"],
    max_retries=0,
)

count = client.messages.count_tokens(
    model="glm-5.3-unrestricted",
    system="Keep answers concise.",
    messages=[{"role": "user", "content": "Describe a solar eclipse."}],
)
print(count.input_tokens)
```

Use the API origin without `/v1` for the Anthropic SDK. This operation requires the customer key's `inference:write` permission. It does not stream, create an inference usage event, or settle a token charge. It still consumes the workspace’s request-rate allowance and requires an actively priced model.

The result comes from the active backend. Its counting implementation can use an estimator when its native tokenizer is unavailable, so treat the count as a planning aid rather than a guaranteed bill. Generated output and subsequent tool rounds are not included.

A count request does not generate a charge or reserve credits for a later inference request. Generation checks for a positive available balance, model availability and spending limits, then charges actual usage after completion. See [billing](https://docs.otamd.com/billing.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.