Skip to main content

AI Token Counter

Count tokens for GPT-4o, Claude, and Gemini models instantly.

Reviewed by · Last reviewed

Runs 100% in your browser - your data never leaves your device

Rate this tool
Be the first to rate

How to Use the AI Token Counter

  1. Paste or type your text into the input area.
  2. Click Count Tokens.
  3. Read the per-model breakdown in the results table below.

What It Does

The AI Token Counter runs entirely in your browser. GPT-4o token counts use the cl100k_base BPE encoder via the gpt-tokenizer library loaded on demand - no data is sent to any server. Claude and Gemini estimates use a character-based formula (chars divided by 3.5) that is accurate to within roughly 10% for English text. Use this tool to check prompt length before hitting API limits or to estimate API costs.

When Token Counts Matter

  • Context window budgeting. Before stuffing a long document into a prompt, check that it fits the model's context limit with room left for the system prompt and the response.
  • Cost estimation. API pricing is per million tokens. Multiply the count by your model's input rate to predict what a batch job will cost before running it.
  • Chunking for RAG. When splitting documents for embeddings, you usually target a fixed token size per chunk. Paste a sample chunk to verify your splitter is producing the size you think it is.
  • Truncation debugging. If completions cut off mid-sentence, the prompt plus response likely hit the limit. Counting the prompt tells you how much budget the response actually had.

Things to Keep in Mind

Token counts are not word counts: common English averages roughly 0.75 words per token, but code, JSON, non-Latin scripts, and long compound words tokenize less efficiently. Whitespace and punctuation cost tokens too, which is why minified JSON counts fewer tokens than pretty-printed JSON with identical content. Chat-format requests also add a small per-message overhead (a few tokens per message) that a raw text count does not include, so treat API-side counts as the final authority when you are right at a limit.

Frequently Asked Questions

How are tokens counted for GPT-4o?

GPT-4o uses the cl100k_base BPE encoding. This tool runs the same encoder client-side via gpt-tokenizer, so the count matches what OpenAI's API reports.

Why are Claude and Gemini counts approximate?

Anthropic and Google do not publish client-side tokenizer packages. The tool uses a character-based estimate (chars / 3.5 for English) which is within roughly 10% for typical prose. For precise counts use the provider's API.

Is my text sent to any server?

No. All tokenization runs in the browser tab. There is no fetch call.

Related tools

More Developer Tools

Support ZeroUtil