What temperature should I use for code?
Lower values, such as 0 to 0.3, usually work well for code and data extraction where you want consistency. Follow the model provider recommendation, since some models are tuned for a specific default.
A setting that controls how random or predictable a model output is when it picks each next token.
Temperature is a setting that controls how much randomness an AI model uses when picking each next token. At each step, the model scores many possible next tokens. A low temperature, near 0, makes it almost always pick the top choice, so answers are more predictable and repetitive. A higher temperature spreads the choice across more options, giving more varied and sometimes more creative output, but also more mistakes and odd turns. Most APIs accept values from 0 to 1 or 0 to 2. Many chat apps and coding agents set it for you, and some newer reasoning models fix it or ignore it.
If you call a model through an API for tasks like extraction, classification or code generation, lower temperatures generally give steadier results that are easier to test. For brainstorming names or drafting copy, higher values give more variety. In a coding agent you usually cannot change it, and it matters much less than good instructions and context. Changing it is rarely the fix for a model that keeps getting something wrong.
Asking for "a name for a budgeting app" five times at temperature 0 tends to return the same or very similar names. At temperature 1, you get five different ideas, a couple of them unusable. For pulling a date out of an invoice, you want the first behavior; for naming ideas, the second. Some reasoning models ignore the setting entirely and use their own fixed value.
Temperature 0 does not guarantee identical outputs every time, and it does not make answers correct. Small differences can still appear, and a model can repeat the same wrong answer consistently.
All 28 terms are in the AI glossary. For models side by side, see frontier vs open-weight.
Lower values, such as 0 to 0.3, usually work well for code and data extraction where you want consistency. Follow the model provider recommendation, since some models are tuned for a specific default.
Usually not. Coding agents choose their own model settings. Your influence comes from instructions files, the task description and the model or effort level you pick.
Top-p is a related setting that limits choices to the smallest set of tokens whose combined probability reaches p. Providers generally suggest adjusting temperature or top-p, not both.