Tools

OpenAI token counter

Count the tokens in a prompt exactly as OpenAI's tokenizer does, and see where each token starts and ends.

Runs in your browserAI developer tools843
Free

Input

0 B

Result

The result will appear here.

Context limits, rate limits and the bill are all measured in tokens, not characters, and the ratio between the two changes a lot with the language: English runs at about four characters per token, while Chinese is often close to one. This tool counts the tokens in any text with the same byte-pair encoding tables OpenAI's models use — o200k_base for GPT-4o, GPT-4.1, GPT-5 and the o-series, cl100k_base for GPT-4, GPT-3.5 and the text-embedding-3 models. It runs on gpt-tokenizer (niieani/gpt-tokenizer, MIT), a pure-JavaScript port of openai/tiktoken whose output matches tiktoken token for token; our tests compare it with tiktoken itself on English, Chinese, mixed text and code.

How it works

  • Only the encoding you choose is downloaded, as its own chunk of a few megabytes; after that, counting happens in your browser and the text is never sent anywhere.
  • The token-boundary view separates tokens with │ and shows line breaks as ↵ and tabs as →. A Chinese character or emoji that the encoding splits into several byte tokens is shown once, with a small superscript saying how many tokens it took.
  • Strings such as <|endoftext|> are counted as ordinary text rather than rejected, which is how the API treats them when they appear inside a message.
  • The token-ID view lists the numeric IDs the model actually receives; both views show the first 20,000 tokens, and the count always covers the whole text.

Where your data goes

Nowhere. This tool runs entirely in your browser: the text you paste is processed by the page and is never transmitted to a server or written to a log.

This tool is free and needs no account. Its results exist only in your open page and are not saved anywhere.

What it costs

This tool is free, with no sign-in and no points.

Common questions

Is the count exact for Claude, Gemini, Llama or DeepSeek?
No. Every vendor trains its own tokenizer, so the same text comes out as a different number of tokens on each. The o200k_base count is a reasonable estimate for other modern models on English text, typically within 10–20%, but it can be further off for Chinese or code. For an exact figure use the vendor's own counting endpoint, such as Anthropic's count_tokens or Gemini's countTokens.
Which encoding should I choose?
o200k_base for anything current from OpenAI: GPT-4o, GPT-4.1, GPT-5 and the o1/o3/o4 reasoning models. cl100k_base for GPT-4, GPT-4 Turbo, GPT-3.5 Turbo and the text-embedding-3 and ada-002 embedding models. o200k_base has twice the vocabulary, so the same non-English text usually needs noticeably fewer tokens with it.
Why does a chat request use more tokens than this shows?
Because the API wraps each message in a few formatting tokens of its own — about three per message plus three to prime the reply — and function or tool definitions are counted as well. This tool counts the text you paste, which is what you need when trimming a prompt; for a full request, add those few tokens per message.
Why does one Chinese character sometimes count as two or three tokens?
Byte-pair encodings work on UTF-8 bytes, and a Chinese character is three bytes. Common characters and words have tokens of their own, but a rarer character is split into byte pieces, and each piece is a token. The superscript in the boundary view, such as ⁽²⁾, marks exactly those characters.

The open-source behind it

This tool runs on niieani/gpt-tokenizer, released under MIT. If you need the same behaviour inside your own program, that is the library to reach for.

niieani/gpt-tokenizer

Also known as

  • token counter
  • openai tokenizer
  • gpt token counter
  • tiktoken online
  • o200k_base
  • cl100k_base
  • count tokens