Bytes, characters, tokens: which one gets billed and how do they relate?
Billing is per token, not per byte or character. The byte to token ratio is content-dependent and model-specific; only the model's tokenizer tells you the exact count.
Imagine a courier that charges by parcels, not by weight. You arrive with a bag of stuff and the courier breaks it into parcels according to their own rules. English text packs neatly: about 3 to 4 characters per parcel. Minified JSON or Python code does not pack neatly, because the courier's rules were built for prose and weird punctuation breaks at the seams. Hindi or Japanese characters use up parcels at a different rate again, because the rules learned during training were trained on mostly-English text and never saw enough non-Latin characters to compress them well. So 1 KB of English costs about 250 parcels; the same 1 KB of code or non-English text can cost twice as much. The only way to know your real bill is to run the courier's own ruler over your specific bag.
Detailed answer & concept explanation~7 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: distinguish bytes, characters, and tokens, state that billing is per token, explain BPE produces content-dependent compression ratios, give numbers for English vs code vs non-Latin text, and name the canonical tools for accurate counting.
Real products, models, and research that use this idea.
- OpenAI's `tiktoken` library counts tokens locally; `tiktoken.encoding_for_model('gpt-4o')` returns the o200k_base encoder used for billing.
- Anthropic's `messages.count_tokens` endpoint returns the exact billable token count for a Claude prompt before submitting it.
- Llama 3 ships a 128k-vocabulary SentencePiece tokenizer that improves compression on non-English text versus Llama 2's 32k vocabulary.
- GPT-4o's switch from cl100k_base to o200k_base cut Hindi token counts by roughly 4x and Korean by ~1.7x, lowering effective cost for those markets.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does the same text cost more tokens in cl100k_base than in o200k_base?
QHow does byte-level BPE prevent out of vocabulary issues?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Estimating cost by character count. Tokenizers compress differently across content types, so character-based estimates can be off by 2x or more for code and non-Latin text.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.