An interactive guide to the six sampling parameters that shape model output: temperature, top_p, top_k, frequency and presence penalties, and max tokens. Each comes with a worked example and a matrix of which providers support it.
Interactive guide to LLM API parameters. Understand what temperature, top_p, top_k, frequency penalty, presence penalty, and max tokens actually do, with live examples and provider compatibility.
Controls randomness. Lower values make output more deterministic and focused. Higher values make output more creative and varied.
Example output at moderate temperature
"Kubernetes uses pods as the smallest deployable unit. Each pod runs one or more containers."
Use 0–0.3 for factual/code tasks, 0.7–1.0 for creative writing, 1.5+ for brainstorming.
| Parameter | API Key | Range | Default | Use Case |
|---|---|---|---|---|
| Temperature | temperature | 0–2 | 0.7 | Use 0–0 |
| Top P (Nucleus Sampling) | top_p | 0–1 | 1 | Usually set to 1 |
| Top K | top_k | 1–100 | 40 | Not available in OpenAI API |
| Frequency Penalty | frequency_penalty | -2–2 | 0 | Set to 0 |
| Presence Penalty | presence_penalty | -2–2 | 0 | Use 0 |
| Max Tokens | max_tokens | 1–128000 | 4096 | Set this to control costs |
The most common mistake is tuning temperature and top_p together. They both truncate the same probability distribution, from different directions: temperature reshapes it, top_p clips its tail. Adjusting both makes the effect of either impossible to reason about. Every major provider recommends changing one and leaving the other at its default.
The second is treating temperature 0 as deterministic. It makes sampling greedy, which is not the same thing: floating-point non-associativity across batched GPU inference means identical requests can still produce different outputs. Low temperature reduces variance substantially; it does not give you reproducibility guarantees.