Skip to content

fix(vertex_ai): answer a clear 400 for n > 1 with image modalities on Gemini chat - #53598

Merged
mateo-berri merged 6 commits into
BerriAI:mainfrom
drewv19:litellm_vertex_gemini_image_n_rejection
Nov 23, 2026
Merged

mateo-berri merged 6 commits into
BerriAI:mainfrom
drewv19:litellm_vertex_gemini_image_n_rejection

Conversation

@drewv19

@drewv19 drewv19 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Vertex image models answer n > 1 with modalities with only "Request contains an invalid argument.", on /v1/chat/completions and /v1/responses

How it solves it:

  • n > 1 with "image" in modalities answers a 400 naming n
  • drop_params drops n
  • allowed_openai_params: ["n"] still forwards n as sent
  • Batch rows keep forwarding n, so Vertex fails only that row
  • Every other request maps n as before

User Flow

Before: a developer asking a Vertex Gemini image model for two images in one request gets a vague 400

  1. They send POST https://litellm-domain/v1/chat/completions with model vertex_ai/gemini-3.1-flash-image, "modalities": ["image", "text"] and "n": 2
  2. Vertex answers 400 "Request contains an invalid argument.", never naming n
  3. POST https://litellm-domain/v1/responses fails the same way

After: the same request gets a 400 that names n, or one image under drop_params

  1. They send the same request
  2. The proxy answers 400 at once, naming n and how to fix it
  3. With "drop_params": true it returns 200 with one image, on /v1/responses too
  4. Without modalities, "n": 2 still returns two images

Relevant issues

Fixes #53119

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays 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)
model_list:
  - model_name: vertex-flash-image
    litellm_params:
      model: vertex_ai/gemini-3.1-flash-image
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
  - model_name: vertex-nano-banana
    litellm_params:
      model: vertex_ai/gemini-nano-banana-2.1
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
  - model_name: studio-flash-image
    litellm_params:
      model: gemini/gemini-3.1-flash-image
      api_key: os.environ/GEMINI_API_KEY
  - model_name: vertex-text
    litellm_params:
      model: vertex_ai/gemini-3-flash-preview
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
  - model_name: wire-vertex-image
    litellm_params:
      model: vertex_ai/gemini-3.1-flash-image
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
      api_base: os.environ/WIRE_VERTEX
  - model_name: wire-vertex-image-drop
    litellm_params:
      model: vertex_ai/gemini-3.1-flash-image
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
      api_base: os.environ/WIRE_VERTEX
      drop_params: true
  - model_name: wire-fallback-image
    litellm_params:
      model: vertex_ai/gemini-3.1-flash-image
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
      api_base: os.environ/WIRE_VERTEX
  - model_name: wire-vertex-text
    litellm_params:
      model: vertex_ai/gemini-3-flash-preview
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
      api_base: os.environ/WIRE_VERTEX
  - model_name: wire-studio-image
    litellm_params:
      model: gemini/gemini-3.1-flash-image
      api_key: os.environ/GEMINI_API_KEY
      api_base: os.environ/WIRE_GEMINI
  - model_name: wire-studio-tts
    litellm_params:
      model: gemini/gemini-3.8-flash-tts
      api_key: os.environ/GEMINI_API_KEY
      api_base: os.environ/WIRE_GEMINI
  - model_name: wire-vertex-tts
    litellm_params:
      model: vertex_ai/gemini-3.8-flash-tts
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
      api_base: os.environ/WIRE_VERTEX
  - model_name: vertex-25-flash-image
    litellm_params:
      model: vertex_ai/gemini-2.5-flash-image
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
litellm_settings:
  callbacks: ["prometheus"]
router_settings:
  disable_cooldowns: true
  fallbacks: [{"wire-fallback-image": ["wire-vertex-image-drop"]}]

Env vars: VERTEXAI_PROJECT, GOOGLE_APPLICATION_CREDENTIALS, GEMINI_API_KEY, LITELLM_MASTER_KEY, DATABASE_URL, plus WIRE_VERTEX and WIRE_GEMINI, the recorders in front of Vertex AI and AI Studio

python litellm/proxy/proxy_cli.py --config config.yaml --host 127.0.0.1 --port <port> --num_workers 2 --use_prisma_db_push

Every case is one curl, printed by the shell from the same string it ran

