import { Callout } from '@/components/ui/callout';
When you start using the Gemini API, the temperature parameter is one of the first things you notice changes outputs dramatically. The same prompt feels completely different at 0.0 versus 1.0. What is harder to find is concrete guidance on which value to actually use for which task. Most implementations I see ship with temperature=0.7 simply because that is the default.
After running Gemini in production across several services, I have built up a working sense of the right value per task. This article distills that into something reproducible. Code samples are in both Python and TypeScript.
What Temperature Controls
Technically, temperature scales the sharpness of the next-token probability distribution.
temperature=0.0— pick the most likely token every time (deterministic)temperature=1.0— sample from the model's learned distribution as-istemperature>1.0— flatten the distribution; low-probability tokens become more likely
Translated to practical terms: low values mean stable but potentially repetitive, high values mean creative but volatile. The temperature design problem is figuring out where on that axis a given task should sit.
Per-Task Recommendations
These are starting points, not absolutes. Adjust based on your evaluation criteria.
Translation: temperature=0.1–0.3
Translation prioritizes faithful meaning reproduction. I use 0.2 as a default.
from google import genai
client = genai.Client()
def translate_to_japanese(text: str) -> str:
response = client.models.generate_content(
model="gemini-2.5-pro",
contents=f"Translate the following English text into natural Japanese.\n\n{text}",
config={"temperature": 0.2},
)
return response.textAt 0.0 the output drifts toward word-for-word literalism, losing context-aware vocabulary choice. Around 0.2 you hit the sweet spot of accurate and natural. Above 0.5 the model starts inventing nuance that was not in the original.
Summarization: temperature=0.2–0.4
For long-form summarization I center around 0.3. Summarization is fundamentally compression, so you want low temperature, with just a sliver of room for natural phrasing.
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
async function summarizeArticle(article: string): Promise<string> {
const response = await ai.models.generateContent({
model: 'gemini-2.5-pro',
contents: `Summarize the following article in 200 words or fewer.\n\n${article}`,
config: { temperature: 0.3 },
});
return response.text ?? '';
}Automated summarization pipelines stay low for consistency. For social media caption generation, 0.5–0.7 is more useful — you actually want stylistic variety.
Code Generation: temperature=0.0–0.2
Reproducibility is everything in code generation. The same spec should produce the same code on every call.
def generate_function(spec: str) -> str:
response = client.models.generate_content(
model="gemini-2.5-pro",
contents=f"Implement a Python function from the following spec. Type hints required.\n\n{spec}",
config={"temperature": 0.0},
)
return response.textWhen generating code samples for the Dolice Labs sites I run, I default to temperature=0.0. People sometimes call this "boring." Code does not need to be interesting. It needs to run, pass tests, and stay maintainable.
The exception is initial UI design exploration — when you genuinely want to see multiple options, push it to 0.5–0.7, generate three to five candidates, and let a human choose.
Chat / Conversational Agents: temperature=0.7–0.9
In a chatbot, identical answers to the same question feel robotic. I center around 0.8, which gives enough variation to feel natural without sliding into incoherence.
def chat_response(user_message: str, history: list) -> str:
response = client.models.generate_content(
model="gemini-2.5-pro",
contents=[*history, {"role": "user", "parts": [{"text": user_message}]}],
config={
"temperature": 0.8,
"top_p": 0.95,
},
)
return response.textPair high temperature with top_p=0.95. The top_p cap keeps you on the high-probability tail even when temperature is generous, preserving quality.
Creative Writing / Brainstorming: temperature=0.9–1.2
For poems, stories, and ad copy, push to around 1.0. When you want to maximize idea diversity for human curation, 1.2 works well.
Above 1.5, you start getting outputs where meaning collapses. With Gemini 2.5, I treat 1.0 as the safe ceiling.
Classification / Extraction: temperature=0.0
For sentiment classification, named entity extraction, or structured data generation, there is no reason to leave 0.0. Reproducibility is the quality criterion here.
Quick Reference Table
| Task | Recommended Temperature | top_p |
|---|---|---|
| Classification / Extraction | 0.0 | 1.0 |
| Code Generation | 0.0–0.2 | 1.0 |
| Translation | 0.1–0.3 | 0.95 |
| Summarization | 0.2–0.4 | 0.95 |
| General Q&A | 0.4–0.6 | 0.95 |
| Chat / Dialogue | 0.7–0.9 | 0.95 |
| Creative / Brainstorm | 0.9–1.2 | 0.95 |
Build a Habit of Measuring
The numbers above are starting points. The actual best value for your prompt and data has to be measured. When I set up a new pipeline, I run a quick evaluation script:
import statistics
def evaluate_temperature_stability(prompt: str, target_temp: float, n_trials: int = 5):
"""Call the same prompt n times and observe length/uniqueness."""
responses = []
for _ in range(n_trials):
r = client.models.generate_content(
model="gemini-2.5-pro",
contents=prompt,
config={"temperature": target_temp},
)
responses.append(r.text)
lengths = [len(r) for r in responses]
print(f"Temperature: {target_temp}")
print(f" Length: mean={statistics.mean(lengths):.0f}, stdev={statistics.stdev(lengths):.0f}")
print(f" Unique responses: {len(set(responses))} / {n_trials}")
return responsesRun it at 0.0, 0.3, 0.7, 1.0 and watch how length variance and unique-response counts change. After a few minutes you have an intuitive feel for the temperature zone that fits your task.
Two Common Misconceptions
Misconception 1: Lower temperature always means higher accuracy.
0.0 is reproducible, but on multi-step reasoning tasks, the model can lock into the first plausible path and miss the right answer. For hard math or multi-hop reasoning, 0.3–0.5 often beats 0.0 on accuracy.
Misconception 2: Temperature is the only knob that matters.
top_p (nucleus sampling), top_k, max_output_tokens, and your system prompt all interact. Temperature is important, but it is not the whole story.
Next Step
Open your current Gemini integration and check what value temperature is set to. If it is the default, it is probably 1.0. Pick the row in the table that matches your task and try it. The resulting jump in output stability is usually obvious within five test runs.