Repository navigation
fix(hosted_vllm,azure): leave the caller's messages untouched when building the chat request - #51841
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
…essages_vllm_mistral_azure # Conflicts: # litellm/llms/hosted_vllm/chat/transformation.py # tests/unit/llms/azure/chat/test_azure_chat_gpt_transformation.py
[Medium impact] The PR appears safe to merge, with no new actionable issues found. Summaryhosted vLLM and Azure now build changed messages and content parts without editing the caller’s history. Provider request shapes stay the same.
Reviews (3) · Last reviewed commit: "test(hosted_vllm): drop the async varian..." · Reviewed by Greptile |
Merging this PR will not alter performance1 warning
Comparing |
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 f4cfe99. Configure here.
fix(hosted_vllm,azure): leave the caller's messages untouched when building the chat request on lts/1.108.x (#51841)
Handwritten 1-3 sentence description
When a self-hosted vLLM model failed and the proxy fell back to Gemini, Gemini got the request vLLM had already rewritten, so it never saw the caller's video and made up an answer. vLLM and Azure now build their own copies instead of editing the caller's messages, so a fallback or an app that reuses its history sends exactly what the caller wrote. What each provider receives is unchanged
Details
TLDR
Problem this solves:
filepart intovideo_urlvideo_url, dropped it, and invented an answerimage_url,file, andfunction_callpartsHow it solves it:
User Flow
Before: a developer whose vision app falls back from a self-hosted vLLM model to Gemini gets an answer about a video Gemini never received
vllm-videoto fall back togemini-videowhen vLLM failsvllm-videowith a text part and afilepart for an mp4 URL withformat: video/mp4x-litellm-attempted-fallbacks: 1After: the fallback answer describes the real clip, the same as a direct call to Gemini
vllm-videoto fall back togemini-videowhen vLLM failsvllm-videowith a text part and afilepart for an mp4 URL withformat: video/mp4x-litellm-attempted-fallbacks: 1gemini-videocallRelevant issues
Supersedes #44977
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 merge base
05518975a5and After is2dea37b8a8. The tipf4cfe9973eadds two tests-only commits, which type the new tests and drop an async variant. The new tests fail on the merge base and pass at the tip./v1/messagesformat, Azure down to Geminifunction_call.arguments, Azure down to gpt-4.1-miniOn the proxy, the Azure change shows when a fallback reads
format, which Azure used to stripSetup (both legs)
Each leg runs a 2-worker proxy from its own tree with the same config, against real Gemini, Anthropic, and Azure. vLLM points at a dead port, so each vLLM call falls back. Each case also sends its body straight to the fallback model as a control
config.yaml
Steps and the curl loop
Env vars are
GEMINI_API_KEY,ANTHROPIC_API_KEY,AZURE_AI_API_BASE,AZURE_AI_API_KEY, andLITELLM_MASTER_KEYapplication/octet-stream:python octet_server.py 22185cd <tree> && PYTHONPATH=<tree> litellm --config config.yaml --port <port> --num_workers 2 --detailed_debug --timeout_worker_healthcheck 60run_cases.shbelow. The Azure cases ran the same curl and printed{model, content: .choices[0].message.content, prompt_tokens: .usage.prompt_tokens}, with the nullfunction_callanderrorfields left out belowRequest bodies and the image server
Video by URL (
body_url_vllm-video.json, and the control swaps in"model":"gemini-video"){"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"}}]}]}Video as base64 is the same request with the file part as
{"file_data": "data:video/mp4;base64,<the same 1 MB clip>", "format": "video/mp4"}Thinking turn (
turn2_vllm-chat.json) is the second turn of aget_weathertool conversation. Turn 1 went straight toclaude-thinkingwith the question "Pick a European capital whose name has as many letters as there are primes below 20, then get its weather. Tell me the weather and why you picked it." and a 16000 token thinking budget, since the config's 1024 budget maps to low effort and Claude skipped thinking. Turn 2 holds that question, the assistant turn with its content as a text part list, its signedthinking_blocks,reasoning_content, and the tool call, and the tool result18C and sunny. vLLM's transform rewrites this assistant turn, so this case checks that the fallback still gets the full historyImage on
/v1/messages{"model": "vllm-video", "max_tokens": 100, "messages": [{"role": "user", "content": [{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": "<64x64 red PNG>"}}, {"type": "text", "text": "What color is this image? Answer in one word."}]}]}Image by URL to Azure. Azure cannot reach the local image server, so it fails and the router falls back to Gemini. The request sets
formatbecause the server answers with octet-stream. Both legs answer Red, so this case only checks that the fallback still works{"model":"azure-image","max_tokens":50,"messages":[{"role":"user","content":[{"type":"text","text":"What color is this image? Answer in one word."},{"type":"image_url","image_url":{"url":"http://127.0.0.1:22185/red","format":"image/png"}}]}]}Azure call that succeeds sends the same four messages as the SDK app below (
body_azure_ok.json, with"model":"azure-image"and theget_current_cityfunction)octet_server.pySDK app (my_app.py), run as
PYTHONPATH=<tree> python my_app.py azureandpython my_app.py vllmreportprintsmessages == snapshotand each changed message, andshortcuts strings over 40 characters.VIDEOis the same mp4 URL as aboveBefore (
05518975a5)Video by URL
Video as base64
Fallback and control output
Thinking turn, image on /v1/messages, Azure to Gemini, Azure call that succeeds
The request body this leg's
--detailed_debuglog shows going to Azure forazure_okis 2042 bytes with sha256863b7e02d2182e36…SDK app
my_app.py azure and my_app.py vllm output
After (
2dea37b8a8)Video by URL
Video as base64
Fallback and control output
Thinking turn, image on /v1/messages, Azure to Gemini, Azure call that succeeds
The request body this leg's
--detailed_debuglog shows going to Azure forazure_okis 2042 bytes with sha256863b7e02d2182e36…, the same bytes as BeforeSDK app
my_app.py azure and my_app.py vllm output
Azure-down legs (Before
05518975a5, Afterf4cfe9973e)config.yaml, bodies, media server, and runner
Azure points at a closed port, so every Azure call fails and the router falls back. The media server answers the 1 MB clip as
application/octet-streamat an extensionless URL, so onlyformatsays it is a video. The direct calls to each fallback model are the controls. gpt-5.4-mini rejects the legacyfunctionrole on both legs, so the null-arguments case also runs against gpt-4.1-minibody_azure-down-video.json(the control swaps in"model":"gemini-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:23417/clip","format":"video/mp4"}}]}]}body_azure-down-legacy.json(azure-down-toolsand the controls swap the model name){"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"}]}media_server.py, run aspython media_server.py 23417 clip.mp4run_cases.shrun_cases.sh output, both legs
Blast radius at
f4cfe9973eWhat else reads the messages, base against head and merged with main
One answer changes beyond the fix. An Azure request with a null legacy
function_call.argumentsthat falls back to a model taking thefunctionrole went from 200 to 500, and the error carries the fallback's own 400. Every other answer is the same or goes from a made-up video to the real clip. The requests litellm sends to vLLM and Azure are byte-identical on both sides. What hooks, guardrails, and the stored spend-log request receive is now the caller's messagesBreaking
function_call.arguments, went from 200 to 500 with OpenAI's "expected a string, but got null" 400 inside, the same 400 a direct gpt-4.1-mini call getsconvert_to_azure_openai_messageswrote""onto the caller's message and the router replayed that edited message to the fallbackopenai/fallback now gets the caller's videofilepart where it used to getvideo_urlBackward incompatible
during_callguardrails, the post-call success hook, and the storedproxy_server_requestinLiteLLM_SpendLogsnow hold the caller's messages for hosted vLLM and Azurevideo_urlfor the caller'sfile,formatdropped, a bareimage_urlstring turned into{url}, andfunction_call.arguments""for null. Base wrote that into the spend row even on Azure calls with no fallbackduring_callguardrail saw the caller's or the rewritten messages depending on timing. Head always gives it the caller'sRegression risk
fileandfunction_callshapes for these two providers. Only a custom logger and a custom guardrail were driven. Every vendor already receives those shapes from every other provider, so the risk is lowopenai/behind a hosted vLLM model. The OpenAI transform downloads the caller's video URL and sends it as file data, which vLLM may reject. It needs a real vLLM server to driveDependency graph
HostedVLLMChatConfig.transform_requesthosted_vllm/chatVLLMConfigsubclassvllm/AzureOpenAIConfigazure/chatAzureOpenAIGPT5Configazure/GPT-5AzureOpenAIO1Configazure/o-series/v1/messages/v1/messagesadapter/v1/responseslitellm_settings.callbacksduring_callguardrailguardrailscache: trueVLLMConfigcallsvllm_handler.completionand never reachestransform_request. The o-series transform does not callconvert_to_azure_openai_messages. Mistral is not changedNot verified
openai/fallback against a real vLLM server. No vLLM server is available, so every vLLM call goes to a closed portproxy_server_requestcolumn read aboveHow it ran
Base
05518975a5, headf4cfe9973e, and head merged with main atec48e2491c, each with its own Postgres, two workers, and its own Rust bridge build. Each proxy printedlitellm.__file__inside its own tree. A forwarding recorder sat in front of the vLLM base, which forwards to a closed port so every vLLM call fails over, and in front of the real Azure resource.rig_hooks.pyloads aCustomLoggerand aduring_callguardrail through config that record the messages each hook gets/v1/messagesto Azure/v1/messages, vLLM to GeminiResponse cache,
cache: truewithtype: local, read from the cache keys each proxy logged since each worker has its own cacheStored
proxy_server_requestmessages per spend rowType
🐛 Bug Fix
Caveats (if any)
Medium
function_call.argumentswent from 200 to 500, see Decision 7openai/now downloads the caller's URL (an unreachable one gets a 400), and one to Anthropic gets Anthropic's 400Low
video_urldropDecisions
image_urlandfileitems in fix(openai): stop stripping cache_control from the caller's own messages and tools #35602, which is in this PR's merge base, so this PR leaves that file alonefilepart rewrite (fix(mistral): forward prompt_cache_key to the Mistral API #47432) and itsnamedrop both build new dicts at the merge base_azure_tool_call_invoke_helpernow returns the chunk type instead of an optional one, since it never returned Noneduring_callguardrails, the post-call success hook, and the request stored in spend logs now see the messages the caller sent for hosted vLLM and Azure, where they used to see the rewritten ones. At the merge base aduring_callguardrail saw one or the other depending on timing. That is what every provider whose transform never edited in place already logs. The body sent to the provider is still logged asraw_requestwhenlog_raw_request_responseis on. Two more effects follow. A repeat of the same vLLM video or Azure media request now hits the response cache, because the merge base rewrote the messages between the cache lookup and the cache write. A streamed vLLM video call with no usage from the server now gets its prompt tokens estimated from the caller'sfilepart, where the merge base logged 0 because the token counter raised on the rewrittenvideo_urlpartfunction_call.argumentsinto"", so an Azure to OpenAI fallback on a model that still takes thefunctionrole now gets OpenAI's 400 for the null. A vLLM toopenai/fallback, such as a second vLLM server, now gets the caller'sfilepart, which the OpenAI transform downloads and sends as file data, so that server is better set up ashosted_vllm/. The other option was to turn nullargumentsinto""and videofileparts intovideo_urlin the OpenAI-compatible transforms. That changes direct calls for every one of them, so it belongs in its own changeFinal Attestation
Bugbot summary