Repository navigation
fix(hosted_vllm,azure): leave the caller's messages untouched when building the chat request on lts/1.108.x (#51841) - #53972
Conversation
…ilding the chat request hosted_vllm and Azure rewrote the caller's nested message objects while building the request, so a Router fallback reused the rewritten parts. A video file part reached a Gemini fallback as video_url, which Gemini drops. Both now build new message dicts and content parts and send the same request body as before (cherry picked from commit db6d0d8)
(cherry picked from commit fb548ad)
(cherry picked from commit f4cfe99)
PR overviewNo security issues were found in this pull request. Reviews
|
[Medium impact] The PR appears safe to merge, with the previous live-provider proof requirement addressed
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
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 2442f28. Configure here.
Handwritten 1-3 sentence description
This brings #51841 to lts/1.108.x. hosted vLLM and Azure chat calls now build their own copies instead of editing the caller's messages, so a fallback or an app that reuses its history sends what the caller wrote, and each provider still gets the same request. On this line the video fallbacks #51841 fixed on main already work, and the visible fix is that a repeated Azure image request now hits the response cache
Details
TLDR
Problem this solves:
image_url,file, andfunction_callpartsfilepart and assistant turnsHow it solves it:
litellm/lines as mainThe first pick is clean. The test picks add the imports the line's test files lack and drop
import asyncioonce the async test is goneUser Flow
Before: a developer who asks an Azure model about the same image twice pays for every call, even with the proxy's response cache on
cache: truewith a local cache for the Azure modelazure-imageimage_urlgiven as a plain data URL stringidand its ownx-litellm-response-cost, so Azure ran and billed all threeAfter: the repeats come back from the cache
cache: truewith a local cache for the Azure modelazure-imageimage_urlgiven as a plain data URL stringidand anx-litellm-cache-keyheader, in about 10 msRelevant issues
LTS twin of #51841
Pre-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 moreDelays 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
Before is the line tip and merge base
703ff66da9, and After is the branch tip2442f28a95. The line moved on toa90ec12cb4after these runs, but its new commits touch other functions and merge cleanlyfunction_call.arguments, to gpt-4.1-miniformat, Azure down to GeminiThe video rows already pass on this line through other line commits, so here they only check that nothing broke. Both new regression tests fail at
703ff66da9and pass at2442f28a95, 1865 tests in the touched suites pass, andmake checkpassesSetup (both legs)
Configs, start command, bodies, media server, and runners
Env vars are
GEMINI_API_KEY,AZURE_AI_API_BASE,AZURE_AI_API_KEY,OPENAI_API_KEY, andLITELLM_MASTER_KEY. Each leg starts a proxy from its own tree withcd <tree> && PYTHONPATH=<tree> .venv/bin/litellm --config <config> --port <port> --num_workers 2. The cache leg uses--num_workers 1, since each worker keeps its own local cacheconfig_cache.yamlconfig_azure.yaml. Azure points at a closed port, so every Azure call falls backconfig.yaml. vLLM points at a closed port, so every vLLM call falls backbody_cache_azure-image.json, a 32x32 red PNG{"model":"azure-image","max_tokens":20,"messages":[{"role":"user","content":[{"type":"text","text":"What color is this image? Answer in one word."},{"type":"image_url","image_url":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAKElEQVR4nO3NsQ0AAAzCMP5/un0CNkuZ41wybXsHAAAAAAAAAAAAxR4yw/wuPL6QkAAAAABJRU5ErkJggg=="}]}]}body_az_azure-down-legacy.json(the controlbody_az_openai-legacy.jsonswaps in"model":"openai-legacy"){"model":"azure-down-legacy","max_tokens":300,"functions":[{"name":"get_current_city","parameters":{"type":"object","properties":{}}}],"messages":[{"role":"user","content":"What city am I in?"},{"role":"assistant","content":null,"function_call":{"name":"get_current_city","arguments":null}},{"role":"function","name":"get_current_city","content":"Copenhagen"}]}body_az_azure-down-video.json(the control swaps in"model":"gemini-video"). The media server answers the 1 MB Big Buck Bunny clip asapplication/octet-streamat an extensionless URL, so onlyformatsays it is a video{"model":"azure-down-video","max_tokens":300,"messages":[{"role":"user","content":[{"type":"text","text":"Describe the attached video in one sentence. If no video is attached, reply exactly: NO VIDEO ATTACHED"},{"type":"file","file":{"file_id":"http://127.0.0.1:27739/clip","format":"video/mp4"}}]}]}body_url_vllm-video.json(the control swaps in"model":"gemini-video"). The base64 bodies send the same clip as"file_data": "data:video/mp4;base64,..."with the sameformat{"model":"vllm-video","max_tokens":300,"messages":[{"role":"user","content":[{"type":"text","text":"Describe the attached video in one sentence. If no video is attached, reply exactly: NO VIDEO ATTACHED"},{"type":"file","file":{"file_id":"https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4","format":"video/mp4"}}]}]}media_server.py, run aspython media_server.py 27739 clip.mp4run_cases_cache.shThe cache key header value is shown as
<present>belowrun_cases_azure.shrun_cases.shconfig_vllm.yaml. vLLM is a real vLLM 0.29.0 server on CPU serving Qwen3.5-2B, started withdocker run -d -p 127.0.0.1:21871:8000 public.ecr.aws/q9t5s3a7/vllm-cpu-release-repo:v0.29.0 Qwen/Qwen3.5-2B --max-model-len 16384 --limit-mm-per-prompt '{"image":0,"video":0}' --reasoning-parser qwen3 --enable-auto-tool-choice --tool-call-parser qwen3_coder. Both legs use--num_workers 1and the master keysk-local-vllm-qabody_tool_call.json{"model":"vllm-chat","max_tokens":300,"chat_template_kwargs":{"enable_thinking":false},"messages":[{"role":"user","content":"What is the weather in Paris right now? Use the get_weather tool."}],"tools":[{"type":"function","function":{"name":"get_weather","description":"Get the current weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}]}body_tool_use_history.json{"model":"vllm-chat","max_tokens":300,"chat_template_kwargs":{"enable_thinking":false},"messages":[{"role":"user","content":"What is the weather in Paris right now? Use the get_weather tool."},{"role":"assistant","thinking_blocks":[{"type":"thinking","thinking":"I should call get_weather for Paris.","signature":"sig-1"}],"content":[{"type":"text","text":"Let me check the weather in Paris."},{"type":"tool_use","id":"call_paris_1","name":"get_weather","input":{"city":"Paris"}}]},{"role":"tool","tool_call_id":"call_paris_1","content":"{\"city\":\"Paris\",\"temp_c\":14,\"sky\":\"light rain\"}"}],"tools":[{"type":"function","function":{"name":"get_weather","description":"Get the current weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}]}body_tool_calls_history.json{"model":"vllm-chat","max_tokens":300,"chat_template_kwargs":{"enable_thinking":false},"messages":[{"role":"user","content":"What is the weather in Paris right now? Use the get_weather tool."},{"role":"assistant","content":null,"tool_calls":[{"id":"call_paris_2","type":"function","function":{"name":"get_weather","arguments":"{\"city\":\"Paris\"}"}}]},{"role":"tool","tool_call_id":"call_paris_2","content":"{\"city\":\"Paris\",\"temp_c\":14,\"sky\":\"light rain\"}"}],"tools":[{"type":"function","function":{"name":"get_weather","description":"Get the current weather for a city","parameters":{"type":"object","properties":{"city":{"type":"string"}},"required":["city"]}}}]}run_cases_vllm.shBefore (
703ff66da9)Azure image sent 3 times, cache on
zsh run_cases_cache.sh, before half. Three different ids, each billedAzure down, null
function_call.arguments, to gpt-4.1-minizsh run_cases_azure.sh, before half. The fallback answers because Azure's rewrite of the caller's message leaked into it, while a direct call gets OpenAI's 400Fallback 200, direct call 400
Video fallbacks
Azure down to Gemini, then vLLM to Gemini by URL and base64, each with its direct control
Real vLLM, tool calls
zsh run_cases_vllm.sh 20336 23457, before half. All three answer 200A tool call, then history with a `tool_use` content turn carrying `thinking_blocks`, then history with a `tool_calls` turn
After (
2442f28a95)Azure image sent 3 times, cache on
zsh run_cases_cache.sh, after half. Calls 2 and 3 return call 1's id from the cacheAzure down, null
function_call.arguments, to gpt-4.1-minizsh run_cases_azure.sh, after half. The fallback now gets the caller's null and answers like the direct call, see CaveatsFallback 500 with OpenAI's 400 inside, direct call 400
Video fallbacks
Azure down to Gemini, then vLLM to Gemini by URL and base64, each with its direct control
Real vLLM, tool calls
zsh run_cases_vllm.sh 20336 23457, after half. All three answer 200A tool call, then history with a `tool_use` content turn carrying `thinking_blocks`, then history with a `tool_calls` turn
Type
🐛 Bug Fix
Caveats (if any)
Medium
argumentswent from 200 to 500openai/now downloads the caller's video URLfilepartLow
image_urlstring, a file part'sfilename, andcache_controlfactory.py, in unrelated functionsFinal Attestation
Bugbot summary