Skip to content

fix(router): skip declared text-only deployments for image requests on every routing strategy - #48241

Merged
joshua-berri merged 4 commits into
mainfrom
litellm_vision_filter_without_pre_call_checks
Oct 24, 2026
Merged

joshua-berri merged 4 commits into
mainfrom
litellm_vision_filter_without_pre_call_checks

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Image requests in a model group that mixes vision and text-only deployments no longer land on a text-only deployment. The router already knew how to skip deployments declared supports_vision: false, but only when enable_pre_call_checks: true was set, which almost nobody sets, so a latency-routed group with an OpenAI vision model and a Bedrock gpt-oss model kept sending images to gpt-oss and returning its 400. The skip now runs on every routing strategy by default, and chat completion errors now carry x-litellm-model-id so you can tell which deployment failed.

Details

TLDR

Problem this solves:

How it solves it:

  • Filter moved out of _pre_call_checks and runs on every request, right after the pre-call block and before order filtering and strategy selection
  • Same rules: skip only explicit or cost-map supports_vision: false, unknown stays eligible
  • All text-only group keeps every deployment so the provider error still surfaces
  • maybe_get_model_id also reads the chat request metadata the router fills in

User Flow

Before: a user sending an image to a mixed mixed group gets a Bedrock 400 on most tries

  1. Admin runs mixed with openai/gpt-5.6 and bedrock/openai.gpt-oss-120b-1:0 under latency-based-routing, nothing else set
  2. User sends POST http://localhost:4000/v1/chat/completions with an image_url part
  3. Response is 400 This model doesn't support the image content block with no x-litellm-model-id header
  4. Retrying sometimes returns 200 from the OpenAI deployment, so the user sees it as flaky

After: the same request always reaches the vision deployment

  1. Admin runs the same config
  2. User sends the same POST http://localhost:4000/v1/chat/completions with an image_url part
  3. Response is 200 every time and x-litellm-model-id names the OpenAI deployment, the same on POST /v1/responses with input_image
  4. A plain text request still lands on either deployment

Linear ticket

Resolves LIT-9792

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

Screenshots / Proof of Fix

Live proxy, real OpenAI and Bedrock calls, no mocks. Config used for both runs:

model_list:
  - model_name: mixed
    litellm_params:
      model: openai/gpt-5.6
      api_key: os.environ/OPENAI_API_KEY
    model_info:
      id: oai-vision
  - model_name: mixed
    litellm_params:
      model: bedrock/openai.gpt-oss-120b-1:0
      aws_region_name: us-east-1
    model_info:
      id: bedrock-gpt-oss

router_settings:
  routing_strategy: latency-based-routing

Each case loops the same curl and prints the status line, the x-litellm-model-id header and the first line of the body:

for i in 1 2 3; do
  curl -s -D - -o body.json localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
    -d '{"model":"mixed","messages":[{"role":"user","content":[{"type":"text","text":"What color is this image? One word."},{"type":"image_url","image_url":{"url":"'"$IMG"'"}}]}]}' \
    | grep -i "^HTTP\|x-litellm-model-id"; head -c 110 body.json
done

Before (e6a32bb)

Chat completions with image_url

  1. Three image requests
  2. Output
