Skip to content

fix(responses): backport #50968 and #51038 to lts/1.108.x - #51122

Merged
yucheng-berri merged 3 commits into
lts/1.108.xfrom
litellm_backport_50968_51038_lts_1_108_x
Nov 11, 2026
Merged

yucheng-berri merged 3 commits into
lts/1.108.xfrom
litellm_backport_50968_51038_lts_1_108_x

Conversation

@kerry-berri

@kerry-berri kerry-berri commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • gpt-5.4/5.5 function-tool calls with no reasoning_effort were bridged to /v1/responses on the LTS line
  • Vertex Gemini image edits were billed a flat per-image price, not by tokens

How it solves it:

Backport matrix:

User Flow

Before: an app calling gpt-5.4-mini with a function tool and no reasoning_effort through the LTS proxy lands on the Responses API, and a Vertex image edit shows zero token usage

  1. They send POST https://litellm-domain/v1/chat/completions with "model": "gpt-5.4-mini", one function tool, no reasoning_effort
  2. The reply comes back with a resp_... id, the upstream call went to https://api.openai.com/v1/responses
  3. They send POST https://litellm-domain/v1/images/edits with "model": "vertex-image" and a PNG
  4. The reply has usage.input_tokens: 0, usage.output_tokens: 0, and SpendLogs shows the flat $0.0672 per image

After: the same tool call stays on Chat Completions and the image edit is billed by its tokens

  1. They send the same POST https://litellm-domain/v1/chat/completions with "model": "gpt-5.4-mini", one function tool, no reasoning_effort
  2. The reply comes back with a chatcmpl-... id and the same tool call, the upstream call went to https://api.openai.com/v1/chat/completions
  3. They send the same POST https://litellm-domain/v1/images/edits
  4. The reply carries usage.input_tokens: 1131 (11 text, 1120 image), usage.output_tokens: 1120, and SpendLogs shows the token-based $0.0677655

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

Two proxies from the LTS worktrees, real OpenAI and real Vertex, no mocks. Before is the line's tip 3ff159742d on port 4191, After is this branch on port 4192, each with two workers (--num_workers 2, no --reload, two Application startup complete lines) sharing one Redis on 6394, each with its own local Postgres for SpendLogs. Upstream URLs are the httpx request lines in each proxy's log. Azure is not in the replay, this box has no AZURE_API_BASE, the source PR covered it. LITELLM_LOCAL_MODEL_COST_MAP=True so each proxy prices from its own tree's map.

python litellm/proxy/proxy_cli.py --config /tmp/proof/config.yaml --port 4191 --num_workers 2 --detailed_debug --use_v2_migration_resolver --log_config /tmp/proof/logging.json  # 4192 for After
config.yaml, logging.json and client
model_list:
  - model_name: gpt-5.4-mini
    litellm_params: {model: openai/gpt-5.4-mini, api_key: os.environ/OPENAI_API_KEY}
  - model_name: gpt-5.5
    litellm_params: {model: openai/gpt-5.5, api_key: os.environ/OPENAI_API_KEY}
  - model_name: gpt-5.6
    litellm_params: {model: openai/gpt-5.6, api_key: os.environ/OPENAI_API_KEY}
  - model_name: gpt-5.4-mini-medium
    litellm_params: {model: openai/gpt-5.4-mini, api_key: os.environ/OPENAI_API_KEY, reasoning_effort: medium}
  - model_name: vertex-image
    litellm_params:
      model: vertex_ai/gemini-3.1-flash-image
      vertex_project: <project>
      vertex_credentials: os.environ/VERTEX_CREDENTIALS
      vertex_location: global
router_settings: {redis_host: 127.0.0.1, redis_port: 6394, num_retries: 0}
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  database_url: os.environ/DATABASE_URL
  proxy_batch_write_at: 1
  coordination_redis: {host: 127.0.0.1, port: 6394}

