Claude Token Counter

Count tokens for Anthropic's Claude models — Opus 4.7, Sonnet 4.6, Haiku 4.5, Claude 3.5 Sonnet — with cost estimates against current API pricing. Anthropic doesn't ship a JavaScript tokenizer, so this uses a calibrated heuristic that matches the official /count_tokens endpoint within ~5% for English. Runs in your browser; text never leaves the page.

Advanced options

Paste text and click Count tokens.

How to use the Claude Token Counter

Paste any text, pick the Claude variant you'll be calling, and press Count tokens. The tool returns the token count, character count, and (with cost enabled) per-call, monthly, and annual cost projections based on Anthropic's current API list pricing.

For production workloads where exact billing matters, hit Anthropic's /v1/messages/count_tokens endpoint instead — same request shape as /messages, just returns the token count without running the model. That endpoint is free. For pre-flight sizing where you haven't built the API client yet (or you don't want to paste production data through an API call), this tool is the faster path.

What is Claude's tokenizer

Claude uses a SentencePiece-style Byte Pair Encoding tokenizer with a vocabulary in the range of ~150K tokens. Anthropic hasn't published the exact vocabulary or made it available as a public library (unlike OpenAI's tiktoken), so direct in-browser tokenization isn't possible without an API call.

Empirically, Claude's tokenizer behaves similarly to GPT-3.5's cl100k_base for English text — about 4 characters per token on average. It's slightly looser (more tokens) than o200k_base used by GPT-4o and GPT-5. For code, especially with single-character identifiers and dense punctuation, Claude is in the same ballpark as cl100k_base. For non-Latin scripts (Mandarin, Hindi, Arabic), Claude's tokenizer can produce 1.5-2x more tokens than o200k_base, which matters for multilingual cost analysis.

Pricing comparison across the Claude line

For 1,000 tokens of input + 1,000 tokens of output, the per-call cost works out to:

ModelInput ($/M)Output ($/M)Cached ($/M)Per-call (1K + 1K)
Claude Opus 4.7$15.00$75.00$1.50$0.090
Claude Sonnet 4.6$3.00$15.00$0.30$0.018
Claude Haiku 4.5$1.00$5.00$0.10$0.006
Claude 3.5 Sonnet (legacy)$3.00$15.00$0.30$0.018

Opus is 5x the cost of Sonnet for similar quality on most tasks; reserve it for the genuinely hard problems. Haiku is 3x cheaper than Sonnet and noticeably faster — a good default for high-volume classification, routing, and shorter generation. Cached pricing applies only to input tokens that match a previously-cached prefix; it does not discount output.

Common use cases

  • System prompt sizing. Pasting a Sonnet system prompt to see whether it fits in the cacheable prefix (the 1024-token minimum for Sonnet means short prompts don't benefit from prompt caching at all).
  • RAG chunk planning. Counting your average retrieved chunk to size a top-k retrieval that fits the model's context without wasting it.
  • Comparing Claude to GPT. Same text into both this tool and the OpenAI Token Counter to see where the per-token-cost difference goes once tokenization is accounted for.
  • Pre-flight budget for a migration. If you're moving a workload from GPT-4o to Claude Sonnet, the token-count delta plus the per-token price delta gives you the real monthly cost change.
  • Long-context cost estimation. Claude's 200K context isn't tiered like Gemini's, but per-call pricing scales linearly. A 150K-token input on Sonnet 4.6 costs $0.45 per call before output. Knowing the count up front avoids surprises.

Frequently asked questions

Why is this an estimate and not the exact Anthropic count?

Anthropic does not ship an official JavaScript tokenizer. The exact count is only available via the /v1/messages/count_tokens endpoint, which requires an API call. This tool uses a calibrated heuristic that matches Anthropic's API count within about 5% for English text and within 10% for code. For exact production billing, use the API endpoint.

How do Claude tokens differ from OpenAI tokens for the same text?

Claude's tokenizer (a SentencePiece-style BPE) typically produces 5-15% more tokens than GPT-4o (o200k_base) for the same English text, and roughly the same as GPT-3.5's cl100k_base. For code and non-English text the difference is larger. Use the Multi-Model Token Comparison tool to see the side-by-side.

Does Claude charge for system prompts and tool definitions the same way?

Yes — every input token is billed at the same rate per model, whether it's in a system prompt, user message, tool definition, or assistant prefix. The big exception is prompt caching: cached input tokens cost 10% of normal input price (90% discount). The cache has minimum content length requirements (~1024 tokens for Sonnet/Haiku, ~2048 for Opus) and a 5-minute idle TTL.

What's the cheapest Claude option?

Claude Haiku 4.5 at $1.00/M input, $5.00/M output. With aggressive prompt caching the effective input rate drops to $0.10/M, which makes Haiku competitive with GPT-5 Mini for many high-volume workloads. For most production use the default is Sonnet 4.6 at $3/$15; Opus is reserved for the hardest tasks.

Does Claude support a 200K context for every model?

Yes — Opus 4.7, Sonnet 4.6, Haiku 4.5, and the Claude 3 line all ship with a 200,000-token input window. Output limits vary: 64K for Opus and Sonnet 4.x, 16K for Haiku 4.5, 8K for older Sonnet 3.5. Long-context billing is uniform — Anthropic doesn't charge a step-up at 128K the way Gemini does.

Can I use this for cost estimation?

Yes. Enable "Show cost" in the options, enter monthly call volume, and the tool multiplies tokens by Anthropic's current per-million-token pricing. The cached-input cost mode applies the 90% discount; use it when most of your input is a stable system prompt that gets cache hits.