HTTP/1.1 400 Bad Request
    litellm.BadRequestError: BedrockException - {"message":"This model doesn't support the image content block tha
HTTP/1.1 200 OK x-litellm-model-id: oai-vision
    Red
HTTP/1.1 400 Bad Request
    litellm.BadRequestError: BedrockException - {"message":"This model doesn't support the image content block tha

Responses with input_image

  1. Two image requests
  2. Output
HTTP/1.1 400 Bad Request x-litellm-model-id: bedrock-gpt-oss
    litellm.BadRequestError: BedrockException - {"message":"This model doesn't support the image content block tha
HTTP/1.1 400 Bad Request x-litellm-model-id: bedrock-gpt-oss
    litellm.BadRequestError: BedrockException - {"message":"This model doesn't support the image content block tha

Text request

  1. Three text requests
  2. Output
HTTP/1.1 200 OK x-litellm-model-id: bedrock-gpt-oss
HTTP/1.1 200 OK x-litellm-model-id: bedrock-gpt-oss
HTTP/1.1 200 OK x-litellm-model-id: bedrock-gpt-oss

After (a3b0109)

Chat completions with image_url

  1. Three image requests
  2. Output
HTTP/1.1 200 OK x-litellm-model-id: oai-vision
    Coral
HTTP/1.1 200 OK x-litellm-model-id: oai-vision
    Red
HTTP/1.1 200 OK x-litellm-model-id: oai-vision
    Red

Responses with input_image

  1. Two image requests
  2. Output
HTTP/1.1 200 OK x-litellm-model-id: oai-vision
    [{'id': 'rs_047fe30f672ee05d006add2270930887d090d68e2d20935e76', 'summary': [], 'type': 'reasoning', ...
HTTP/1.1 200 OK x-litellm-model-id: oai-vision
    [{'id': 'rs_03c246feab795cb9006add2272415087d0a3b696bff7e503f5', 'summary': [], 'type': 'reasoning', ...

Text request

  1. Three text requests
  2. Output
HTTP/1.1 200 OK x-litellm-model-id: bedrock-gpt-oss
HTTP/1.1 200 OK x-litellm-model-id: bedrock-gpt-oss
HTTP/1.1 200 OK x-litellm-model-id: bedrock-gpt-oss

Chat completions with image_url while the vision deployment is in cooldown

Same config with api_key: sk-not-a-real-key on the OpenAI deployment, so its 401 puts it in cooldown and the image has to land on the text-only deployment. Before, the three Bedrock 400s came back with no x-litellm-model-id

HTTP/1.1 400 Bad Request
    litellm.BadRequestError: BedrockException - {"message":"This model doesn't support the image content
HTTP/1.1 400 Bad Request
    litellm.BadRequestError: BedrockException - {"message":"This model doesn't support the image content
HTTP/1.1 400 Bad Request
    litellm.BadRequestError: BedrockException - {"message":"This model doesn't support the image content

After, the same 400 names the deployment that failed

HTTP/1.1 400 Bad Request x-litellm-model-id: bedrock-gpt-oss
    litellm.BadRequestError: BedrockException - {"message":"This model doesn't support the image content block that you provided. Update the con
HTTP/1.1 400 Bad Request x-litellm-model-id: bedrock-gpt-oss
    litellm.BadRequestError: BedrockException - {"message":"This model doesn't support the image content block that you provided. Update the con
HTTP/1.1 400 Bad Request x-litellm-model-id: bedrock-gpt-oss
    litellm.BadRequestError: BedrockException - {"message":"This model doesn't support the image content block that you provided. Update the con

This cooldown case is why the filter runs late, on the candidates that survived the cooldown, blocked and pre-call filters, rather than inside _common_checks_available_deployment. An earlier revision ran it before them and this request returned 429 No deployments available instead. For the same reason it also runs after _pre_call_checks, so with enable_pre_call_checks: true a context-window rejection of the last vision leg still leaves the text legs as candidates (test_router_sends_an_image_to_the_text_only_leg_when_pre_call_checks_drop_the_vision_leg, which raises ContextWindowExceededError when the filter runs earlier)

Mutation check: removing both _without_declared_text_only_deployments calls from get_available_deployment and async_get_available_deployment turns test_router_picks_the_vision_leg_for_image_requests_without_enable_pre_call_checks and test_async_router_picks_the_vision_leg_for_responses_images_without_enable_pre_call_checks red

Type

🐛 Bug Fix

Caveats (if any)

Low

  • Unknown vision capability stays eligible by design, declare supports_vision: false on custom text-only deployments
  • No latency penalty or cooldown for provider 400s, a malformed request would punish healthy deployments

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

Note

Medium Risk
Changes default router candidate selection on every request; behavior is well-tested but affects core load-balancing for vision vs text-only deployments.

Overview
Image requests in mixed model groups now avoid deployments explicitly marked text-only (supports_vision: false) on every routing strategy, not only when enable_pre_call_checks is enabled. Filtering moved out of _pre_call_checks into _without_declared_text_only_deployments, which runs after cooldown/blocking/pre-call pruning and before order/strategy selection in both sync and async deployment pickers. If every leg is text-only, all candidates stay so provider errors still surface; when the vision leg is excluded by pre-call checks or cooldown, images can still route to a text-only deployment.

Proxy error responses can expose the chosen deployment id more reliably via maybe_get_model_id, which now falls back through a small _metadata_model_id helper on litellm_metadata and caller metadata (including in-place router updates), improving x-litellm-model-id on failures such as chat completions.

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

joshua-berri and others added 2 commits October 24, 2026 20:38
…ithout enable_pre_call_checks

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…led vision leg falls back to the text leg

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@joshua-berri

Copy link
Copy Markdown
Contributor

@greptileai review

@joshua-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.

Stale Bugbot comment from a previous run.

@greptile-apps

greptile-apps Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the remaining numbered finding addressed

Summary

Image requests now skip declared text-only deployments after pre-call checks in both routing paths. Error responses can also read the deployment ID from chat request metadata. The latest changes add Final annotations to the tests, addressing the remaining numbered finding. No new actionable issues were found

  • Image requests skip declared text-only deployments when another candidate remains.
  • Proxy errors can show the selected deployment ID from request metadata.

Reviews (3) · Last reviewed commit: "test(router): mark the remaining locals ..." · Reviewed by Greptile

Comment thread litellm/router.py Resolved
Comment thread tests/unit/test_router/test_router.py Resolved
@codspeed

codspeed Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 35 untouched benchmarks


Comparing litellm_vision_filter_without_pre_call_checks (891ae74) with main (5603724)

Open in CodSpeed

@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/router.py 69.23% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

…he new tests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@joshua-berri

Copy link
Copy Markdown
Contributor

@greptileai review

@joshua-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.

Stale Bugbot comment from a previous run.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@joshua-berri

Copy link
Copy Markdown
Contributor

@greptileai re-review please

@joshua-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 891ae74. Configure here.

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.

2 participants