Skip to content

translator: accept reasoning_effort high for Gemini 3 Pro models - #2749

Open
AlSh007 wants to merge 6 commits into
theagentrouter:mainfrom
AlSh007:fix/gemini-pro-reasoning-effort-high
Open

AlSh007 wants to merge 6 commits into
theagentrouter:mainfrom
AlSh007:fix/gemini-pro-reasoning-effort-high

Conversation

@AlSh007

@AlSh007 AlSh007 commented Sep 27, 2026 •

Copy link
Copy Markdown

Description

mapReasoningEffortToThinkingLevel rejects reasoning_effort: "high" for any Gemini 3 model whose name does not contain flash. A Chat Completions request against gemini-3-pro with reasoning_effort: "high" therefore fails with invalid reasoning effort: ... reasoning effort 'high' is only supported for Gemini Flash models before it reaches Vertex, while the same request with medium succeeds and is sent as thinking_level: high.

The guard looks carried over from the none case, where it is correct because only Flash supports the minimal thinking level. For high it is not: Google's thinking docs [1] list high as a supported level for every Gemini 3 model and as the default level for gemini-3-pro-preview and gemini-3.1-pro-preview, the Vertex OpenAI compatibility guide [2] does not restrict it, and the function's own doc comment already says "high" → ThinkingLevelHigh without a model restriction.

This change maps high to ThinkingLevelHigh for all models and adds the Pro case to TestMapReasoningEffortToThinkingLevel and to the openAIReqToGeminiGenerationConfig table. The new rows fail on main with the error above and pass with the fix. go test ./internal/translator/ passes.

AI usage: I used Claude Code [3] to help find the mismatch and draft the change; I reviewed the code and ran the tests locally.

Related Issues/PRs (if applicable)

The guard was introduced in #1844, whose high test only covers gemini-3-flash.

1: https://ai.google.dev/gemini-api/docs/thinking
2: https://docs.cloud.google.com/vertex-ai/generative-ai/docs/start/get-started-with-gemini-3#openai-example
3: https://claude.com/claude-code

@AlSh007
AlSh007 requested a review from a team as a code owner September 27, 2026 16:54
@netlify

netlify Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for theagentrouter canceled.

Name Link
🔨 Latest commit 54bb2de
🔍 Latest deploy log https://app.netlify.com/projects/theagentrouter/deploys/6ac938bd98a6ce0008c8bb22

@missBerg missBerg added bug Something isn't working area/translation Provider/endpoint coverage and schema translation (incl. fidelity bugs) labels Sep 30, 2026
@codecov

