Devbelt

AI Token Counter

Count OpenAI tokens and see context window usage, locally

0 of 128,000 tokens used0.0%
0tokens
TEXT

Everything runs in your browser. Your text is never uploaded or stored on a server.

About

"How many tokens is this?" comes up constantly once you're building anything on top of an LLM API, and eyeballing it from word count is close to useless, since tokens don't line up with words or characters in any fixed way. This tool runs tiktoken, the same tokenizer library OpenAI's own models use, directly in your browser, so you get an exact count for GPT-4o, GPT-4o mini, o3-mini, or GPT-3.5 Turbo, plus a bar showing how much of that model's context window your text would use. Nothing you paste is ever sent anywhere to get that number.

What a token actually is

A token is the unit an LLM actually reads and writes in, and it isn't a word or a character, it's a chunk somewhere in between. "Hello" is one token. "Tokenization" might be two or three. A single emoji can be several. This is why a rough "count the words and multiply" estimate drifts further off the more unusual, technical, or non-English your text is: code, JSON, and rare words all tend to break into more tokens per character than plain conversational English does.

It matters because everything that costs you against a model, the context window, the output limit, is measured in tokens, not characters. A prompt that looks short on screen can still be token-heavy, and a prompt that looks long can be token-cheap, depending on what's actually in it.

How OpenAI's BPE tokenizers work

OpenAI's models use byte pair encoding (BPE): start with individual bytes, then repeatedly merge the most frequently occurring adjacent pair into a new token, using a fixed table of merges learned ahead of time from a huge amount of text. Common sequences like "ing" or "the" end up as single tokens because they occurred constantly during that training; rare sequences stay split into smaller pieces, sometimes down to individual bytes for something truly unusual.

Different OpenAI models use different merge tables, called encodings. GPT-4o, GPT-4o mini, and o3-mini all use o200k_base, a newer encoding with a larger vocabulary. GPT-3.5 Turbo uses the older cl100k_base. That's why switching the model dropdown on this page can change the count for the exact same text: you're not just changing a limit, you're changing which merge table is splitting your text into tokens.

Context window strategy

The context window is the total number of tokens a model can hold in view at once, input and output combined. Go over it and the request fails outright, it isn't a soft limit the model quietly works around. That's what the usage bar above the counter is for: it turns "is this prompt safe to send" from a guess into a number you can watch climb as you paste in more.

In practice, staying inside the window is a budgeting problem. Trim what doesn't need to be there, summarize long reference material instead of pasting it in full, and remember you need headroom left over for the model's own response, not just your input. A prompt that exactly fills the window leaves no room for an answer.

Frequently asked questions

Does my text leave my browser?
No. Tokenization runs entirely in your browser using tiktoken. Your text is never sent to or stored on a server, not even to count it.
Why don't you support Claude, Gemini, or Llama?
Because there's no public, offline tokenizer for them to run locally. OpenAI publishes tiktoken, so an exact, local count is possible. For the others, the only way to get a number would be to guess, and this tool doesn't present a guess as a real count.
Why do different models count the same text differently?
Because GPT-4o, GPT-4o mini, and o3-mini use one BPE encoding (o200k_base) and GPT-3.5 Turbo uses an older one (cl100k_base). Different encodings split the same text into different tokens, so switching models can change the count even though your text hasn't changed at all.
What happens if my text goes over the context window?
The request fails. A model's context window is a hard limit on input and output combined, not a soft cap it works around quietly. The usage bar turns yellow as you approach it and red once you're past it, so you can catch it before you send anything.
Are these counts exact or estimated?
Exact. This tool computes the real token count using tiktoken, the same tokenizer library OpenAI's own models use, not a word-count approximation.