Repository navigation
fix(vertex_ai): answer a clear 400 for n > 1 with image modalities on Gemini chat - #53598
Merged
mateo-berri merged 6 commits intoNov 23, 2026
Merged
Conversation
Contributor
Contributor
Contributor
[Medium impact] The PR appears safe to merge, with no new actionable issues found.
|
…r only on the n error 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, and drop_params on the row still drops n. The Gemini configs no longer override custom_llm_provider, so other param errors keep their old shape and only the n error carries the provider name.
…_image_n_rejection # Conflicts: # tests/unit/llms/vertex_ai/files/test_vertex_ai_files_transformation.py
Contributor
10 of 12 tasks
Contributor
Contributor
|
bugbot run |
Contributor
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 667e857. Configure here.
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.
Handwritten 1-3 sentence description
Asking a Vertex Gemini image model for more than one answer with modalities set used to fail with Google's vague "Request contains an invalid argument." error. Now the proxy rejects it with a 400 that says what to change, or drops the extra answers under drop_params. Several images without modalities still work like before
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_paramsdropsnallowed_openai_params: ["n"]still forwardsnas sentn, so Vertex fails only that rownas beforeUser 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
Fixes #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, same config, 2 uvicorn workers and a Postgres DB each, called real Vertex AI and Google AI Studio. Before is merge base 3e7961b, After is 667e857, and full output is in this gist's files 21 and 30 to 36
Last updated: 667e857
Shared setup (config, env var names, start command)
Env vars:
VERTEXAI_PROJECT,GOOGLE_APPLICATION_CREDENTIALS,GEMINI_API_KEY,LITELLM_MASTER_KEY,DATABASE_URL, plusWIRE_VERTEXandWIRE_GEMINI, the recorders in front of Vertex AI and AI StudioEvery case is one curl, printed by the shell from the same string it ran
ndrop_paramsndrop_paramsndrop_paramsndrop_params["image"]only, n=2nndrop_paramsresponse.failedn["text", "image"], n=2nCases with the same answer on both sides
allowed_openai_params: ["n"]allowed_openai_params: ["n"]anddrop_paramsdrop_paramsA Vertex batch with an
n=2image row uploads on both sides and fails only that row, and underdrop_paramsAfter runs both rows. The jobs ran on uploads identical to this tip's (file 32)Before (3e7961b)
All 22 cases, Before
After (667e857)
All 22 cases, After
/live-pr-risk at 667e857
No supported request shape regresses. Every base and head difference is the
ncheck this PR addsBase 3e7961b and head 667e857 each ran 2 uvicorn workers on their own Postgres DB with the config above. Recorders sat in front of the real Vertex AI and Google AI Studio endpoints, so every cell's outbound request was diffed between base and head. Spend rows,
/metricsand a live Vertex batch job were read on both sides (files 32 and 33)Breaking
None on a supported request shape
Backward incompatible
n > 1with "image" inmodalitiesnow fails before any provider call withUnsupportedParamsError, where base sent it and relayed Vertex'sBadRequestErrornUnsupportedParamsErrorwith providervertex_aiorgemini, 0 tokens and noapi_basedrop_paramsdeployment now answers 200 with one image, where base failed on both deployments, so/metricscounts a successful fallback instead of a failed onegeminias its provider, where base namedvertex_ai_betaRegression risk
nsent as"2"or2.0with image modalities still gets Vertex's vague 400 on both sides, since the check reads only an integermp3, read the same on both sides, provider label includedDependency graph
/v1/responsesdrop_params/metrics/v1/files,/v1/batchesvertex_ai_beta/v1beta/v1/images/generations/v1/messagesThe integration lanes ran at 667e857 (file 35). SDK passed 27 of 27, accounting 6 of 6 and providers 1,035 of 1,037. The 2 provider reds are fault tests that time out the same way on main at 3e7961b
Not verified
vertex_ai_betasuccess. Vertex answered 403 "insufficient authentication scopes" to the rig's credential on both sides, so only the pre-callncheck and the request underdrop_paramswere seen (file 34)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)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 checkDecisions
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