# Request (chat unless noted) Before (3e7961b) After (667e857)
1 flash-image, image modalities, n=2 vague 400 400 names n
2 same, drop_params vague 400 200, 1 image
3 nano-banana, image modalities, n=2 vague 400 400 names n
4 same, drop_params vague 400 200, 1 image
5 AI Studio flash-image, n=2 400 "Multiple candidates" 400 names n
6 same, drop_params 400 "Multiple candidates" 200, 1 image
7 flash-image, n=2, stream vague 400 400 names n
8 same, drop_params vague 400 200, 1 image
9 modalities ["image"] only, n=2 vague 400 400 names n
15 Responses API, n=2 vague 400 400 names n
16 Responses API, drop_params vague 400 200, 1 image
17 Responses API, n=2, stream 200 then response.failed 400 names n
18 modalities ["text", "image"], n=2 vague 400 400 names n
Cases with the same answer on both sides
# Request Both sides
10 image modalities, n=1 200, 1 image
11 no modalities, n=2 200, 2 images
12 text modalities, n=2 vague 400
13 allowed_openai_params: ["n"] vague 400
14 text model, text modalities, n=2 200, 2 choices
19 allowed_openai_params: ["n"] and drop_params vague 400
20 2.5-flash-image, no modalities, n=2 400 "not supported by this model"
21 AI Studio, no modalities, n=2, drop_params 400 "Multiple candidates"
22 native generateContent, candidateCount 2 vague 400

A Vertex batch with an n=2 image row uploads on both sides and fails only that row, and under drop_params After runs both rows. The jobs ran on uploads identical to this tip's (file 32)

