Token Counter

Paste your prompt or drop a text file and this page counts its tokens on the spot. Counts for OpenAI's o200k_base and cl100k_base encodings are exact, because the real tokenizer runs here. Claude, Gemini and Llama figures are estimates from character length, since those vendors count tokens through their own APIs.

Which count you get for each model family
Model familyWhat this page showsExact count from
GPT-5, GPT-4.1, GPT-4o, o1, o3, o4-miniExact (o200k_base)This page
GPT-4, GPT-3.5 Turbo, text-embedding-3Exact (cl100k_base)This page
ClaudeEstimateMessages count_tokens endpoint
GeminiEstimatecountTokens in the Gemini API
Llama and other open modelsEstimateThe model's own tokenizer files

Updated

A token is the unit a language model reads and bills by: often a whole short word, sometimes a piece of a longer one, a space or a punctuation mark. OpenAI publishes its byte pair encodings, so this page loads the same data and splits your text exactly as their models do. Your text never leaves the tab.

Count tokens

Paste text or drop a file to see its token count. Everything is counted on this device; nothing is uploaded.

Encodings and the models that use them

Taken from the model-to-encoding table in OpenAI's open-source tiktoken library (MIT licence), checked October 19, 2026.

OpenAI encodings by model
EncodingModelsExact here
o200k_basegpt-5, gpt-4.5, gpt-4.1, gpt-4o, o1, o3, o4-miniYes
cl100k_basegpt-4, gpt-3.5-turbo, text-embedding-3-small and -large, text-embedding-ada-002Yes
Claude tokenizerAll current Claude models (not published)No, estimate
Gemini tokenizerGemini models (counted through the API)No, estimate

Counting tokens in your own code

Exact OpenAI count in JavaScript

The same MIT-licensed gpt-tokenizer package this page loads. Import the encoding you need.

import { encode } from "gpt-tokenizer/encoding/o200k_base";

const text = "How many tokens is this sentence?";
console.log(encode(text).length);

Exact OpenAI count in Python

tiktoken picks the encoding from the model name.

import tiktoken

enc = tiktoken.encoding_for_model("gpt-4o")
print(len(enc.encode("How many tokens is this sentence?")))

Exact Claude count through the API

Free to call within rate limits, but it needs your own API key, so run it from your machine.

curl https://api.anthropic.com/v1/messages/count_tokens \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model": "claude-opus-5-5",
       "messages": [{"role": "user", "content": "How many tokens is this sentence?"}]}'

Why token counts differ between models

Each vendor trains its own vocabulary. A larger vocabulary such as o200k_base, with about two hundred thousand entries, can cover common words and code fragments in one piece, so the same paragraph usually comes out shorter than under the older cl100k_base.

That means a count from one family is not a safe stand-in for another. Use the exact count where this page has the real tokenizer, and treat every other figure as a planning number.

Getting exact counts for Claude and Gemini

Anthropic's Messages API has a count_tokens endpoint that takes the same body as a normal request and returns input_tokens. Google's Gemini API offers count_tokens on its models as well, and each response also carries a usage block with the real figures.

Both need an API key, which a static page should never ask for, so this tool stops at the estimate and shows the request you can run yourself below.

How it works

  1. Paste text into the box, or drop a .txt or .md file onto it.
  2. Pick an encoding. o200k_base covers current OpenAI models; cl100k_base covers GPT-4 and GPT-3.5 Turbo.
  3. Read the exact token count next to the character and word counts, plus the estimates for other model families.
  4. Turn on the token view to see where each token starts and ends, shaded in alternating colours.

Tips

  • Numbers, code and non-English text usually cost more tokens per character than plain English prose.
  • Leading spaces belong to the next token in these encodings, so a word mid-sentence often counts differently from the same word at the start.
  • Budget for the reply too: output tokens count against the context window and are billed separately.
  • For a Claude or Gemini budget that must be exact, call that vendor's free counting endpoint before you send the real request.

Frequently asked questions

Which encoding do GPT-5 and GPT-4o use?

OpenAI's tiktoken library maps GPT-5, GPT-4.1, GPT-4o and the o1, o3 and o4-mini reasoning models to o200k_base. Older GPT-4 and GPT-3.5 Turbo models, plus the text-embedding-3 models, map to cl100k_base.

Why is the Claude number only an estimate?

Anthropic does not publish the tokenizer for its current models. Its token counting endpoint gives the real figure, is free to call within rate limits, and its docs say Claude Opus 4.7 and later produce roughly 30 percent more tokens than earlier models for the same text.

How is the estimate worked out?

Characters divided by four, rounded up. Google's Gemini docs give that ratio as a rule of thumb for its models. It is fair for English prose and drifts for code, numbers and other languages, which is why the page labels it as an estimate.

Does chat formatting add tokens?

Yes. Chat requests wrap each message in a few special tokens for roles and separators, and tools or images add more. This page counts the raw text only, so expect the billed input to be slightly higher.

Is my text sent anywhere?

No. The tokenizer data downloads once into the page and the counting runs on your device. Nothing you paste or drop is uploaded.

Related: AI API cost calculator, Prompt optimizer, AI prompt generator, What is a system prompt, PDF to Markdown.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Free Tools

Product

Who It's For

Features

Resources

Company

View Sitemap