How the estimate works
The counter splits your text into words, numbers, symbols and non-Latin characters and applies typical tokens-per-character ratios for each. English prose lands near four characters per token. Code, JSON and URLs cost more because they contain many symbols, and Chinese, Japanese, Cyrillic and Arabic text costs more per character too. The "likely range" shows a margin of error because no heuristic can match a real tokenizer exactly.
Get an exact Claude token count
Claude has its own tokenizer, so do not use OpenAI's tiktoken to count Claude tokens. Anthropic provides a free token-counting endpoint:
import anthropic
client = anthropic.Anthropic()
count = client.messages.count_tokens(
model="claude-sonnet-5-5",
messages=[{"role": "user", "content": "Your text here"}],
)
print(count.input_tokens)
It returns the input token count for exactly the request you would send, including system prompt and tools.
Why token counts matter
- Cost. You pay per million input and output tokens. Use the Claude API cost calculator to turn a token count into dollars.
- Context limits. Prompts, files, tool results and the model's answer all share one context window.
- Speed. Shorter prompts respond faster.
Tips to reduce tokens
- Remove boilerplate, repeated instructions and unused tool definitions.
- Send only the relevant part of a file instead of the whole file.
- Use prompt caching for large context that you send repeatedly.