codecov Bot commented Sep 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread internal/translator/gemini_helper.go Outdated
@@ -608,7 +608,7 @@ func isGeminiFlashModel(model internalapi.RequestModel) bool {
// - "none" → ThinkingLevelMinimal (Gemini Flash only)
// - "low" → ThinkingLevelLow
// - "medium" → ThinkingLevelMedium for Flash, ThinkingLevelHigh for Pro

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.

gemini 3.1 pro preview supports medium thinking according to the doc you linked[1]. We should update to the a more accurate representation of what's available

  1. https://ai.google.dev/gemini-api/docs/thinking#thinking-levels

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, thanks. Per the thinking-levels table, gemini-3.1-pro-preview lists low/medium/high while gemini-3-pro-preview lists only low/high. Pushed b7826ec: medium now maps to ThinkingLevelMedium for Flash and 3.1 Pro, and only falls back to ThinkingLevelHigh for Gemini 3 Pro. Doc comment and tests updated (3.1 Pro → medium, 3 Pro preview → high).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Update: added the missing DCO sign-off to my commit, so the fix is now ff8a740 (same change as the earlier b7826ec).

@AlSh007
AlSh007 force-pushed the fix/gemini-pro-reasoning-effort-high branch from b7826ec to ff8a740 Compare October 5, 2026 07:51
@AlSh007

AlSh007 commented Oct 6, 2026

Copy link
Copy Markdown
Author

Rebased onto current main. The medium-thinking mapping for 3.1 Pro from your review is already in this branch. Ready for another look.

@AlSh007
AlSh007 force-pushed the fix/gemini-pro-reasoning-effort-high branch from ff8a740 to 4664127 Compare October 6, 2026 09:20
Comment thread internal/translator/gemini_helper.go Outdated
// Gemini 3 Pro only lists "low" and "high"; Flash and Gemini 3.1 Pro also list "medium".
// https://ai.google.dev/gemini-api/docs/thinking#thinking-levels
func supportsMediumThinkingLevel(model internalapi.RequestModel) bool {
return !strings.Contains(strings.ToLower(model), "gemini-3-pro")

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.

nit: gemini-3.1-flash-lite-image also does not support medium

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, thanks. The thinking-levels table lists gemini-3.1-flash-lite-image with only minimal and high, so medium now falls back to ThinkingLevelHigh there, same as Gemini 3 Pro. Pushed 0e3ab35 with a test case and updated the doc comments.

@AlSh007
AlSh007 force-pushed the fix/gemini-pro-reasoning-effort-high branch from 4664127 to 0e3ab35 Compare October 6, 2026 14:54
@AlSh007

AlSh007 commented Oct 6, 2026

Copy link
Copy Markdown
Author

@aabchoo I pushed 0e3ab35 for the gemini-3.1-flash-lite-image nit (medium now falls back to high there, with a test). CodeQL, Precommit and Build and Test are waiting on action_required for the new head. Could you approve the workflow run so CI can start? Thanks!

@AlSh007

AlSh007 commented Oct 8, 2026

Copy link
Copy Markdown
Author

/retest

AlSh007 and others added 3 commits October 9, 2026 19:26
mapReasoningEffortToThinkingLevel rejected reasoning_effort "high" for any
Gemini 3 model whose name does not contain "flash", so a Chat Completions
request against gemini-3-pro with reasoning_effort: high failed with an
invalid request body error before reaching Vertex. The guard was carried
over from the "none" case, where it is right because only Flash supports
the minimal thinking level. Google's thinking docs list high as a supported
level for every Gemini 3 model and as the default for the Pro models, and
the function already maps "medium" on Pro to ThinkingLevelHigh.

Map "high" to ThinkingLevelHigh for all models and cover the Pro case in
both the unit table and the generation config table.

AI assistance: Claude was used to help find the mismatch and draft the
change; it was reviewed and tested locally.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: AlSh007 <alok44170@gmail.com>
…ini 3.1 Pro

Gemini 3 Pro only lists low/high thinking levels, but Gemini 3.1 Pro
(like Flash) also supports medium. Only fall back to high for Gemini 3 Pro.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: AlSh007 <85677626+AlSh007@users.noreply.github.com>
….1 Flash-Lite Image

gemini-3.1-flash-lite-image lists only minimal and high thinking levels, so
medium has no equivalent there, as with Gemini 3 Pro.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: AlSh007 <85677626+AlSh007@users.noreply.github.com>
@AlSh007
AlSh007 force-pushed the fix/gemini-pro-reasoning-effort-high branch from 0e3ab35 to 4654253 Compare October 9, 2026 13:56
@AlSh007

AlSh007 commented Oct 9, 2026

Copy link
Copy Markdown
Author

@aabchoo this is rebased onto current main (it was 7 commits behind) and the translator tests pass locally. Your review comments are addressed: medium now maps to ThinkingLevelMedium on Gemini 3.1 Pro and falls back to high on Gemini 3 Pro and 3.1 Flash-Lite Image. The last full CI run on this change was green.

Since the push, CodeQL, Precommit and Build and Test are waiting on action_required. Could you, or any maintainer, approve the workflow run, and merge once CI is green? Thanks!

@aabchoo
aabchoo enabled auto-merge (squash) October 9, 2026 15:27
@AlSh007

AlSh007 commented Oct 9, 2026

Copy link
Copy Markdown
Author

@aabchoo thanks for enabling auto-merge. I updated the branch to current main (merge commit 94e5b55) so it's no longer behind. Since that push came from my fork, CodeQL, Precommit and Build and Test are waiting on action_required again. Could you approve the workflow run so CI can start and auto-merge can go through? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/translation Provider/endpoint coverage and schema translation (incl. fidelity bugs) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants