Skip to content

fix(gemini): map minimal thinking to low for Gemini 3.7 and 3.8 Flash - #41201

Merged
mateo-berri merged 2 commits into
mainfrom
litellm_gemini_37_38_flash_no_minimal_thinking
Sep 16, 2026
Merged

mateo-berri merged 2 commits into
mainfrom
litellm_gemini_37_38_flash_no_minimal_thinking

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Gemini 3.7 and 3.8 Flash reject thinkingLevel: minimal with a 400
  • LiteLLM still sent minimal for reasoning_effort minimal, none and disable on them
  • On /v1/messages, thinking: {type: disabled} hit the same path and failed
  • Claude Code with thinking off behind a Gemini 3.8 Flash alias got a 500 and retried ten times

How it solves it:

  • Gemini 3.7 and 3.8 Flash now floor those efforts to thinkingLevel: low
  • The floor comes from the cost map: supports_minimal_reasoning_effort: false on those entries
  • Earlier Gemini 3.x Flash models keep minimal
  • The enable_gemini_default_thinking_level_low path uses the same rule
  • is_explicitly_disabled_factory in litellm.utils goes public, as its provider-config readers already implied
  • A regression test drives /v1/messages with thinking disabled through the Gemini bridge

User Flow

Before: a developer who aliases a Claude model name to vertex_ai/gemini-3.8-flash gets a 400 whenever their client turns thinking off

  1. They send POST https://litellm-domain/v1/messages with "model": "claude-sonnet-5" and "thinking": {"type": "disabled"}
  2. The response is 400 Vertex_aiException BadRequestError with "Thinking level is unsupported: THINKING_LEVEL_MINIMAL"
  3. In Claude Code pointed at the proxy with thinking off (MAX_THINKING_TOKENS=0), every prompt ends in API Error: 500 ... THINKING_LEVEL_MINIMAL after ten retries
  4. The same happens on POST https://litellm-domain/v1/chat/completions with "model": "vertex_ai/gemini-3.8-flash" and "reasoning_effort": "minimal", "none" or "disable"

After: the same requests succeed

  1. They send POST https://litellm-domain/v1/messages with "model": "claude-sonnet-5" and "thinking": {"type": "disabled"}
  2. The response is 200 with the Gemini answer
  3. Claude Code with thinking off answers the prompt
  4. POST https://litellm-domain/v1/chat/completions with "reasoning_effort": "minimal", "none" or "disable" on vertex_ai/gemini-3.8-flash also returns 200

Relevant issues

Fixes #37314

Overlaps with community PRs #36874 and #37478, which target a non-default branch and cover a subset of the paths

Affected release

Linear ticket

Resolves LIT-7775

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Setup shared by both legs. Config lit7775-qa-config.yaml has five deployments, all vertex_location: global (the only location serving 3.8 Flash): claude-sonnet-5 and claude-haiku-4-5 are aliases of vertex_ai/gemini-3.8-flash, and vertex_ai/gemini-3.8-flash, vertex_ai/gemini-3.7-flash and the control vertex_ai/gemini-3.6-flash are listed under their own names, with master_key: sk-lit7775-qa, drop_params: false and no database. Each leg is one proxy with two workers, python litellm/proxy/proxy_cli.py --config lit7775-qa-config.yaml --port <port> --num_workers 2 --detailed_debug: Before from the merge base 7e3ca14 on port 53382, After from a1ad95d on port 56949. Claude Code v2.1.273 runs interactively in tmux as ANTHROPIC_BASE_URL=http://127.0.0.1:<port> ANTHROPIC_AUTH_TOKEN=sk-lit7775-qa ANTHROPIC_MODEL=claude-sonnet-5 ANTHROPIC_SMALL_FAST_MODEL=claude-haiku-4-5 MAX_THINKING_TOKENS=0 claude and gets the prompt Reply with just the single word ok. The curl cases use H='Authorization: Bearer sk-lit7775-qa' and the message Reply with the single word ok

Before (7e3ca14)

Claude Code with thinking off

  1. Launch Claude Code as above against port 53382 and send the prompt
  2. The pane cycles through Retrying in Ns · attempt N/10 for 3m 45s and ends on API Error: 500 litellm.APIError: litellm.BadRequestError: Vertex_ai_betaException BadRequestError - b'{ "error": { "code": 400, "message": "Thinking level is unsupported: THINKING_LEVEL_MINIMAL", "status": "INVALID_ARGUMENT" } }'

