Applied AI·topic 2 of 12
Tokens
Tokens are the unit of everything: cost, latency, context limits and most odd model behaviour. Internalise this section and half the API layer explains itself. Pair with scripts 1 to 3.
Read in order · tick what you already know
- 01
every bill, rate limit and context error you will ever see is denominated in tokens, not words or requests.
Token
- 02
the same string cost a different number of tokens on the other provider, because each model family ships its own.
Tokeniser
- 03
everything the model can ever emit is drawn from one fixed list of a few tens of thousands of entries.
Vocabulary
- 04
the model never sees your text at all, only the list of integers the tokeniser handed over.
Token ID
- 05
you notice a common word costs one token and a rare surname costs five, because frequent pairs got merged and yours was left in pieces.
Byte pair encoding (BPE)
- 06
the model cannot see individual characters unless the tokeniser happens to split them out.
Tokeniser quirks
- 07
the reserved markers for turn boundaries get inserted for you, and malformed ones are behind a good share of jailbreaks.
Special tokens
- 08
if a local model behaves bizarrely, a wrong or missing chat template is the first suspect.
Chat template
- 09
everything you send and everything it says has to fit one budget, and the retrieved documents are what usually blow it.
Context window
- 10
you halved the prompt and the bill barely moved, because the long generated answer was where the money actually went.
Input vs output tokens
- 11
the request fit fine and the answer still stopped mid-sentence, because the output cap is a separate and much smaller limit.
Context length vs max output
- 12
you count the tokens before sending rather than multiplying the word count by 1.3 and hoping.
Token counting
- 13
you time it yourself on your own hardware, because the number in the announcement was measured on something else.
Tokens per second