Tiktokenizer

Anthropic Claude Sonnet 5 · Local estimate

Claude Sonnet 5 Token Counter

Estimate Claude Sonnet 5 text locally using Anthropic's documented English character rule with its newer-tokenizer adjustment. No API key is required; use count_tokens for model-aware input planning.

Accuracy note

Local character estimate using about 3.5 English characters per token with an approximate 30% newer-tokenizer adjustment. It produces no token IDs and excludes request overhead. Other languages, code and emoji can vary substantially; actual Messages usage remains the billing reference.

Official counting docs →
Model ID
claude-sonnet-5
Context
1,000,000 tokens
Max output
128,000 tokens
Local support
Local character estimate
Input estimate
Messages count_tokens; actual usage may differ

Facts checked against official sources on .

How to Count Claude Sonnet 5 Tokens

For a private estimate without an API key, paste text into the editor. The local rule uses Anthropic's approximate 3.5 English characters per token for earlier tokenizers, with about 30% added for the newer tokenizer. This is a planning heuristic and does not reconstruct token boundaries or IDs.

For a model-aware estimate, call Anthropic's Messages token counting endpoint with model claude-sonnet-5 and the same supported system prompt, messages, client tools, and base64 images or PDFs you plan to send. The response returns an estimated input_tokens value before message generation.

Anthropic describes this as a preflight estimate: actual input usage can differ slightly, and system-added optimization tokens in the estimate are not billed. Use it for prompt planning, then read the Messages response usage for the actual request. The local character estimate is separate from this model-aware endpoint and should not be used as an exact context or billing boundary.

pythonOfficial counting example
import anthropic

client = anthropic.Anthropic()
result = client.messages.count_tokens(
    model="claude-sonnet-5",
    system="You are a concise assistant.",
    messages=[{"role": "user", "content": "Count this prompt."}],
)
print(result.input_tokens)

Claude Sonnet 5 Uses a Newer Tokenizer

Anthropic states that Claude Sonnet 5 uses the newer tokenizer also used by Claude Opus 4.7 and later Opus models, Claude Fable 5, and related current models. The same text produces approximately 30 percent more tokens than on earlier Claude models, although the exact change depends on the content.

That does not mean Sonnet 5 is always more expensive or less efficient; it means token-based limits and prices must be evaluated with Sonnet 5 counts. Recount real prompts rather than copying a Sonnet 4.6 token total into a new budget.

What count_tokens Includes

Request componentSupported by preflight countCaveat
System and messagesYesUse the exact conversation structure
Client tools and advisor toolYesFor the advisor tool, only the executor's first sampling call is counted
Other server tools and MCP serversNoRead actual usage from the Messages response
Images and PDFsBase64 sourcesURL and file sources are not supported by count_tokens
Generated answerNoRead output usage after generation
System-added optimization tokensMay appearAnthropic says these are not billed to you

Claude Sonnet 5 Context Planning

Claude Sonnet 5 supports a one-million-token context window and up to 128,000 output tokens. Because the newer tokenizer represents the same source text with more tokens on average than Sonnet 4.6, the effective amount of text that fits in a fixed token budget can be lower.

Leave headroom for the answer and for request components that are easy to overlook, especially tool schemas, documents, and long multi-turn histories. Run count_tokens again whenever the model ID, system prompt, tool set, or document set changes.

Tiktokenizer Reference Sources

Tokenizer behavior and model limits change. Verify production decisions with current provider documentation:

Frequently asked questions

How do I count Claude Sonnet 5 tokens?

For a keyless local estimate, paste text into this page. For model-aware structured input, use Anthropic Messages count_tokens with model claude-sonnet-5; actual Messages usage can differ slightly.

Did Claude Sonnet 5 change tokenizers?

Yes. Anthropic says it uses a newer tokenizer that produces approximately 30 percent more tokens than earlier Claude models for the same text, depending on content.

Is the Claude token counting endpoint free?

Anthropic currently documents token counting as free and subject to separate rate limits.

Is the local Claude estimate exact?

No. It uses a documented English character heuristic with a newer-tokenizer adjustment, without real token boundaries or IDs. Other languages, code and emoji can vary substantially.