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

# Count input tokens before sending

> Measure the exact input-token cost of a request before sending it, via POST /v1/messages/count_tokens.

Measure the token cost of a request before sending it. Available on the Anthropic surface.

## Endpoint

```http theme={"system"}
POST /v1/messages/count_tokens
```

Accepts the same body as `/v1/messages` (minus `max_tokens`). Returns:

```json theme={"system"}
{ "input_tokens": 42 }
```

## Example

```python theme={"system"}
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.abliteration.ai",
    api_key=os.environ["ABLIT_KEY"],
)

resp = client.messages.count_tokens(
    model="abliterated-model",
    messages=[{"role": "user", "content": "How many tokens is this?"}],
)
print(resp.input_tokens)
```

## curl

```sh theme={"system"}
curl https://api.abliteration.ai/v1/messages/count_tokens \
  -H "x-api-key: $ABLIT_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "abliterated-model",
    "messages": [{"role": "user", "content": "Count me"}]
  }'
```

## Notes

* The count reflects **your payload only** — internal system instructions we add for tool routing are excluded. What you see is what you'd be billed for.
* Tools, system prompts, and image blocks are all included in the count.
* If the upstream count path is unavailable, the API falls back to a local estimator. Counts should still be within a few tokens of the real figure.
