Skip to main content
Measure the token cost of a request before sending it. Available on the Anthropic surface.

Endpoint

POST /v1/messages/count_tokens
Accepts the same body as /v1/messages (minus max_tokens). Returns:
{ "input_tokens": 42 }

Example

from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.abliteration.ai",
    auth_token=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

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.