Before (3e7961b)

  1. Two images with image modalities
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2}'
{"error":{"message":"litellm.BadRequestError: Vertex_aiException BadRequestError - {\n  \"error\": {\n    \"code\": 400,\n    \"message\": \"Request contains an invalid argument.\",\n    \"status\": \"INVALID_ARGUMENT\"\n  }\n}\n\n\nLiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400
All 22 cases, Before
== 1. vertex-flash-image, image modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 2. vertex-flash-image, image modalities, n=2, drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "drop_params": true}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 3. vertex-nano-banana, image modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-nano-banana", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-nano-banana' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 4. vertex-nano-banana, image modalities, n=2, drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-nano-banana", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "drop_params": true}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-nano-banana' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 5. studio-flash-image, image modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "studio-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2}'
HTTP 400
error: litellm.BadRequestError: GeminiException BadRequestError - {   "error": {     "code": 400,     "message": "Multiple candidates is not enabled for this model",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'studio-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 6. studio-flash-image, image modalities, n=2, drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "studio-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "drop_params": true}'
HTTP 400
error: litellm.BadRequestError: GeminiException BadRequestError - {   "error": {     "code": 400,     "message": "Multiple candidates is not enabled for this model",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'studio-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 7. vertex-flash-image, image modalities, n=2, stream
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "stream": true}'
HTTP 400
error: litellm.BadRequestError: Vertex_ai_betaException BadRequestError - b'{\n  "error": {\n    "code": 400,\n    "message": "Request contains an invalid argument.",\n    "status": "INVALID_ARGUMENT"\n  }\n}\n'  LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 8. vertex-flash-image, image modalities, n=2, drop_params, stream
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "drop_params": true, "stream": true}'
HTTP 400
error: litellm.BadRequestError: Vertex_ai_betaException BadRequestError - b'{\n  "error": {\n    "code": 400,\n    "message": "Request contains an invalid argument.",\n    "status": "INVALID_ARGUMENT"\n  }\n}\n'  LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 9. vertex-flash-image, modalities [image] before n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "modalities": ["image"], "n": 2, "messages": [{"role": "user", "content": "Draw a red circle"}]}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 10. vertex-flash-image, image modalities, n=1
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 1}'
HTTP 200
choices: 1 | images per choice: [1]
== 11. vertex-flash-image, no modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "n": 2}'
HTTP 200
choices: 2 | images per choice: [1, 1]
== 12. vertex-flash-image, text modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["text"], "n": 2}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 13. vertex-flash-image, image modalities, n=2, allowed_openai_params [n]
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "allowed_openai_params": ["n"]}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 14. vertex-text, text modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-text", "messages": [{"role": "user", "content": "Say hi"}], "modalities": ["text"], "n": 2, "max_tokens": 200}'
HTTP 200
choices: 2 | images per choice: [0, 0]
== 15. Responses API, vertex-flash-image, image modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "input": "Draw a red circle", "modalities": ["image", "text"], "n": 2}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 16. Responses API, vertex-flash-image, image modalities, n=2, drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "input": "Draw a red circle", "modalities": ["image", "text"], "n": 2, "drop_params": true}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 17. Responses API, vertex-flash-image, image modalities, n=2, stream
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "input": "Draw a red circle", "modalities": ["image", "text"], "n": 2, "stream": true}'
HTTP 200
event: response.failed
data: {"type":"response.failed","response":{"id":"resp_1900933660234d3fb854d5ecd3e49c6f","created_at":1795406698,"error":{"code":"invalid_request_error","message":"litellm.BadRequestError: Vertex_ai_betaException BadRequestError - b'{\\n  \"error\": {\\n    \"code\": 400,\\n  
== 18. vertex-flash-image, modalities [text, image], n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["text", "image"], "n": 2}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 19. vertex-flash-image, image modalities, n=2, allowed_openai_params [n], drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "allowed_openai_params": ["n"], "drop_params": true}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 20. vertex-25-flash-image, no modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-25-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "n": 2}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "The request is not supported by this model.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-25-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 21. studio-flash-image, no modalities, n=2, drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "studio-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "n": 2, "drop_params": true}'
HTTP 400
error: litellm.BadRequestError: GeminiException BadRequestError - {   "error": {     "code": 400,     "message": "Multiple candidates is not enabled for this model",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'studio-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 22. vertex-flash-image, native generateContent, candidateCount 2, IMAGE modality
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:30705/v1beta/models/vertex-flash-image:generateContent -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"contents": [{"role": "user", "parts": [{"text": "Draw a red circle"}]}], "generationConfig": {"candidateCount": 2, "responseModalities": ["TEXT", "IMAGE"]}}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.

After (667e857)

  1. Same request
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2}'
{"error":{"message":"litellm.UnsupportedParamsError: n=2 with image output in modalities is not supported for gemini-3.1-flash-image. Gemini returns one candidate per request when modalities asks for image output, so send n=1 or separate requests, or set drop_params to drop n.\n\nLiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"invalid_request_error","param":null,"code":"400"}}
HTTP 400
All 22 cases, After
== 1. vertex-flash-image, image modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2}'
HTTP 400
error: litellm.UnsupportedParamsError: n=2 with image output in modalities is not supported for gemini-3.1-flash-image. Gemini returns one candidate per request when modalities asks for image output, so send n=1 or separate requests, or set drop_params to drop n.  LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 2. vertex-flash-image, image modalities, n=2, drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "drop_params": true}'
HTTP 200
choices: 1 | images per choice: [1]
== 3. vertex-nano-banana, image modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-nano-banana", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2}'
HTTP 400
error: litellm.UnsupportedParamsError: n=2 with image output in modalities is not supported for gemini-nano-banana-2.1. Gemini returns one candidate per request when modalities asks for image output, so send n=1 or separate requests, or set drop_params to drop n.  LiteLLM: model group 'vertex-nano-banana' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 4. vertex-nano-banana, image modalities, n=2, drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-nano-banana", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "drop_params": true}'
HTTP 200
choices: 1 | images per choice: [1]
== 5. studio-flash-image, image modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "studio-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2}'
HTTP 400
error: litellm.UnsupportedParamsError: n=2 with image output in modalities is not supported for gemini-3.1-flash-image. Gemini returns one candidate per request when modalities asks for image output, so send n=1 or separate requests, or set drop_params to drop n.  LiteLLM: model group 'studio-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 6. studio-flash-image, image modalities, n=2, drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "studio-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "drop_params": true}'
HTTP 200
choices: 1 | images per choice: [1]
== 7. vertex-flash-image, image modalities, n=2, stream
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "stream": true}'
HTTP 400
error: litellm.UnsupportedParamsError: n=2 with image output in modalities is not supported for gemini-3.1-flash-image. Gemini returns one candidate per request when modalities asks for image output, so send n=1 or separate requests, or set drop_params to drop n.  LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 8. vertex-flash-image, image modalities, n=2, drop_params, stream
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "drop_params": true, "stream": true}'
HTTP 200
stream: 2 chunks, choice indexes [0], images 1
== 9. vertex-flash-image, modalities [image] before n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "modalities": ["image"], "n": 2, "messages": [{"role": "user", "content": "Draw a red circle"}]}'
HTTP 400
error: litellm.UnsupportedParamsError: n=2 with image output in modalities is not supported for gemini-3.1-flash-image. Gemini returns one candidate per request when modalities asks for image output, so send n=1 or separate requests, or set drop_params to drop n.  LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 10. vertex-flash-image, image modalities, n=1
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 1}'
HTTP 200
choices: 1 | images per choice: [1]
== 11. vertex-flash-image, no modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "n": 2}'
HTTP 200
choices: 2 | images per choice: [1, 1]
== 12. vertex-flash-image, text modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["text"], "n": 2}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 13. vertex-flash-image, image modalities, n=2, allowed_openai_params [n]
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "allowed_openai_params": ["n"]}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 14. vertex-text, text modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-text", "messages": [{"role": "user", "content": "Say hi"}], "modalities": ["text"], "n": 2, "max_tokens": 200}'
HTTP 200
choices: 2 | images per choice: [0, 0]
== 15. Responses API, vertex-flash-image, image modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "input": "Draw a red circle", "modalities": ["image", "text"], "n": 2}'
HTTP 400
error: litellm.UnsupportedParamsError: n=2 with image output in modalities is not supported for gemini-3.1-flash-image. Gemini returns one candidate per request when modalities asks for image output, so send n=1 or separate requests, or set drop_params to drop n.  LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 16. Responses API, vertex-flash-image, image modalities, n=2, drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "input": "Draw a red circle", "modalities": ["image", "text"], "n": 2, "drop_params": true}'
HTTP 200
output types: ['image_generation_call'] | images: 1
== 17. Responses API, vertex-flash-image, image modalities, n=2, stream
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "input": "Draw a red circle", "modalities": ["image", "text"], "n": 2, "stream": true}'
HTTP 400
error: litellm.UnsupportedParamsError: n=2 with image output in modalities is not supported for gemini-3.1-flash-image. Gemini returns one candidate per request when modalities asks for image output, so send n=1 or separate requests, or set drop_params to drop n.  LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 18. vertex-flash-image, modalities [text, image], n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["text", "image"], "n": 2}'
HTTP 400
error: litellm.UnsupportedParamsError: n=2 with image output in modalities is not supported for gemini-3.1-flash-image. Gemini returns one candidate per request when modalities asks for image output, so send n=1 or separate requests, or set drop_params to drop n.  LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 19. vertex-flash-image, image modalities, n=2, allowed_openai_params [n], drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "modalities": ["image", "text"], "n": 2, "allowed_openai_params": ["n"], "drop_params": true}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 20. vertex-25-flash-image, no modalities, n=2
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "vertex-25-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "n": 2}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "The request is not supported by this model.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-25-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 21. studio-flash-image, no modalities, n=2, drop_params
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model": "studio-flash-image", "messages": [{"role": "user", "content": "Draw a red circle"}], "n": 2, "drop_params": true}'
HTTP 400
error: litellm.BadRequestError: GeminiException BadRequestError - {   "error": {     "code": 400,     "message": "Multiple candidates is not enabled for this model",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'studio-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
== 22. vertex-flash-image, native generateContent, candidateCount 2, IMAGE modality
$ curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:24595/v1beta/models/vertex-flash-image:generateContent -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"contents": [{"role": "user", "parts": [{"text": "Draw a red circle"}]}], "generationConfig": {"candidateCount": 2, "responseModalities": ["TEXT", "IMAGE"]}}'
HTTP 400
error: litellm.BadRequestError: Vertex_aiException BadRequestError - {   "error": {     "code": 400,     "message": "Request contains an invalid argument.",     "status": "INVALID_ARGUMENT"   } }   LiteLLM: model group 'vertex-flash-image' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: wire-fallback-image. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.
/live-pr-risk at 667e857

No supported request shape regresses. Every base and head difference is the n check this PR adds

Base 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, /metrics and a live Vertex batch job were read on both sides (files 32 and 33)

Breaking

None on a supported request shape

Backward incompatible

  • n > 1 with "image" in modalities now fails before any provider call with UnsupportedParamsError, where base sent it and relayed Vertex's BadRequestError
    • The client still gets a 400 with the same body shape, and the message now names n
    • The failure spend row logs UnsupportedParamsError with provider vertex_ai or gemini, 0 tokens and no api_base
    • Closed by litellm's drop_params convention
  • A fallback to a drop_params deployment now answers 200 with one image, where base failed on both deployments, so /metrics counts a successful fallback instead of a failed one
  • The AI Studio stream error now names gemini as its provider, where base named vertex_ai_beta

Regression risk

  • n sent as "2" or 2.0 with image modalities still gets Vertex's vague 400 on both sides, since the check reads only an integer
  • Gemini TTS param errors, such as audio format mp3, read the same on both sides, provider label included

Dependency graph

Dependent Entry Status
Vertex chat mapper chat verified live, tested
AI Studio chat mapper chat stream verified live, tested
Responses API bridge /v1/responses verified live
Deployment drop_params chat verified live
Router fallback chat verified live
Spend failure row proxy verified live
Prometheus labels /metrics verified live
Vertex batch rows /v1/files, /v1/batches verified live, tested
vertex_ai_beta SDK verified live up to the call
Gemini TTS chat audio verified live, no diff
Native generateContent /v1beta verified live, no diff
Images API /v1/images/generations verified live, no diff
Anthropic messages /v1/messages verified live, no diff

The 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

  • A vertex_ai_beta success. Vertex answered 403 "insufficient authentication scopes" to the rig's credential on both sides, so only the pre-call n check and the request under drop_params were seen (file 34)
  • The Vertex live passthrough with a param error

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • Some n > 1 requests still get a provider 400 that never names n, as on base
    • No modalities on gemini-2.5-flash-image (case 20) or AI Studio, even with drop_params (case 21)
    • Audio output on gemini-3.8-flash-tts (file 36)
    • Text-only modalities on an image model (case 12)
    • Native generateContent with candidateCount 2 (case 22)
    • Catching these needs a per-model map, filed as a follow-up

Low

Decisions

The check reads the request, not the model map. Without modalities, gemini-3.1-flash-image returns two images for "n": 2 (case 11) while gemini-2.5-flash-image refuses it (case 20), yet the map's gemini/ rows list image output for both. A map rule like #53201's would break case 11, so the refusals without modalities, AI Studio's included (case 21), stay with the provider

Audio stays out of the check. gemini-2.5-flash-preview-tts returns two audio answers for "n": 2 while gemini-3.8-flash-tts fails, so a rule on audio alone would break a working request (file 36)

We rejected dropping responseModalities, which ignores the caller's modalities, and fanning n out, which multiplies cost unasked

allowed_openai_params: ["n"] wins over drop_params, the same order this file uses for logprobs

Batch rows with n > 1 still upload, since Vertex fails only that row

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
Bugbot summary

[!NOTE]
Medium Risk
Changes when and how n is validated for Vertex/Gemini chat requests (pre-call 400 vs forwarded to Google); batch behavior is intentionally exempt via allow_unsupported_n.

Overview
Gemini/Vertex chat and responses now reject n > 1 when modalities includes image, returning a clear UnsupportedParamsError (400) before the provider call instead of Google’s vague invalid-argument error. With drop_params, n is dropped (with a warning) and the request proceeds with a single image candidate; allowed_openai_params: ["n"] still forwards n when explicitly allowed.

Parameter mapping adds gemini_image_candidate_count and an allow_unsupported_n flag on map_openai_params. Vertex batch file uploads pass allow_unsupported_n=True so batch rows can still include candidate_count and fail only at the provider, while interactive chat keeps the early validation.

Unit tests cover chat/responses mapping, drop_params, allowed_openai_params, and batch row transformation.

Reviewed by Cursor Bugbot for commit 667e857. Bugbot is set up for automated code reviews on this repo. Configure here.

@veria-ai

veria-ai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable issues found.

Summary

Gemini requests with image modalities and integer n > 1 now return a clear 400 before contacting the provider. With drop_params, the mapper omits n.

  • Gemini image requests name the unsupported candidate count.
  • Vertex batch rows keep their own image candidate-count choices.

Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

…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
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mateo-berri
mateo-berri merged commit 6a6c90a into BerriAI:main Nov 23, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Vertex Gemini image models: n > 1 on /chat/completions is forwarded as candidateCount and returns an opaque 400 INVALID_ARGUMENT

2 participants