Claude prompts · Official API counting guide

Claude Token Counter

Compare prompt text locally, then count Claude messages with the official API. The browser result is a reference encoding, not Claude's tokenizer.

Accuracy note

The local explorer does not load Claude's tokenizer. Use Anthropic Messages count_tokens with your target model and structured inputs for a model-aware estimate; final request usage can differ slightly.

Official counting docs →

How the Claude token counter works

Use the editor to inspect the text you plan to send: paste a draft, compare wording and look for repeated instructions or oversized examples. The live panel shows boundaries and IDs from the selected reference encoding. Switching that encoding changes the local comparison; it does not turn the panel into Claude's proprietary tokenizer.

For Claude input planning, run the official Messages count_tokens operation with the model ID and message structure you intend to use. Keep the system prompt, conversation history and supported tool definitions in the request. The returned input_tokens value is the provider's preflight estimate, which can differ slightly from actual message usage.

pythonCount a Claude message with the official API
# pip install anthropic
# Set ANTHROPIC_API_KEY in your environment.
from pathlib import Path
import anthropic

prompt = Path("prompt.txt").read_text(encoding="utf-8")
client = anthropic.Anthropic()
count = client.messages.count_tokens(
    model="claude-opus-5",
    messages=[{"role": "user", "content": prompt}],
)
print("Claude input tokens:", count.input_tokens)

Claude token calculator vs word counter

A word counter cannot account for model vocabulary, punctuation, code or message formatting. A short JSON payload can contain few ordinary words but many distinct token pieces. A translation can also change token length while preserving the meaning. Measure the actual prompt instead of applying one word-to-token multiplier to every language.

Use this Claude token calculator as a two-step workflow: inspect the draft locally, then check the structured request with Claude's API. Record the model ID next to that result. After editing the system instructions, adding tools or changing the conversation history, recount the complete input so the number still describes the request you will send.

Claude token count by model

Pass the exact active model ID to the counting endpoint. This site's Claude model guides document the API-based workflow; the browser comparison on those pages is not a substitute for a Claude count. Keep the model selection consistent when comparing two prompt drafts.

Input counting does not predict how much text or reasoning a future response will produce. Reserve an output allowance separately, and inspect the completed response's usage when measuring what actually happened. For requests that the counting endpoint does not support, follow the provider's current guidance and the usage reported by the Messages API.

Claude guideTokenizer accessCounting method
Claude Sonnet 5Provider-managedMessages count_tokens with the target model ID
Claude Fable 5Provider-managedMessages count_tokens with the target model ID

Tiktokenizer Reference Sources

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

Frequently asked questions

Is this Claude token counter exact?

The browser panel is a reference encoding, not Claude's tokenizer. For a Claude-specific input estimate, use the official counting endpoint with your model and complete supported message structure.

Is the Claude token calculator free?

The local reference tool is free without signup. Anthropic documents its token-counting endpoint as free with rate limits; it requires an API account and key.

Does pasting here send my prompt to Anthropic?

No. The browser explorer analyzes text locally. Running the separate Python example sends prompt.txt to Anthropic using your own API credentials.

Why are the local token IDs different from Claude's?

Token IDs belong to the selected vocabulary. The reference encoding in this browser is not a published Claude vocabulary, so its IDs should not be used as Claude IDs.

Can a word count predict Claude input tokens?

It cannot provide a reliable exact count. Text, language and request structure matter; measure the intended input with the model-aware method.

Can I inspect this guide without JavaScript?

Yes. The counting instructions, model links, Python example and FAQs are included in the initial HTML. The live reference explorer requires JavaScript.