pr41201-a1ad95dbbd-lit7775-before-claude-error.png

/v1/messages thinking disabled

  1. curl -s -w "HTTP %{http_code}\n" http://127.0.0.1:53382/v1/messages -H "$H" -H 'content-type: application/json' -d '{"model":"claude-sonnet-5","max_tokens":64,"thinking":{"type":"disabled"},"messages":[{"role":"user","content":"Reply with the single word ok"}]}'
  2. HTTP 400 with body {"type": "invalid_request_error", "message": "litellm.BadRequestError: Vertex_aiException BadRequestError - {\"error\": {\"code\": 400, \"message\": \"Thinking level is unsupported: THINKING_LEVEL_MINIMAL\", \"status\": \"INVALID_ARGUMENT\"}}. Received Model Group=claude-sonnet-5 ..."}

/v1/messages thinking disabled, streamed

  1. Same request with "stream": true, read with curl -s -N
  2. The stream body is {"error":{"message":"litellm.APIError: litellm.BadRequestError: Vertex_ai_betaException BadRequestError - b'{ \"error\": { \"code\": 400, \"message\": \"Thinking level is unsupported: THINKING_LEVEL_MINIMAL\", \"status\": \"INVALID_ARGUMENT\" } }'","type":"internal_server_error","param":null,"code":"500"}}

/v1/chat/completions reasoning_effort minimal, none, disable

  1. for m in vertex_ai/gemini-3.8-flash vertex_ai/gemini-3.7-flash; do for e in minimal none disable; do curl -s -w "HTTP %{http_code}\n" http://127.0.0.1:53382/v1/chat/completions -H "$H" -H 'content-type: application/json' -d "{\"model\":\"$m\",\"max_tokens\":64,\"reasoning_effort\":\"$e\",\"messages\":[{\"role\":\"user\",\"content\":\"Reply with the single word ok\"}]}"; done; done
  2. All six return HTTP 400 with {"message": "litellm.BadRequestError: Vertex_aiException BadRequestError - {\"error\": {\"code\": 400, \"message\": \"Thinking level is unsupported: THINKING_LEVEL_MINIMAL\", \"status\": \"INVALID_ARGUMENT\"}}. Received Model Group=<model> ..."}

Controls

  1. /v1/messages on claude-sonnet-5 with "thinking":{"type":"enabled","budget_tokens":1024} and "max_tokens":2048: HTTP 200, content block types ["text"]
  2. /v1/messages on vertex_ai/gemini-3.6-flash with "thinking":{"type":"disabled"}: HTTP 200, content [{"type": "text", "text": "ok"}]

After (a1ad95d)

Claude Code with thinking off

  1. Launch Claude Code as above against port 56949 and send the prompt
  2. The pane shows ⏺ ok after Baked for 4s

pr41201-a1ad95dbbd-lit7775-after-tip-claude-ok.png

/v1/messages thinking disabled

  1. Same curl against port 56949
  2. HTTP 200, content [{"type": "text", "text": "ok"}]

/v1/messages thinking disabled, streamed

  1. Same streamed curl against port 56949
  2. event: message_start with "model":"claude-sonnet-5", then event: content_block_start for a text block, then event: content_block_delta with {"type": "text_delta", "text": "ok"}

/v1/chat/completions reasoning_effort minimal, none, disable

  1. Same loop against port 56949
  2. All six return HTTP 200. The three vertex_ai/gemini-3.8-flash calls and vertex_ai/gemini-3.7-flash with minimal answer "ok"; vertex_ai/gemini-3.7-flash with none and disable came back with empty choices and "completion_tokens_details": {"reasoning_tokens": 61, "text_tokens": 0}, since level low still thinks and the 64-token budget ran out before the answer
  3. Same two calls with "max_tokens":256: HTTP 200, content "ok", reasoning_tokens 91 and 100
  4. The proxy log shows every none and disable request leaving with thinkingConfig: {'thinkingLevel': 'low', 'includeThoughts': False}, and minimal only on the gemini-3.6-flash control

Controls

  1. /v1/messages on claude-sonnet-5 with thinking enabled: HTTP 200, content block types ["text"]
  2. /v1/messages on vertex_ai/gemini-3.6-flash with thinking disabled: HTTP 200, content [{"type": "text", "text": "ok"}], and the chat form with none reports "completion_tokens_details": {"text_tokens": 1} with no reasoning tokens