logging.json turns on httpx INFO only, so the upstream URL is printed per request. The client is the one from #50968 (OpenAI SDK, get_weather function tool, one x-litellm-call-id per request, six cases) followed by the one from #51038 (httpx.post to /v1/images/edits with a 128x128 red square PNG and the prompt "Change the red square to a blue circle on white.").

Every chat request returned 200 with one choice, a get_weather tool call and finish_reason: tool_calls. Only the upstream route, the id and the price changed.

Before (3ff1597)

Chat tool calls

  1. gpt-5.4-mini, no effort -> POST https://api.openai.com/v1/responses, id resp_066cfd5b...
  2. gpt-5.5, no effort -> POST https://api.openai.com/v1/responses, id resp_00d60eed...
  3. gpt-5.6, no effort -> POST https://api.openai.com/v1/responses, id resp_0e2e1539...
  4. gpt-5.4-mini, extra_body effort medium -> POST https://api.openai.com/v1/responses, id resp_088efc19...
  5. gpt-5.4-mini, effort none -> POST https://api.openai.com/v1/chat/completions, id chatcmpl-...
  6. gpt-5.4-mini-medium (deployment effort) -> POST https://api.openai.com/v1/responses, id resp_0e61b113...

Vertex image edit

  1. POST /v1/images/edits -> POST https://aiplatform.googleapis.com/v1/projects/<project>/locations/global/publishers/google/models/gemini-3.1-flash-image:generateContent, 200, one image
  2. usage: {"input_tokens": 0, "output_tokens": 0, ...}, x-litellm-response-cost: 0.0672
  3. SELECT spend, prompt_tokens, completion_tokens FROM "LiteLLM_SpendLogs" -> 0.0672 | 0 | 0

After (c707b26)

Chat tool calls

  1. gpt-5.4-mini, no effort -> POST https://api.openai.com/v1/chat/completions, id chatcmpl-EiuA...
  2. gpt-5.5, no effort -> POST https://api.openai.com/v1/chat/completions, id chatcmpl-EiuA...
  3. gpt-5.6, no effort -> POST https://api.openai.com/v1/responses, id resp_0357f88c...
  4. gpt-5.4-mini, extra_body effort medium -> POST https://api.openai.com/v1/responses, id resp_02bfbfcf...
  5. gpt-5.4-mini, effort none -> POST https://api.openai.com/v1/chat/completions, id chatcmpl-EiuA...
  6. gpt-5.4-mini-medium (deployment effort) -> POST https://api.openai.com/v1/responses, id resp_0296e3b2...

Vertex image edit

  1. Same POST /v1/images/edits -> same Vertex generateContent URL, 200, one image
  2. usage: {"input_tokens": 1131, "input_tokens_details": {"image_tokens": 1120, "text_tokens": 11}, "output_tokens": 1120, "output_tokens_details": {"image_tokens": 1120, "text_tokens": 0}}, x-litellm-response-cost: 0.0677655
  3. SpendLogs -> 0.0677655 | 1131 | 1120, matching 1131 x 0.0000005 + 1120 x 0.00006

Picked tests on the line (tests/unit/responses/test_responses_api_bridge_flag.py, tests/unit/test_main.py, tests/unit/proxy/guardrails/test_deferred_guardrail_logging.py, the anthropic adapters test, the vertex image edit and image cost calculator tests, tests/integration/sdk/test_unset_effort_tool_bridge_wire.py): 1184 passed, 6 failed, and the 6 are count-tokens tests in tests/unit/llms/gemini/test_gemini_common_utils.py that fail the same way on the line's tip before the picks.

Full e2e suite on the tip: https://buildkite.com/litellm/litellm-e2e/builds/855 passed (litellm-e2e at c707b26f69, qa-verdict pass). Its two soft-failed secret manager steps (hashicorp vault, cyberark conjur) soft-fail the same way on the line's own qualification build 850. The image step needed one retry for a uv cache lock timeout in the docker build, which build 850 also hit.

