How to Count Tokens for ChatGPT, Claude and Gemini (Cost Guide)

How to Count Tokens for ChatGPT, Claude and Gemini (Cost Guide)

By Talk & Tool5 min read

A token is the unit a language model reads and bills by. It is usually a word, part of a word, or a punctuation mark. To count tokens, run your text through the model's tokenizer. For a quick estimate, English text with modern OpenAI tokenizers comes to roughly one token per word. Here is how counting works for GPT, Claude and Gemini models, and how to turn a count into a cost.

What a token actually is

Models do not see letters or words. A tokenizer splits text into pieces from a fixed vocabulary, and each piece becomes a number. Common words are usually a single token. Rarer words are split into several parts:

  • "Hello, world!" → Hello , world ! = 4 tokens
  • "Tokenization is surprisingly unintuitive." → Token ization is surprisingly unint uitive . = 7 tokens

Those counts come from OpenAI's o200k_base encoding, used by GPT-4o and GPT-4.1. Note that the leading space is part of the token: " world" and "world" are different tokens.

Rules of thumb (and their limits)

The classic estimate is about 4 characters or 0.75 words per token for English. That came from older tokenizers. Newer vocabularies are more efficient: in our test, a 53-word English paragraph was 57 tokens with o200k_base, about 1.1 tokens per word or 5.2 characters per token.

Counts rise sharply for:

  • Code: brackets, operators and indentation often become separate tokens. function add(a, b) { return a + b; } is 13 tokens for 8 "words".
  • Non-English text: languages that are less represented in the vocabulary, and scripts like Chinese, Arabic or Hindi, can take several times more tokens for the same meaning.
  • Numbers, IDs and URLs: long digit strings and random identifiers split into many small pieces.
  • Whitespace and formatting: JSON, tables and repeated spaces all add tokens.

Why different models count differently

Every model family has its own tokenizer, so the same text gives different counts:

  • OpenAI: GPT-4o and GPT-4.1 use o200k_base, which is public, so counts for those models can be exact. OpenAI has not published tokenizers for every newer model, so counts made with o200k_base are estimates for them.
  • Anthropic (Claude): Anthropic says Claude 4.7 and later models use a newer tokenizer that produces roughly 30% more tokens for the same text than earlier Claude models. Its API has a token-counting endpoint for exact figures.
  • Google (Gemini): Gemini's API has a countTokens method. Its tokenizer is not available to run in a browser, so browser tools estimate.

The LLM token counter counts in your browser with o200k_base. Results are marked exact where that is the model's own tokenizer and "≈" where it is an estimate. There are model pages for Claude Sonnet 5, Claude Opus 5.5, GPT-4o and Gemini 2.5 Pro, among others.

From tokens to cost

API prices are quoted per million tokens, with separate rates for input (your prompt) and output (the model's reply). Output is usually priced several times higher.

Cost = (input tokens ÷ 1,000,000 × input price) + (output tokens ÷ 1,000,000 × output price)

Example: a support chatbot handles 100,000 requests a month, each with a 2,000-token prompt (system instructions, conversation history, retrieved documents) and a 500-token reply. That is 200 million input tokens and 50 million output tokens. On Claude Sonnet 5 at $2 input and $10 output per million: 200 × $2 + 50 × $10 = $900 a month.

Bar chart comparing the monthly API cost of one chatbot workload across Claude, GPT and Gemini models, from 450 to 1,800 dollars
Assumes identical token counts. In practice each tokenizer counts the same text differently, which shifts these totals.

Prices change often, and several models have promotional or tiered pricing. The LLM price comparison lists current rates with the date they were last verified. Plug your own volumes into the LLM API cost calculator.

How to cut token costs

  • Prompt caching: if the start of your prompt (system instructions, reference documents) is the same across requests, cached input is billed at a fraction of the normal rate, often 90% less for cache reads. In the example above, caching 1,500 of the 2,000 input tokens on Sonnet 5 would cut input cost from $400 to about $130 before any cache-write charges.
  • Trim conversation history: re-sending the whole chat every turn makes input grow quickly. Summarise older turns or keep only the last few.
  • Cap output length: set a sensible maximum and ask for concise answers. Output tokens are the expensive ones.
  • Route by difficulty: send simple classification or extraction to a small model, and reserve large models for hard reasoning.
  • Retrieve less, better: five relevant passages beat twenty loosely related ones, on cost and usually on answer quality.

Context windows are tokens too

A model's context window is the maximum number of tokens for input and output combined in one request. Many current models accept around a million tokens, and some smaller ones 128,000–400,000. Hitting the limit truncates or rejects the request, so count long documents before sending them.

Frequently asked questions

How many tokens is 1,000 words?

For English with modern OpenAI tokenizers, roughly 1,100–1,400 tokens depending on vocabulary and formatting. Code and non-English text can take far more.

Do spaces and punctuation count as tokens?

Yes. Punctuation is often its own token, and spaces are usually attached to the following word. Extra whitespace and formatting add tokens.

Are input and output tokens priced the same?

Almost never. Output is typically 4–8 times more expensive per token than input, so long replies drive cost more than long prompts.