Gemini 4 and 3.6+ ignore temperature, top_p, top_k: remove them
Gemini 4 and 3.6+ ignore custom temperature, top_p, top_k and send a deprecation warning header; a 400 is planned later. Remove all three now.
If temperature: 0 still gives different answers from Gemini 4 every time, or the response carries a deprecation warning header, the value is not being applied. The official Gemini API docs say Gemini 4 and Gemini 3.6+ models ignore custom values for temperature, top_p, and top_k and return deprecation warning headers; the fix is to remove all three from your requests.
[1] Check which model you call; what to do depends on it.
| Model | How the three values are handled | What to do |
|---|---|---|
| Gemini 4 · Gemini 3.6+ | Custom values ignored, warning header | Remove the three from the request |
| Earlier Gemini 3 | Applied, but temperature below 1.0 can cause looping or degraded performance | Keep the defaults (temperature 1.0) |
The Gemini 3 guide likewise says code that set a low temperature should drop that line and use the default of 1.0. Moving to Gemini 3 models with old settings carried over is the trap.
[2] Find where the three values are set in code and config. SDKs use temperature, top_p, top_k; REST bodies use temperature, topP, topK.
$ grep -rnE "temperature|top_?p|top_?k|topP|topK" --include=*.py --include=*.js --include=*.ts --include=*.json .Shared wrappers or frameworks sometimes inject defaults, so if your own code has none, check that library's generation settings too.
[3] Remove the three. If the generationConfig of a REST generateContent body had lines such as "temperature": 0.2, "topP": 0.9, "topK": 40, take out only those and leave other settings like output length alone.
{ "contents": [{"parts": [{"text": "Explain how AI works"}]}], "generationConfig": { "maxOutputTokens": 1024 }}If your code keeps settings per model, branch so the three are dropped only for Gemini 4 and 3.6+ and kept for other models. Tie the settings to the model name, so nothing breaks when these become 400s.
[4] If you lowered temperature to pin the answer down, use something else. The official docs name no replacement parameter. For unstable output shape, structured output with a response schema is the right tool; see Lock Gemini's response to a JSON schema. For checks that need the same answer for the same input, store results and compare them instead.
[5] After removing them, check whether the warning is gone in the response headers. Use -D - to print only headers.
$ curl -sS -D - -o /dev/null "https://generativelanguage.googleapis.com/v1beta/models/<model>:generateContent" -H "x-goog-api-key: $GEMINI_API_KEY" -H "Content-Type: application/json" -d @request.jsonOpenAI reasoning models also refuse temperature in some cases, but there you get a 400 right away; see Fix OpenAI "Unsupported value: 'temperature'" (reasoning).