What do temperature and max tokens actually do?

Every large language model exposes two dials that shape its output: temperature, which controls how predictable or random the next token is, and max tokens, which is a hard length budget rather than a quality dial. This interactive guide shows both with real, client-side math — a live softmax calculation over next-token probabilities, and a live truncation of a sample response.

How a model picks the next word

Given a prompt like “The ocean was…”, a model scores every candidate next token, then converts those scores into probabilities with softmax(logits / temperature). At temperature 0 it always takes the single highest-scoring token (predictable). As temperature rises toward 2, the probabilities flatten and unlikely tokens get a real chance of being picked (anything can happen).

The exact formula: P(token_i) = exp(z_i / T) / sum_j exp(z_j / T), where z is the logit (the model's raw score for a token) and T is the temperature. At T = 0 this becomes greedy decoding — argmax, no division — since dividing by zero is undefined. The other common sampling knobs are top_p (nucleus sampling, keeps the smallest set of tokens whose probabilities add up to p) and top_k (keeps only the k highest-probability tokens); both filter the distribution after temperature has reshaped it, and all three compose.

Max tokens is a budget, not a dial

Max tokens caps how many tokens a response is allowed to use. It doesn't make answers smarter or more correct — it just stops generation once the budget runs out, sometimes mid-sentence. Higher limits mostly affect cost and latency, since usage-based pricing and response time scale with tokens generated.

Tokens aren't words: a common rule of thumb is roughly 4 characters or 0.75 words per token in English, so token counts and word counts are close but not equal. max_tokens caps output only, and that output shares the model's context window with the input — input tokens plus max_tokens have to fit inside the context window, or the request fails.

Frequently asked questions

What is temperature in an LLM?
Temperature is a number, usually between 0 and 2, that controls how a language model turns its raw next-token scores (logits) into a probability it samples from, via softmax(logits / temperature). Low temperature sharpens the distribution toward the top token; high temperature flattens it.
What happens at temperature 0?
Sampling becomes deterministic: the model always picks the single highest-probability token (argmax / greedy decoding), giving the same output every time for the same input.
Is higher temperature better?
No — it's a trade-off between variety and coherence. Low temperature suits tasks with one correct answer; higher temperature suits open-ended or creative tasks.
What does max tokens control?
A hard upper limit on how many tokens the response may generate. It's a length budget and stop condition, not a quality setting — hitting it cuts the response off wherever it happens to be.
Does max tokens affect response quality?
Not directly — it doesn't improve reasoning or correctness. A limit set too low can truncate a useful answer before it finishes; raising it past what's needed mainly adds cost and latency.
What temperature should I use for a support chatbot?
Low, around 0.1–0.3, for consistent, on-policy answers. Code generation is similar (0–0.3). General chat often uses ~0.7; brainstorming tools often use 1.0–1.3.
What are logits?
The raw, unnormalized scores a model outputs for every possible next token before any probability conversion — one number per vocabulary token, which can be any real number and doesn't sum to 1 on its own. Softmax(logits / temperature) turns them into a probability distribution.
What is the difference between temperature and top_p?
Temperature reshapes the whole probability distribution before sampling by dividing every logit by T. top_p (nucleus sampling) instead filters it, keeping only the smallest set of top-ranked tokens whose probabilities add up to p and discarding the rest. They compose — most APIs let you set both at once.

In OnlyUtils, these live on your LLM agent's settings — see the developer console or go back to onlyutils.com.