Grype sweep of the line's uv.lock against main's: no lock bumps, every flagged package resolves to the same version on both, so nothing main already clears is open here.

Gauntlet-mini: SURVIVED, 5/5 lenses, 0 confirmed, run 6ef61d39cc46, reviewed 1c85cbb (differs from the tip only by a comment on a noqa). Degraded mode, the five lenses were run sequentially by the session (no Agent tool in Devin). Rejected: a non-integer candidatesTokenCount raises a pydantic ValidationError out of the image-edit transform, identical to main's code and Google types the field as an integer. Strongest dissent: an extra_body.reasoning_effort that is neither a string nor a mapping is ignored and the call stays on chat, the same as main's helper.

Type

🐛 Bug Fix

Caveats (if any)

Low

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

Link to Devin session: https://app.devin.ai/sessions/1e9988398af9458c9f459ea05785a792
Open in Devin Desktop: https://app.devin.ai/desktop/session/1e9988398af9458c9f459ea05785a792?variant=devin
Requested by: @kerry-berri


Note

Medium Risk
Changes production routing for GPT-5 chat completions with tools and billing for Vertex image edits; behavior is test-covered but affects widely used completion and image-edit paths.

Overview
Backports two routing/billing fixes onto the LTS line.

GPT-5 tool + reasoning routing: Function-tool requests with no reasoning_effort no longer auto-bridge to /v1/responses for gpt-5.4/gpt-5.5 (and Azure mini/nano variants marked default_reasoning_effort: "none"). Unset effort only triggers the Responses bridge on GPT-5.6+ when the model map default is not "none". bridge_reasoning_effort resolves effort from top-level reasoning_effort or extra_body.reasoning_effort before responses_api_bridge_check runs.

Vertex Gemini image edit: Image-edit responses now parse usageMetadata into ImageResponse.usage (shared Gemini transform, with Pydantic validation) and surface traffic_type in hidden_params, enabling token-based cost instead of a flat per-image fee.

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

…letions (#50968)

Backport of #50968 to lts/1.108.x.
Cherry-picked from d47c031 (main).

Line adaptation: the line has no bridge_reasoning_effort helper or deployment-pinned
routing mode, so the bridge-flag tests pass the effort directly and skip the mode pin.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Backport of #51038 to lts/1.108.x.
Cherry-picked from 53e1e9b (main).

Line adaptation: the line has no map_vertex_image_size or the Gemini image-size tests, so only
the usage test and the token-usage response path come across.

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

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ kerry-berri
❌ devin-ai-integration[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@veria-ai

veria-ai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@codecov

codecov Bot commented Nov 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kerry-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no outstanding findings

Summary

Backports the tool-routing and Vertex image-edit billing fixes to the LTS branch

  • GPT-5 tool calls use the endpoint that matches their reasoning effort.
  • Vertex Gemini image edits include the usage needed for token-based costs.

Reviews (3) · Last reviewed commit: "fix(responses): read reasoning_effort fr..." · Reviewed by Greptile

Comment thread litellm/main.py Resolved
Comment thread litellm/responses/bridge_check.py Resolved
Comment thread litellm/main.py Resolved

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

…gate

Minimal prerequisite for #50968 on lts/1.108.x: the bridge_reasoning_effort and
str_keyed_mapping helpers from 897dda7 (#46263, main), so a reasoning_effort sent
in extra_body still bridges gpt-5.4+ function-tool calls now that an unset effort
stays on chat completions.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the litellm_backport_50968_51038_lts_1_108_x branch from 1c85cbb to c707b26 Compare November 11, 2026 04:23
@kerry-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@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 c707b26. Configure here.

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri
yucheng-berri merged commit 49d9a3f into lts/1.108.x Nov 11, 2026
62 of 65 checks passed
@yucheng-berri
yucheng-berri deleted the litellm_backport_50968_51038_lts_1_108_x branch November 11, 2026 18:28
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.

3 participants