Home/Writing/How to Count Claude Tokens: Counting API, Rules of Thumb, Cost

Writing

How to Count Claude Tokens: Counting API, Rules of Thumb, Cost

Count Claude tokens exactly with Anthropic's free counting endpoint, estimate them from word counts, and turn the result into dollars for each Claude model.

Short answer

For an exact count, send your request to Anthropic's token counting endpoint (client.messages.count_tokens in Python). It is free and supports system prompts, tools, images and PDFs. For a rough count, Anthropic documents 1M tokens as about 555,000 words on the tokenizer used by Claude Opus 4.7 and later, which puts 200K tokens at roughly 111,000 words. Older models fit about 150,000 words into 200K tokens. To convert tokens to money, multiply by the model's per-million rate: 200K input tokens cost $0.40 on Claude Sonnet 5.5.

Use this guide forNext action
Understanding the cost decisionClaude Token Calculator →

Every Claude cost estimate starts with a token count. Get the count wrong and every calculation after it inherits the error. There are two ways to get it: ask Anthropic's API, or estimate from word counts. This guide covers both, explains why the newest Claude models count the same text differently, and shows how to turn a count into a dollar figure.

Count exactly with the token counting API

Anthropic's token counting endpoint takes the same request body as the Messages API: model, system prompt, messages and tools. It returns the number of input tokens that request would use. It also handles images and PDFs, as long as they are sent as base64 rather than by URL or file ID.

In Python it is one call on the official SDK:

import anthropic

client = anthropic.Anthropic()

count = client.messages.count_tokens(
    model="claude-sonnet-5-5",
    system="You are a support assistant for an invoicing app.",
    messages=[{"role": "user", "content": "Why was I charged twice this month?"}],
)
print(count.input_tokens)

The TypeScript SDK exposes the same endpoint as client.messages.countTokens, and the raw HTTP route is POST /v1/messages/count_tokens.

Points from Anthropic's documentation that matter for cost work:

  • It is free. Token counting has no charge. It has its own requests-per-minute limits by usage tier, separate from your message-creation limits.
  • It is an estimate. Anthropic says the count can differ by a small amount from the real request. It may include tokens Anthropic adds for system optimizations, and you are not billed for those.
  • It counts under the model you name. Pass the model ID you will actually call. The same prompt counts differently on Claude Sonnet 4.6 and Claude Sonnet 5.5, as explained below.
  • Some inputs are rejected. Requests that use server tools such as web search or code execution, or the MCP connector, return an error. For those, read the usage object on the real response.
  • It ignores caching. Prompt caching only happens during real message creation, so the count tells you the size of a prompt, not what share of it will be a cache hit.

If you are building an application, call the endpoint on representative requests during development, store the counts, and use them as your per-request input estimate.

Rules of thumb when you cannot call the API

Sometimes you only have a word count: a spec, a document size, a guess about average chat length. Anthropic's models overview gives the conversion ratios:

  • Claude Opus 4.7 and later (including Claude Fable 5.1, Opus 5.5, Sonnet 5.5 and Haiku 5.5): 1M tokens is roughly 555,000 words or 2.5 million Unicode characters. That works out to about 1.8 tokens per English word, or about 2.5 characters per token.
  • Earlier models (Claude Sonnet 4.6, Haiku 4.5 and older): 1M tokens holds about 750,000 words, or roughly 1.33 tokens per word.

Treat these as English-prose averages. Source code, JSON, tables and non-English text usually tokenize less efficiently, so measure a sample before you rely on a ratio for those inputs.

How much is 200K tokens in Claude?

Anthropic's own shorthand is that 200K tokens is roughly 150,000 words. That matches the older ratio. On the newer tokenizer, the same 1M-to-555,000-words figure scales to roughly 111,000 words for 200K tokens. Plan with the lower figure for any current model.

In money terms, 200K input tokens cost:

  • $2.00 on Claude Fable 5.1
  • $0.80 on Claude Opus 5.5
  • $0.40 on Claude Sonnet 5.5
  • $0.20 on Claude Haiku 4.5

Those are uncached base rates. Claude 4.6 and later models bill the full 1M-token context window at standard per-token prices, with one exception: Claude Haiku 5.5 is priced by prompt length. A request whose prompt is over 100,000 tokens pays five times Haiku 5.5's base rates. A single 200K-token prompt therefore never gets Haiku 5.5's headline price, even though many smaller requests adding up to 200K tokens do.

Why the same text costs more tokens on newer Claude models

Anthropic's pricing page states that Claude 4.7 and later models use a newer tokenizer that produces approximately 30% more tokens for the same text. The exact increase depends on the content and workload shape. Claude Sonnet 4.6 and earlier models keep the previous tokenizer.

This matters most when you migrate. Suppose a prompt measured 10,000 tokens on Claude Sonnet 4.6. On Sonnet 4.6 it costs $0.03 in input. On Claude Sonnet 5.5 the same text is roughly 13,000 tokens. At Sonnet 5.5 rates that comes to about $0.026. Put the two figures side by side: any comparison of per-million rates is off by the token increase, because the newer rate applies to a larger count.

