# Temperature

> The Temperature is a parameter that controls how random the output of a language model is.

## What does temperature do in an LLM?

The parameter that controls randomness when the model chooses the next token. Low values make answers more predictable and focused, which suits code and facts, while high values make them more varied and creative.

- Topic: Generation Settings
- Type: concept

## Example

Wrong:

```js
const res = await llm.generate({
  prompt: extractInvoiceFieldsPrompt,
  temperature: 1.2,
});
```

Right:

```js
const res = await llm.generate({
  prompt: extractInvoiceFieldsPrompt,
  temperature: 0,
});
```

Extraction needs the most likely tokens, so a low temperature gives steadier fields; keep higher values for creative text.

## Common mistakes

- Expecting temperature '0' to return exactly the same answer every time.

## Key points

- Code generation, extraction and classification use a low temperature.
- Temperature and top-p are not both raised at once; usually only one is tuned.
- Tests do not rely on identical output even at temperature '0'.

## Interview questions

### What temperature should I use for code generation?

A low value near '0' suits code, extraction and classification. Higher values give more varied text for brainstorming or creative writing.

### Is temperature 0 deterministic?

Not fully. It favors the most likely token, but batching and hardware effects can still change the output between runs.

### Temperature vs top-p: which should I change?

Usually change one and leave the other at its default. Both reshape the same token distribution, so tuning both makes behavior hard to predict.

## Related cards

- [Top-p](https://wonderium.dev/ai/top-p.md)
- [Max Tokens](https://wonderium.dev/ai/max-tokens.md)
- [Structured Output](https://wonderium.dev/ai/structured-output.md)
- [LLM API](https://wonderium.dev/ai/llm-api.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/temperature
- Last updated: 2026-11-25
