Lab 03 · foundations

Tokenizer Lab

Before a model can reason about a sentence, it has to turn the sentence into integers. The tokenizer decides the units, the context budget and part of the bill. Here is the text the model actually receives.

2 vocabulariesExact countsBrowser only
What this counts. The lab bundles the real o200k_base and cl100k_base tokenizers from gpt-tokenizer. Counts are exact for those vocabularies. Other model families use different tokenizers, so their counts will differ. Nothing you type leaves the browser.
tokenizer / labloading vocabGPT-4o family
Presets

Loading the vocabulary and merging rules…

Why the split matters

A model does not see letters or words. It sees token IDs from a fixed vocabulary. The same sentence can cost different numbers of tokens under different vocabularies, and rare words, code identifiers, JSON punctuation and non-Latin scripts are often split into several tokens.

context used = input tokens + output tokens + tool results + retrieved documents
cost = input tokens × input price + output tokens × output price

Counts here are exact for the two OpenAI vocabularies. Llama, Qwen, Mistral and Gemini use different tokenizers, so their counts will differ. Tokenization is model-specific.

Guided experiments

Find the expensive characters.

Tokenization is full of small surprises. Change one thing, then compare the token count and the split, not just the text.

01

A word is not a token.

Type “internationalization” and then “cat”. Both are single words. Compare their token counts and the visible pieces. Then paste a long identifier from your own code. Which one would you rather pay for a million times?

02

Code is punctuation.

Choose the JSON preset. Look at the braces, quotes and colons. They are structure to a parser and tokens to a model. Switch vocabularies and find where the split changes. This is part of why tool-call formats are designed to be easy to emit.

03

English is not neutral.

Choose Multilingual and compare characters per token. A sentence with the same meaning can cost very different token counts in different scripts. That is a product and fairness decision, not just a formatting detail.

Type at least two characters. Search is indexed after the production build.
Lessons · labs · glossary↑↓ to browse · esc to close