The fix is the one Anthropic recommends in its token counting guide: count the same request twice, once with your current model ID and once with the model you are moving to, and compare the two input_tokens values. Never reuse token budgets, context-window checks or cost estimates measured on a pre-4.7 model.

For how this compares with OpenAI and Google, see why GPT, Claude, and Gemini count tokens differently.

Converting Claude tokens to money

Once you have counts, the arithmetic is simple. Claude bills input and output tokens at separate per-million rates:

cost = input tokens ÷ 1,000,000 × input rate + output tokens ÷ 1,000,000 × output rate

The current rates in our pricing store, each verified against Anthropic's pricing page, and the cost of a 20,000-input, 2,000-output request on each model:

  • Claude Fable 5.1: $10.00 input / $50.00 output per 1M tokens. 20,000 input + 2,000 output tokens cost $0.30.
  • Claude Opus 5.5: $4.00 input / $20.00 output per 1M tokens. 20,000 input + 2,000 output tokens cost $0.12.
  • Claude Sonnet 5.5: $2.00 input / $10.00 output per 1M tokens. 20,000 input + 2,000 output tokens cost $0.06.
  • Claude Haiku 5.5: $0.10 input / $0.50 output per 1M tokens. 20,000 input + 2,000 output tokens cost $0.003.
  • Claude Opus 4.7: $5.00 input / $25.00 output per 1M tokens. 20,000 input + 2,000 output tokens cost $0.15.
  • Claude Sonnet 4.6: $3.00 input / $15.00 output per 1M tokens. 20,000 input + 2,000 output tokens cost $0.09.
  • Claude Haiku 4.5: $1.00 input / $5.00 output per 1M tokens. 20,000 input + 2,000 output tokens cost $0.03.

Scaling up works the same way. A support assistant that sends 3,000 input tokens and gets 400 output tokens back, 100,000 times a month, uses 300M input and 40M output tokens. On Claude Sonnet 5.5 that comes to $1,000.00 a month at base rates. On Claude Haiku 5.5, where every request stays under the 100K threshold, it is $50.00.

Three adjustments move a real bill away from this baseline:

  • Prompt caching. Repeated prefixes, such as a long system prompt or a reference document, are billed at a fraction of the base input rate on cache hits. Anthropic's pricing page lists the multiplier per model.
  • Batch processing. The Batch API halves input and output prices for work that can wait.
  • Thinking. Thinking tokens are billed as output. A model that reasons at length uses more output tokens than the visible answer suggests.

The Claude Token Calculator applies the same store rates. Enter your measured input and output counts and switch between models to compare the same workload.

A practical counting workflow

  1. Collect 20–50 real requests that represent your traffic, including the full system prompt, tools and history.
  2. Run each through count_tokens with the model ID you plan to use, and record the average and the 90th percentile.
  3. Estimate output from real responses, not from the max_tokens cap, and include thinking.
  4. Put the averages into the calculator, then add headroom for longer conversations and retries.
  5. Recount whenever you change models. That step is mandatory when you cross the Claude 4.7 tokenizer boundary.

Prices in this article come from the AICostLabs pricing store, last verified against Anthropic's pricing page on October 13, 2026. Estimates only; verify provider pricing before you commit a budget.

Claude Token CalculatorApply this guide to your own workload.Open calculator →

Common questions

Is there an official Claude tokenizer for Python?

Anthropic documents the token counting endpoint, which the Python SDK exposes as client.messages.count_tokens. You pass the same model, system prompt, messages and tools you would send to the Messages API, and it returns input_tokens for that model's tokenizer. Counting is free but rate-limited by usage tier.

How many words is 200K tokens in Claude?

On the tokenizer introduced with Claude Opus 4.7, Anthropic puts 1M tokens at roughly 555,000 words, so 200K tokens is about 111,000 English words. On Claude Sonnet 4.6, Haiku 4.5 and other earlier models, Anthropic's figure is about 150,000 words. Code and non-English text change the ratio, so count real samples.

Why does the same prompt cost more tokens on newer Claude models?

Claude 4.7 and later models use a newer tokenizer that Anthropic says produces approximately 30% more tokens for the same text. The exact increase depends on the content. Recount prompts against the model you plan to use instead of reusing counts from an older model.

Does the count_tokens endpoint cost money or count against my rate limits?

No charge. Anthropic lists token counting as free to use, with its own requests-per-minute limits by usage tier. Those limits are separate from message creation, so counting does not consume your Messages API rate limit.

Is the token count exact enough for billing?

Anthropic calls the result an estimate that can differ by a small amount from the tokens actually used. It may also include tokens Anthropic adds for system optimizations, which are not billed. It is accurate enough for budgeting and context-window checks; your invoice reflects the usage object returned with each real response.