Repository navigation
fix(vertex_ai): reject n > 1 for Gemini image models (#53119) - #53201
Closed
Aniketchavan7 wants to merge 1 commit into
Closed
Aniketchavan7 wants to merge 1 commit into
Aniketchavan7 wants to merge 1 commit into
Conversation
Contributor
On Vertex Gemini image models (models with 'image' in supported_output_modalities, such as gemini-3.1-flash-image and gemini-nano-banana-2.1), setting n > 1 forwards candidateCount > 1 to Vertex, which responds with an opaque '400 INVALID_ARGUMENT: Request contains an invalid argument'.
This patch:
- Adds _is_gemini_image_model(model) checking supported_output_modalities in model_cost.
- Rejects n > 1 with a clear BadRequestError: 'n={value} is not supported: Vertex Gemini image models return one image per request; send n=1 or separate requests.' before forwarding to Vertex.
- Adds regression test test_vertex_gemini_image_model_rejects_candidate_count_greater_than_one in test_vertex_and_google_ai_studio_gemini.py.
Aniketchavan7
force-pushed
the
fix/vertex-gemini-image-n-rejection
branch
from
November 22, 2026 14:39
973e54b to
f81ebf1
Compare
This was referenced Nov 23, 2026
Contributor
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 #53119
What changes are being made and why?
On
litellm,VertexGeminiConfig.map_openai_paramsmaps OpenAInto VertexcandidateCountfor all Gemini models. However, Vertex Gemini image models (gemini-3.1-flash-image,gemini-nano-banana-2.1,gemini-2.5-flash-image) rejectcandidateCount > 1with an opaque Vertex error:leaving callers with no indication that
ncaused the failure.Key Changes
_is_gemini_image_model(model):supported_output_modalitiesinlitellm.model_costacross candidates(model, f"{self._route}/{bare}", f"gemini/{bare}", bare).Trueif"image"is among the supported output modalities.VertexGeminiConfig.map_openai_params:param == "n"andvalue > 1for an image model, immediately raises a clearlitellm.BadRequestError:n={value} is not supported: Vertex Gemini image models return one image per request; send n=1 or separate requests.n: 1or standard text Gemini models untouched (optional_params["candidate_count"] = value).test_vertex_gemini_image_model_rejects_candidate_count_greater_than_oneintests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.pyverifying thatn > 1on an image model raisesBadRequestError,n == 1setscandidate_count = 1, andn == 2on text models (gemini-1.5-pro) maps as expected.How was this tested?
gemini-3.1-flash-image,gemini-nano-banana-2.1,gemini-2.5-flash-image(raises 400).n=1on image model (passes).n=2ongemini-1.5-pro(passes, setscandidate_count=2).Co-authored-by: yalongwastaken yalongwastaken@users.noreply.github.com