Repository navigation
fix(responses): backport #50968 and #51038 to lts/1.108.x - #51122
Conversation
…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>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
bugbot run |
[Medium impact] The PR appears safe to merge, with no outstanding findings SummaryBackports the tool-routing and Vertex image-edit billing fixes to the LTS branch
Reviews (3) · Last reviewed commit: "fix(responses): read reasoning_effort fr..." · Reviewed by Greptile |
…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>
1c85cbb to
c707b26
Compare
|
bugbot run |
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 c707b26. Configure here.
TLDR
Problem this solves:
How it solves it:
bridge_reasoning_effortfrom fix(router)!: stop a chat-mode Mantle deployment from rewriting the shared Responses routing row #46263 so areasoning_effortsent inextra_bodystill bridgesBackport matrix:
bridge_check.pyresolved as main has it,modelkept where main usesgpt_series_name(the line has no Mantle series split), bridge-flag tests pass the effort directly since the line has no deployment-pinned routing mode, the line's own streamed reasoning test moved toazure/gpt-5.6like the other tests in its group_map_size_to_aspect_ratiokept (nomap_vertex_image_sizehere), only the usage test portedstr_keyed_mappingandbridge_reasoning_effortfrom fix(router)!: stop a chat-mode Mantle deployment from rewriting the shared Responses routing row #46263, its own commit, so a request withextra_body.reasoning_efforton gpt-5.4-mini does not fall to chat and 400User 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
"model": "gpt-5.4-mini", one function tool, noreasoning_effortresp_...id, the upstream call went to https://api.openai.com/v1/responses"model": "vertex-image"and a PNGusage.input_tokens: 0,usage.output_tokens: 0, and SpendLogs shows the flat $0.0672 per imageAfter: the same tool call stays on Chat Completions and the image edit is billed by its tokens
"model": "gpt-5.4-mini", one function tool, noreasoning_effortchatcmpl-...id and the same tool call, the upstream call went to https://api.openai.com/v1/chat/completionsusage.input_tokens: 1131(11 text, 1120 image),usage.output_tokens: 1120, and SpendLogs shows the token-based $0.0677655Pre-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 moreScreenshots / Proof of Fix
Two proxies from the LTS worktrees, real OpenAI and real Vertex, no mocks. Before is the line's tip
3ff159742don port 4191, After is this branch on port 4192, each with two workers (--num_workers 2, no--reload, twoApplication startup completelines) sharing one Redis on 6394, each with its own local Postgres for SpendLogs. Upstream URLs are thehttpxrequest lines in each proxy's log. Azure is not in the replay, this box has noAZURE_API_BASE, the source PR covered it.LITELLM_LOCAL_MODEL_COST_MAP=Trueso 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 Afterconfig.yaml, logging.json and client
logging.jsonturns onhttpxINFO only, so the upstream URL is printed per request. The client is the one from #50968 (OpenAI SDK,get_weatherfunction tool, onex-litellm-call-idper request, six cases) followed by the one from #51038 (httpx.postto/v1/images/editswith 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_weathertool call andfinish_reason: tool_calls. Only the upstream route, the id and the price changed.Before (3ff1597)
Chat tool calls
POST https://api.openai.com/v1/responses, idresp_066cfd5b...POST https://api.openai.com/v1/responses, idresp_00d60eed...POST https://api.openai.com/v1/responses, idresp_0e2e1539...extra_bodyeffort medium ->POST https://api.openai.com/v1/responses, idresp_088efc19...POST https://api.openai.com/v1/chat/completions, idchatcmpl-...POST https://api.openai.com/v1/responses, idresp_0e61b113...Vertex image edit
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 imageusage: {"input_tokens": 0, "output_tokens": 0, ...},x-litellm-response-cost: 0.0672SELECT spend, prompt_tokens, completion_tokens FROM "LiteLLM_SpendLogs"->0.0672 | 0 | 0After (c707b26)
Chat tool calls
POST https://api.openai.com/v1/chat/completions, idchatcmpl-EiuA...POST https://api.openai.com/v1/chat/completions, idchatcmpl-EiuA...POST https://api.openai.com/v1/responses, idresp_0357f88c...extra_bodyeffort medium ->POST https://api.openai.com/v1/responses, idresp_02bfbfcf...POST https://api.openai.com/v1/chat/completions, idchatcmpl-EiuA...POST https://api.openai.com/v1/responses, idresp_0296e3b2...Vertex image edit
POST /v1/images/edits-> same VertexgenerateContentURL, 200, one imageusage: {"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.06776550.0677655 | 1131 | 1120, matching 1131 x 0.0000005 + 1120 x 0.00006Picked 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 intests/unit/llms/gemini/test_gemini_common_utils.pythat 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.lockagainst 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-integercandidatesTokenCountraises a pydanticValidationErrorout of the image-edit transform, identical to main's code and Google types the field as an integer. Strongest dissent: anextra_body.reasoning_effortthat 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
core-utilsis red on threetest_duration_parser.pycases withNo time zone found with key US/Eastern, the same red as the previous LTS PR test: backport stale integration test fixes to lts/1.108.x #51064 on the line, a runner image tzdata gap and nothing the picks touchtests/unit/llms/gemini/test_gemini_common_utils.pyhas 6 count-tokens reds on the line's tip before and after the picks, not touched herebridge_reasoning_effortis a slice of fix(router)!: stop a chat-mode Mantle deployment from rewriting the shared Responses routing row #46263, the rest of that PR (Mantle pinned routing) stays off the lineFinal Attestation
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_effortno longer auto-bridge to/v1/responsesforgpt-5.4/gpt-5.5(and Azure mini/nano variants markeddefault_reasoning_effort: "none"). Unset effort only triggers the Responses bridge on GPT-5.6+ when the model map default is not"none".bridge_reasoning_effortresolves effort from top-levelreasoning_effortorextra_body.reasoning_effortbeforeresponses_api_bridge_checkruns.Vertex Gemini image edit: Image-edit responses now parse
usageMetadataintoImageResponse.usage(shared Gemini transform, with Pydantic validation) and surfacetraffic_typeinhidden_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.