Repository navigation
fix(vertex_ai): answer a clear 400 for n > 1 with image modalities on Gemini chat to lts/1.108.x - #53752
Conversation
(cherry picked from commit 291ed52)
…_gemini_image_n_rejection_lts # Conflicts: # litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py # tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py
…r only on the n error Pick of the main fix onto lts/1.108.x. A Vertex batch row with n > 1 and image modalities is forwarded again, so Vertex fails only that row instead of the upload refusing the whole file. The Gemini configs no longer override custom_llm_provider, so only the n error carries the provider name.
…_gemini_image_n_rejection_lts # Conflicts: # litellm/llms/vertex_ai/files/transformation.py
PR overviewNo security issues were found in this pull request. Reviews
|
surlymochan
left a comment
There was a problem hiding this comment.
Verified the mechanics against the code. drops_unsupported_params (core_helpers.py:412) is true when the global litellm.drop_params is true or the per-call value normalises to true, so the drop path works for both global and per-request flags. The guard runs on the typed request params before the parameter loop, so modalities is still present when it is checked, and the allow_unsupported_n=True bypass in the files transformation is deliberate — the batch-row test pins candidate_count=2 being preserved there.
One nit: the guard only fires for isinstance(n, int). A non-int n (e.g. n=2.0, or "2" arriving from a proxy JSON body) bypasses the 400 and is forwarded as candidate_count, where Gemini rejects it upstream instead of here. Same for modalities given as a bare string "image" rather than a list. Worth coercing or noting, but not blocking.
[Medium impact] This PR appears safe to merge
|
|
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 bce9301. Configure here.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Handwritten 1-3 sentence description
On the 1.108 LTS line, asking a Vertex Gemini image model for more than one answer while also setting modalities fails with Google's vague "Request contains an invalid argument." error. This brings main's fix for it to the line, so the proxy turns that request down with a 400 that says what to change, or drops the extra answers when drop_params is on
Details
TLDR
Problem this solves:
n > 1withmodalitieswith only "Request contains an invalid argument.", on/v1/chat/completionsand/v1/responsesHow it solves it:
n > 1with "image" inmodalitiesanswers a 400 namingndrop_paramsdropsnwith one warningn, so Vertex fails only that rownas beforeBackport checklist
nuploading and name the provider only on thenerror. The line gets the first two as one commit, c52feeb, and the other two as 3ca89df and a9ec78b, as the table below listsallowed_openai_paramsinto the Gemini param mapping (mapper, Gemini call), so main'sallowed_openai_params: ["n"]branch and its test row are left out.drop_params, so the line runs main's batch test for all threeenterprise/orlitellm-proxy-extras/change, so no package bumpc70e97ccd5c52feeb27abcbacc0997c52feeb27a291ed5279f3ca89dfd224f83f3978fa9ec78b091User Flow
Before: a developer asking a Vertex Gemini image model for two images in one request gets a vague 400
vertex_ai/gemini-3.1-flash-image,"modalities": ["image", "text"]and"n": 2nAfter: the same request gets a 400 that names
n, or one image underdrop_paramsnand how to fix it"drop_params": trueit returns 200 with one image, on/v1/responsestoomodalities,"n": 2still returns two imagesRelevant issues
Part of #53119
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<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 moreDelays 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
Two proxies ran from the same config, each with 2 uvicorn workers and its own Postgres DB. Before is lts/1.108.x at 9fca077 and After is bce9301. Every request hit real Vertex AI or Google AI Studio. Raw output is in this gist, files 27 to 29
Last updated: bce9301
Shared setup (config, env var names, start command)
Env vars:
VERTEXAI_PROJECT,GOOGLE_APPLICATION_CREDENTIALS,GEMINI_API_KEY,LITELLM_MASTER_KEY,DATABASE_URLEvery case is one curl, printed by the shell from the same string it ran
ndrop_paramsndrop_paramsndrop_paramsndrop_params, streamnallowed_openai_params: ["n"]nndrop_paramsresponse.failednnallowed_openai_params: ["n"],drop_paramsCases with the same answer on both sides
drop_paramsCase 13 is the one place the line differs from main. The line never passes
allowed_openai_paramsto this mapping, so that request gets the clear 400 here, where main forwardsnand Vertex answers its vague 400A Vertex batch file with an
n=2image row uploads on both sides, so the line keeps sending that row to Vertex, which fails only that row (file 29)Before (9fca077)
All 22 cases, Before
After (bce9301)
All 22 cases, After
Type
🐛 Bug Fix
Caveats (if any)
Medium
n > 1requests still get a provider 400 that never namesn, as on basemodalitiesongemini-2.5-flash-image(case 20) or AI Studio, even withdrop_params(case 21)gemini-3.8-flash-tts(file 36, run on fix(vertex_ai): answer a clear 400 for n > 1 with image modalities on Gemini chat #53598)candidateCount2 (case 22)Low
nerror's advice fails on a text model asked for imagesgemini-3-flash-previewrejects image output even withn=1nsent as"2"or2.0, or rawresponseModalities, skips the checkrouter_code_coveragefails in the code-quality scripts on lts/1.108.x at 4bf8330 too, so that red is inheritedDecisions
The check reads the request, not the model map. Without
modalities,gemini-3.1-flash-imagereturns two images for"n": 2(case 11) whilegemini-2.5-flash-imagerefuses it (case 20), yet the map'sgemini/rows list image output for both. A map rule like #53201's would break case 11, so the refusals withoutmodalities, AI Studio's included (case 21), stay with the providerAudio stays out of the check.
gemini-2.5-flash-preview-ttsreturns two audio answers for"n": 2whilegemini-3.8-flash-ttsfails, so a rule on audio alone would break a working request (file 36)We rejected dropping
responseModalities, which ignores the caller'smodalities, and fanningnout, which multiplies cost unaskedallowed_openai_params: ["n"]wins overdrop_params, the same order this file uses for logprobsBatch rows with
n > 1still upload, since Vertex fails only that rowFinal Attestation
Bugbot summary