Repository navigation
fix(gemini): accept top_logprobs on Google AI Studio models - #49514
mateo-berri wants to merge 3 commits into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
[Medium impact] This PR appears safe to merge with no new actionable findings SummaryAdds Unit and integration tests cover chat requests and Responses requests. The only change since the previous review adds a
Reviews (5) · Last reviewed commit: "fix(gemini): mark the responseLogprobs s..." · Reviewed by Greptile |
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ob param Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
There was a problem hiding this comment.
✅ 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 e5a489c. Configure here.
Handwritten 1-3 sentence description
Details
TLDR
Problem this solves:
top_logprobsongemini/models returned a 400 unlessdrop_paramshid the problem/v1/responseswithtop_logprobsbuilt a Gemini body withlogprobsbut noresponseLogprobs, which Gemini and Vertex both reject with their own 400How it solves it:
top_logprobstoGoogleAIStudioGeminiConfig.get_supported_openai_paramsVertexGeminiConfig.map_openai_paramssetsresponseLogprobs: truewhen it mapstop_logprobs/v1/chat/completionsand/v1/responsesassertgenerationConfig.logprobsandgenerationConfig.responseLogprobson the wire, plus unit tests for both param combinationsUser Flow
Before: a developer asking Gemini for per-token alternatives gets an error instead of logprobs
gemini/gemini-3.8-flashwith"logprobs": true, "top_logprobs": 3litellm.UnsupportedParamsError: gemini does not support parameters: ['top_logprobs']vertex_ai/gemini-2.5-flashwith"top_logprobs": 3and get Vertex's 400logprobs is not supported without setting response_logprobs to be trueAfter: the same requests reach Gemini with the logprob count and the response_logprobs flag
generationConfig.responseLogprobs: trueandgenerationConfig.logprobs: 3, and Gemini answers for the model (on the test key every Google AI Studio model answers 400Logprobs is not enabled for this model, which is Google's model gating and the same answerlogprobs: truealone gets on main)/v1/responsesrequest onvertex_ai/gemini-2.5-flashreturns 200 with the model's textCaveats
The Responses API bridge does not copy chat
logprobsintooutput_text.logprobs, so a/v1/responsescall withtop_logprobsnow succeeds but the response carries no logprobs. That is pre-existing on Vertex and out of scope hereNone of the Google AI Studio models available to the QA key have logprobs enabled, so the live Google AI Studio legs stop at Gemini's own
Logprobs is not enabled for this model400. The Vertex legs ongemini-2.5-flashprove the shared mapping end to endScreenshots / Proof of Fix
Two live proxies from worktrees, no database, real Google AI Studio and Vertex AI calls. Base
6aa546303eon :4821, heade5a489ca31on :4822 (restarted from that commit after the LIT011 marker landed, legs rerun)Config for both
Before (6aa5463, :4821)
After (e5a489c, :4822)
Tests at e5a489c (the only change since ffb199d is a
# rebind-okmarker, the unit and integration selections above were run on the ffb199d tree)Mutation: removing
optional_params["responseLogprobs"] = Truemakestest_top_logprobs_alone_enables_response_logprobsand the Responses integration case fail, removing"top_logprobs"from the supported list makes both integration cases andtest_top_logprobs_maps_to_generation_config_logprobsfail/live-pr-risk pass at e5a489c: dependents of
map_openai_paramsare the Vertex and Google AI Studio chat and Responses paths above, A/B'd live at base and head with real providers, no regression on the chat path, Responses path goes from a provider 400 to 200Type
🐛 Bug Fix
Link to Devin session: https://app.devin.ai/sessions/09cdd950360c40bfa37dbf9e3bd4d9c8
Open in Devin Desktop: https://app.devin.ai/desktop/session/09cdd950360c40bfa37dbf9e3bd4d9c8?variant=devin
Requested by: @mateo-berri
Note
Low Risk
Narrow request-parameter translation for Gemini logprobs with regression tests; no auth, billing, or data-path changes beyond fixing provider request shape.
Overview
Fixes
top_logprobsbeing rejected ongemini/...routes and fixes GeminigenerationConfigwhen onlytop_logprobsis sent (notably/v1/responses).Google AI Studio now lists
top_logprobsinget_supported_openai_params, so LiteLLM no longer raisesUnsupportedParamsErrorbefore the existing Vertex/Gemini param mapper runs.The shared
VertexGeminiConfig.map_openai_paramspath still mapstop_logprobs→generationConfig.logprobs, and now also setsresponseLogprobs: truewhenevertop_logprobsis present, matching Gemini’s requirement that the logprob count not be sent without enabling response logprobs.Unit tests cover both
logprobs+top_logprobsandtop_logprobsalone; integration translation tests assert the outgoinggenerationConfigfor chat completions and Responses.Reviewed by Cursor Bugbot for commit e5a489c. Bugbot is set up for automated code reviews on this repo. Configure here.