Repository navigation
fix(bridges): backport #49960 audio output refusal to lts/1.108.x - #53745
Conversation
…ons before the provider call Backport of BerriAI#49960 to lts/1.108.x, folding its commits into one adapted commit The /v1/messages check goes in litellm/llms/anthropic/pass_through/messages/handler.py, where this line keeps the chat bridge. The line has no litellm.utils.is_gemini_tts_model, so this adds the same name check main got in BerriAI#31915. text_completion keeps the line's **optional_params spread The test fixture drops register_model's add_to_provider_model_sets flag, which this line does not have Cherry-picked from ec882be, c37c252, 9b6b65e, 16255e8, 675bf5d, 3d505a2, 22777c8, 3c5ed0a, a345bc4 (litellm_fix_gemini_audio_bridges)
…rt_49960_lts_1_108_x # Conflicts: # litellm/responses/main.py
PR overviewNo security issues were found in this pull request. Reviews
|
[Medium impact] The change affects audio requests across three public API bridges. Fix the template-selected TTS bypass before merging Findings
|
| completion_kwargs: Final = bridged_audio_output_request(kwargs, _model, custom_llm_provider) | ||
| if isinstance(completion_kwargs, AudioOnlyModel | AudioRequested): | ||
| raise_audio_output_refusal(completion_kwargs, "/v1/completions") |
There was a problem hiding this comment.
Templates bypass the audio refusal
text_completion checks the requested model before completion applies prompt templates. A template can then replace a text model with a Gemini TTS model without another check. The provider call still runs, and the caller gets empty text with billed usage. Check the final model after the template is applied
There was a problem hiding this comment.
Same order as main, where #49960 merged. A template picking a TTS model behaves as before this PR. A follow-up ticket tracks it
There was a problem hiding this comment.
Got it — that makes sense. Since this is a backport and matches main's behavior exactly, keeping the same template ordering is correct. The Low caveat documents it, and the follow-up ticket will address it properly.
| litellm.register_model( | ||
| { | ||
| SINGER_MODEL: {"litellm_provider": "gemini", "mode": "chat", "supported_output_modalities": ["audio"]}, | ||
| VOICE_MODEL: { | ||
| "litellm_provider": "custom_openai", | ||
| "mode": "chat", | ||
| "supported_output_modalities": ["text", "audio"], | ||
| }, | ||
| }, | ||
| persist_across_reloads=False, | ||
| ) |
There was a problem hiding this comment.
Tests leave shared model entries
The autouse fixture adds two models to litellm.model_cost but never removes them. persist_across_reloads=False only disables replay after a reload. Shared cleanup restores the same dictionary, so later tests still see these entries and can depend on test order. Restore the entries during teardown
There was a problem hiding this comment.
This fixture matches main's, which merged with #49960. The cleanup goes to main first and then this line, and a follow-up ticket tracks it
There was a problem hiding this comment.
Got it — matching main's fixture behavior makes sense for a backport. The cleanup can go through both branches together via the follow-up.
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 f851cb5. Configure here.
Handwritten 1-3 sentence description
Backport of #49960 to the 1.108 LTS line. Gemini TTS models on /v1/responses, /v1/messages and /v1/completions gave back an empty 200 and still billed the audio, and now those endpoints answer 400 pointing to /v1/chat/completions before anything is sent to Gemini. A text model asked for audio there gets a 400 too, unless drop_params is on
Details
TLDR
Problem this solves:
How it solves it:
Intentional product change: a text model asked for audio on these endpoints now answers 400 unless drop_params is on
User Flow
Before: a developer who calls a Gemini TTS model through /v1/responses gets an empty answer and still pays for it
"model": "gemini-tts"and"audio": {"voice": "Kore", "format": "pcm16"}, or the same through /v1/messages or /v1/completions"output": []("content": []on /v1/messages,"text": nullon /v1/completions)After: the same request is refused before it reaches Gemini, so nothing is billed
gemini/gemini-3.8-flash-tts returns audio, which /v1/responses cannot carry. Call /v1/chat/completions to get the audio.Relevant issues
Backport of #49960. Its commits are folded into one commit on this line, since the PR's own merge of main replaced ec882be with c37c252
The
is_gemini_tts_modelhelper comes from #31915 (045fb7b), only that one function, since the line has no copy of itMerging lts/1.108.x at f69cbe5 into the branch (f851cb5) conflicted only on the imports at the top of
litellm/responses/main.py. Both import blocks are keptHow the pick differs from main
The /v1/messages check goes in
litellm/llms/anthropic/pass_through/messages/handler.py, because this line has nomessages/native/handler.py.text_completionkeeps the line's**optional_paramsnext to the new kwargs. The unit test fixture callsregister_modelwithoutadd_to_provider_model_sets=False, which this line'sregister_modeldoes not take. Everything else, includingbridged_audio_output.py, matches mainGauntlet-mini: SURVIVED, 5/5 lenses, 0 confirmed (all fixed), run 5e7ab38fe5e1, reviewed fb62f6b21c. 448eef5 has the same tree and only rewords its commit message
Gauntlet-mini findings, all rejected
modalitiesused to answer 200 and now gets a 400. Rejected, since it is fix(bridges): refuse audio output on Responses, Messages and Completions before the provider call #49960's Medium caveat below anddrop_paramsbrings back the 200extra_bodyaudio and amodalitieslist with a null entry skip the check. Rejected, the first is fix(bridges): refuse audio output on Responses, Messages and Completions before the provider call #49960's Low caveat and the second is malformed input, same as mainmock_response, /v1/completions refuses while the other two return the mock. Rejected, it only affects mock-based testsDependencies: no bumps. Every package grype flags on this line's lock is either still on the same version on main or has no fixed release
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
Per-fix smoke on the 1.108 line, since #49960 carries the full QA. Each leg ran a 2-worker proxy on its own commit with the config below, and every call hit Gemini. Before ran at f69cbe5, the line commit this branch merged in, and After ran at this PR's tip f851cb5. The picked unit tests pass on the line at that tip (49 passed), and so does
tests/integration/providers(27 passed)modalities, /v1/responsesHow to run it
Run from the checked-out commit's root with
GEMINI_API_KEYandLITELLM_MASTER_KEYsetWith
PROXYandLITELLM_MASTER_KEYexported, runpython clients.py gemini-tts,python clients.py gemini-flashandpython clients.py gemini-flash drop. It sends one prompt to all four endpoints through the official SDKs.gemini-ttssendsaudio,gemini-flashsendsmodalities, anddropaddsdrop_params: trueThen
python template_client.pyandpython template_client.py dropcall /v1/responses with thespoken-answerprompt, whose template asks formodalities: ["text", "audio"]clients.py
template_client.py
Before (f69cbe5), lines cut at 240 characters
After (f851cb5), lines cut at 240 characters
Type
🐛 Bug Fix
Caveats (if any)
Copied from #49960
Medium
modalitieswith "audio" answered 200 with text before. It answers 400 nowdrop_params: truebrings back the old answerLow
audioormodalitiesskips the check on /v1/messagesfallback_on_unsupported_paramsdefaults to true, so "nothing is billed" holds only when no fallback is configuredaudioormodalitiescomes from a deployment'slitellm_params, the caller is told to leave out params they never sentextra_bodyaudio onlitellm.responses()skips the checkmodalities: ["text", "audio"]andaudioFinal Attestation
Bugbot summary