Docs / Anthropic-compatible

Count tokens

POST/anthropic/v1/messages/count_tokens

Lightweight token estimate used by Claude Code for context management. No provider call and no exact Anthropic tokenizer—a heuristic (~4 chars/token) over system + message text + tool input/content.

Request & response

curl -sS "https://api.tokensaver.fr/anthropic/v1/messages/count_tokens" \
  -H "x-api-key: $TS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4-6",
    "messages": [{"role": "user", "content": "Hello world"}]
  }'

# => { "input_tokens": 3 }

The estimate is max(1, total_chars // 4). Treat it as guidance for context budgets, not billing.