Observations from the run:

  • Claude Code default main calls already worked Before: adaptive thinking
  • Its session-title side call sends thinking disabled; failed silently Before
  • Claude Code WebSearch through Vertex 400s on allowed_function_names; pre-existing, untouched
  • Streamed /v1/messages Before error arrived as a 500-shaped body

Type

🐛 Bug Fix

Caveats (if any)

Low

  • The floor is a cost-map opt-out: a Gemini 3.x Flash entry without supports_minimal_reasoning_effort: false still gets minimal
    • gemini-3.8-flash-preview and other unlisted names stay in that bucket until their entries carry the flag
  • low is the lowest level 3.7 and 3.8 Flash accept, so a disabled or minimal request still spends reasoning tokens there (57 to 100 on the one-word prompt above, none on 3.6 Flash at minimal), and a max_tokens that small can come back with empty choices. Same mapping Gemini 3 Pro already had; leaving thinkingConfig out would hand the model its own, higher, default level
  • /model_group/info now advertises supported_reasoning_efforts ["none", "low", "medium", "high"] for the 3.7 and 3.8 Flash groups instead of the six-level default, so the dashboard's complexity router tiers stop offering minimal and xhigh on them
  • A proxy that fetched the remote cost map before this lands keeps sending MINIMAL until the map reloads or the proxy restarts; the bundled map ships the flag
  • CircleCI llm_translation_testing, local_testing_part1, local_testing_part2 and litellm_router_testing are red at the tip on Together AI model_not_available (openai/gpt-oss-20b is no longer serverless), two Azure fallback assertions and one proxy-provider embedding capture that passes locally at both the tip and the merge base; the same four jobs are red on main pipeline #89670 and tests/llm_translation/test_gemini.py passes in the same job
  • The Gemini 3 mapping table in the docs still says Flash maps minimal, disable and none to minimal; docs follow-up

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/cfec9b931a8d4e9fb8b2ab6a7140f9f3
Open in Devin Desktop: https://app.devin.ai/desktop/session/cfec9b931a8d4e9fb8b2ab6a7140f9f3?variant=devin

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 15, 2026 07:10
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@codspeed

codspeed Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_gemini_37_38_flash_no_minimal_thinking (a1ad95d) with main (be6e7ef)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (765e6e4) during the generation of this report, so be6e7ef was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@greptile-apps

greptile-apps Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Gemini 3.7 and 3.8 Flash now use thinkingLevel: low when clients request minimal or disabled thinking, avoiding Vertex requests with the unsupported minimal level. Earlier Gemini 3 Flash models keep their existing minimal mapping.

  • Adds a model capability flag for whether Gemini Flash supports minimal thinking.
  • Applies the same model check to chat completions, Anthropic messages, and the default thinking-level path.
  • Renames the shared explicit-disable helper and updates its callers and tests.

Confidence Score: 5/5

The PR appears safe to merge. No blocking issue remains.

The metadata covers the bare, Gemini, and Vertex names for both affected models. The new bridge test checks the full disabled-thinking request path. Both earlier review threads are resolved.

Important Files Changed
Filename Overview
litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py VertexGeminiConfig now reads the minimal-thinking limit from model metadata and maps disabled, none, and minimal requests to low for Gemini 3.7 and 3.8 Flash.
model_prices_and_context_window.json The model map marks all six bare, Gemini, and Vertex Gemini 3.7 and 3.8 Flash entries as not supporting minimal reasoning.
litellm/utils.py The renamed is_explicitly_disabled_factory keeps the existing provider lookup and bare-model fallback. No old in-repo references remain.
tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py The tests cover direct mapping, the default-thinking flag, the public OpenAI path, and the disabled-thinking messages bridge with a mocked request.

Reviews (2): Last reviewed commit: "fix(gemini): read the minimal thinking f..." | Re-trigger Greptile

@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ex_ai/gemini/vertex_and_google_ai_studio_gemini.py 88.88% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Live Vertex e2e done: main returns 400 THINKING_LEVEL_MINIMAL from Claude Code and curl with thinking disabled, this tip returns 200. Full output on LIT-7775

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ mateo-berri
❌ devin-ai-integration[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a1ad95d. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mateo-berri
mateo-berri merged commit 319f427 into main Sep 16, 2026
138 of 144 checks passed
@mateo-berri
mateo-berri deleted the litellm_gemini_37_38_flash_no_minimal_thinking branch September 16, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: vertex_ai/gemini-3.7-flash returns 400 for reasoning_effort minimal/none/disable — THINKING_LEVEL_MINIMAL is not supported by this model

2 participants