How Language Models Work: Tokens, Context, Temperature
One customer message travels through this whole page:
Is there any way to get a discount before I commit to the annual plan?
We follow it from raw text to tokens, to numbers, to meaning, to a growing
context, to a bill; and we end where every marketer should: cost per task,
not cost per token.
Tokens: How Text Becomes Pieces
A language model never reads words. It reads tokens: chunks of text, each mapped to an ID (identifier) number in a fixed vocabulary. Type anything below; this is the real GPT-5-family tokenizer running in your browser.
toappears twice: once in
to get,once in
to the.Same ID, different role; the model tells them apart only from the surrounding tokens.
discount.It sees a number. Characters would make sequences too long; whole words can't handle new or rare words (or a typo, or
unmarketability); subword tokenization is the compromise most modern models use. Compare the Persian version: this tokenizer prices it similarly, while another model or phrasing may split it differently. Tokenization decides your unit costs before any pricing page does.
Embeddings: From IDs to Meaning
An ID is just a label; number 11522 is not more
than number 357.
So each token ID is looked up in a giant table and becomes an embedding: a long
list of numbers (a vector) that encodes meaning. Nearby vectors, similar meanings.
Any discount available?,
any promos?, and
is there a deal?land in the same neighborhood of this space. A rule-based chatbot needed a human to script each equivalence; a large language model learned the relationship from data. That is why it generalizes, and also why it can only be as good as the neighborhoods it learned.
Attention: Words Reshape Each Other
Embeddings alone give every word one fixed meaning. But bank
in
river bank
and bank account
should not mean the same thing. Attention is the
mechanism that lets each position update its meaning from permitted context. In a causal,
decoder-only model, a position can attend only to itself and earlier tokens.
The plan is not discountedand
Is the plan discounted?use nearly the same tokens, yet mean opposite things to the model. Meaning became contextual, computed fresh for every input, with each later position able to consult earlier context. That foundational idea is central to modern language models.
Context: What the Model Actually Receives
When a customer types one sentence into a chatbot, that sentence is not what the model receives. The provider assembles a whole package, the context, and the customer's words are usually the smallest part of it.
The Growing Conversation
A bare model call is stateless: it remembers nothing between calls. To continue a conversation, prior context must be supplied again, either by your application or the provider. Step through a four-turn hardware-store chat and watch the input meter climb.
The Key-Value Cache: Don't Pay Twice for the Same Prefix
In attention, every token computes keys and values. A key-value cache stores those computations. If the start of your context is byte-for-byte identical to a recent call, the provider can reuse those computations instead of redoing them, and charges you a fraction of the price for the reused part.
rememberingyou. It is the provider skipping arithmetic it already did, on a prefix that matches exactly. Change one early word and everything after it is recomputed at full price. Stable system prompts are not just good engineering; they are a pricing strategy.
Temperature and Friends: Why the Same Question Gets Different Answers
At each step the model produces a probability for every possible next token, then samples one. Temperature, top_k, and top_p reshape that distribution before the draw. These parameters control response diversity and which candidates remain eligible for selection.
Pricing: Dollars per Task, Not Dollars per Token
Pricing pages list rates for input, cached input, and output tokens. Your real cost also depends on the tokenizer, prompt and history length, output length, and number of calls: cost per task = (fresh-input tokens × input rate) + (cached-input tokens × cached-input rate) + (output tokens × output rate), summed across all calls. Model selection is a procurement decision, and it is workload-dependent. The figures below are illustrative and editable; verify current provider pricing before using them.
Evaluate cost per task, not cost per token.A model can charge more per token, inflate your input count via its tokenizer, and still be cheaper, if it finishes the job in fewer, shorter outputs. The only honest answer to
which model?is a measurement on your own traffic.