LLMscore
Tokens & tokenization
Models read and write integer tokens, not characters — and you pay, wait and run out of context per token.
What it is and why it exists
A tokenizer (usually byte-pair encoding) splits text into sub-word pieces from a fixed vocabulary of ~50k–200k entries. Everything — price, context limits, rate limits, latency — is counted in tokens, so the tokenizer quietly shapes the economics of every request.
Quick prototype
Estimate with “~4 characters ≈ 1 token” for English and move on; count exactly only when you hit a limit.
In production, at scale
Count with the provider’s own tokenizer or token-counting endpoint before sending, budget each prompt section in tokens, and track tokens per request as a first-class metric. Non-English text, code and numbers can cost 1.5–3× more tokens than English prose for the same content.
Vendors and tools
| tiktoken / gpt-tokenizer | OpenAI’s BPE encodings (o200k_base, cl100k_base) for exact local counts |
|---|---|
| Anthropic token counting API | Exact counts for Claude models before sending |
| Hugging Face tokenizers | Fast tokenizers for open-weight models |
| SentencePiece | Tokenizer used by many open models (unigram/BPE) |
On AWS: Bedrock reports input/output token counts per invocation in the response metadata and CloudWatch metrics.
How it fails
- Budgeting in characters, then overflowing the context window on Hindi, Japanese or code-heavy inputs
- Letter-level tasks (counting letters, reversing words) fail because the model never sees individual characters
- Numbers split into odd chunks, which hurts arithmetic and exact copying of IDs
What the interviewer asks next
Why does the same paragraph cost more in Hindi than in English?
BPE vocabularies are learned mostly from English-heavy data, so other scripts get split into more, smaller pieces. Same meaning, more tokens — more cost, more latency, less room in the window.
Why do models struggle to count the letters in a word?
The word arrives as one or two tokens, not letters. The model has to have memorised the spelling of each token; it can’t look inside it.
How would you budget a prompt precisely?
Tokenize each section with the target model’s tokenizer, assign a budget per section, and enforce it in the context assembler — never by truncating the final string blindly.