fix(google): map reasoning_effort to thinkingBudget on Gemini 2.5 - #1768
Open
aayushbaluni wants to merge 1 commit into
Open
fix(google): map reasoning_effort to thinkingBudget on Gemini 2.5#1768aayushbaluni wants to merge 1 commit into
aayushbaluni wants to merge 1 commit into
Conversation
Vertex has two mutually exclusive thinking controls: thinkingLevel (MINIMAL/LOW/MEDIUM/HIGH), which is Gemini 3+ only, and thinkingBudget (integer), which is the Gemini 2.5 family. The reasoning_effort transform emitted thinkingLevel for every model. Gemini 2.5 silently ignores thinkingLevel, so reasoning_effort had no effect there. This is invisible on most 2.5 variants because they default to thinking-on; gemini-2.5-flash-lite defaults to a thinking budget of 0, so the request returned HTTP 200 with zero reasoning tokens and no warning. thinkingLevel was introduced in 318da22 (Thinking level support for Gemini 3 Pro) and applied unconditionally. Branch on the model family instead, and apply the same fix to the google provider, which had the identical code. Fixes Portkey-AI#1639
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1639.
reasoning_effortwas translated tothinkingLevelfor every Gemini model, butthinkingLevelis Gemini 3+ only. On the Gemini 2.5 family the parameter is silently ignored server-side, soreasoning_efforthad no effect.Per Vertex's thinking docs:
thinkingLevel(MINIMAL/LOW/MEDIUM/HIGH)thinkingBudget(integer)This is invisible on most Gemini 2.5 variants because they default to thinking-on, so the model reasons anyway and the dropped parameter never shows up.
gemini-2.5-flash-liteis the exception: it defaults to a thinking budget of0, so the request returns HTTP 200 with zero reasoning tokens and no error — exactly what @davidwhite-spec reported.How it got here
thinkingLevelwas added in 318da22, titled "map openai reasoning_effort to gemini thinking level", following a revert of "Thinking level support for Gemini 3 Pro". The mapping was correct for Gemini 3 but applied unconditionally:Change
Branch on the model family:
thinkingLevel(unchanged behavior)thinkingBudget, scaled by effort (minimal512 →high24576)thinkingLevel, preserving today's defaultThe helper is exported from
google-vertex-ai/transformGenerationConfig.tsand reused byproviders/google/chatComplete.ts, which had a byte-identical copy of the bug. The model id is matched with/gemini-2\.5/so it works for both the bare (gemini-2.5-flash) and provider-prefixed (google.gemini-2.5-flash) forms that reach this transform.The explicit
thinking: {type, budget_tokens}parameter is untouched, and there's a test pinning that.Tests
New
src/providers/google-vertex-ai/transformGenerationConfig.test.ts— 14 tests covering:thinkingBudgeton Gemini 2.5, and never emitsthinkingLevelgoogle.-prefixed formthinkingLevelthinkingLevelreasoning_effort: 'none'still emits nothingthinkingparam is unaffectedVerification
jest src/providers/google-vertex-ai src/providers/google: 32 passed (18 on unmodifiedmain, so +14 and no regressions).supportsThinkingLevelback totrue(i.e. the pre-fix behavior) fails 7 of the 14 new tests, so they measure the fix rather than decorating it.jest src/: 61 passed vs 47 onmain; the pre-existing suite failures and the twotsc --noEmiterrors (bytez/api.ts,open-ai-base/index.ts) are identical before and after this change.prettier --checkclean on all three files.Note on scope
The issue also reports that
/v1/responsesbehaves differently from/v1/chat/completions. That routing isn't in the OSS repo — Vertex doesn't registercreateModelResponseingoogle-vertex-ai/index.ts— so I can't address the endpoint-axis asymmetry here. This PR fixes the model-axis half, which is the part that lives in this codebase and is wrong on the chat-completions path too. I don't have Vertex credentials, so this is verified by unit test and against Google's documented parameter matrix rather than by a live call; a maintainer with agemini-2.5-flash-litekey can confirm reasoning tokens become non-zero.