Repository navigation
fix(responses): map input_audio blocks in the chat-to-Responses bridge - #45224
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
#40032 landed first and added the wire helper that drops a malformed prompt_cache_breakpoint under drop_params, so the input_audio branch now carries its marker through that helper like the text and image branches, with a regression test for the malformed case. Main's unknown-block marker test used input_audio as its unmappable example and now uses a video_url part. The audio test fixture registers its fake models through monkeypatch on the price map, so nothing leaks into the provider model sets, and the new tests carry the Final and fixture annotations the repo asks for
1 similar comment
…preceding part Dropping an input_audio part under drop_params lost the prompt_cache_breakpoint riding on it, so an injected system marker landing on a trailing audio block left prompt_cache_options explicit with no breakpoint on the wire. The marker now moves to the nearest preceding kept part when that part has none. Update the CircleCI-only Responses bridge wire tests that pinned input_audio to its stringified input_text shape: video_url becomes the stringified kind so the marker-on-stringified-block coverage survives, and dedicated audio tests assert the forwarded part and the drop_params carry-over.
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
Replace the per-block slice that re-read the rest of the content list for every retained part with a single reverse scan, and skip the copy for a message that carries no audio part. Type the unit test helper's messages as a sequence of mappings instead of bare lists.
…the bridge Cover the chat-to-Responses bridge's input_audio handling on the real proxy: the part is forwarded as input_audio without drop_params and dropped under drop_params unless the model or its base_model supports audio input, across httpx, the OpenAI SDK (sync stream and async), the Anthropic SDK, native /v1/responses, tool and assistant messages, hostile input_audio values, duplicate parts, an audio-only message, marker carry-over, a null drop_params, a global litellm_settings.drop_params, a mixed burst, and a burst with dropped upstream connections
The dropped-connection cell required exactly one upstream POST per call, which tied it to the retry policy instead of the fix. It now groups the recorded POSTs by marker, requires one attempt per answered call, and checks that every attempt of a doomed call carries the dropped audio shape.
|
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 642ada1. Configure here.
TLDR
Problem this solves:
input_audiopartsinput_textholding the dict's Python reprHow it solves it:
input_audioto the Responses APIinput_audiopart, payload as sentdrop_params, drop the part when the model has no audio inputdrop_params, forward it and let the provider answerprompt_cache_breakpointthe way the text and image parts doprompt_cache_breakpointto the preceding kept part, so an injected system marker that landed on a trailing audio block still reaches the wireIntentional product change: a Responses deployment without
drop_paramsnow returns the provider's own 400 ("Audio input is not available." on OpenAI today) instead of a 200 that read the base64 as text and billed it, so a developer learns the clip was never heard instead of paying for itUser Flow
Before: a developer who sends a voice clip through chat completions to a Responses API deployment gets a 200 with a made-up answer and a huge token bill
openai/responses/gpt-5.4-minideployment with one user message holding atextpart and aninput_audiopart (base64 wav)usage.prompt_tokensreads 113,728 for a 64-character questiondrop_params: trueon the deployment and try again, and the same 200 with the same 113,728 tokens comes backAfter: the same request carries the audio as audio, so the provider answers honestly and the base64 is never billed as text
openai/responses/gpt-5.4-minideployment with one user message holding atextpart and aninput_audiopart (base64 wav)drop_params: trueon the deployment and try again, the clip is dropped, 200 comes back answering only the text, andusage.prompt_tokensis in the dozensPre-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 more@greptileaito re-request a review after pushing changes)Delays 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
Last updated: 642ada1. QA and /live-pr-risk ran on fb9fdca, the last commit with a product diff
Run of 2026-10-07 against api.openai.com (real calls, real money; the big ones are gpt-5.4-mini and gpt-6.1-sol calls billed 113,728 and 113,740 input tokens). Each leg boots its own proxy from its own worktree and venv with
--num_workers 2, Postgres-backed, on a random free port, with a small forwarding recorder in front ofapi.openai.com(WIRE_BASEbelow) so the "what reached OpenAI" line under each case can show the provider's side; the verdict rests on the HTTP responses alone. The before leg ran at the merge base b970e41 in a detached checkout, the after leg at fb9fdca, the last commit with a product diff (the tests commit on top changes no product code). The one end-user surface the bridge serves is/v1/chat/completionson a Responses-only deployment:/v1/responsesnever enters the bridge, and the Anthropic Messages shape has no audio blockConfig (
config.yaml),OPENAI_API_KEYfrom the environment,WIRE_BASEthe recorder forwarding tohttps://api.openai.com/v1:Request body, the same for every case except
model.speech.wavis a 127,244-byte TTS clip saying "The secret word is pineapple." (169,660 base64 chars):{"model": "<model>", "messages": [{"role": "user", "content": [ {"type": "text", "text": "What is the secret word spoken in the audio? Answer in one word."}, {"type": "input_audio", "input_audio": {"data": "<base64 of speech.wav>", "format": "wav"}}]}]}The call, with
req_<model>.jsonholding that body:Before (b970e41)
Case A: text + input_audio to openai/responses/gpt-5.4-mini, no drop_params
curl ... http://127.0.0.1:20685/v1/chat/completions --data-binary @req_text-resp.jsonPOST /v1/responses, modelgpt-5.4-mini, content partsinput_text(64 chars) andinput_text(169,729 chars starting{'type': 'input_audio', 'input_audio': {'data': 'UklGRv), upstream 200 withinput_tokens: 113728Case B: same deployment with drop_params: true
curl ... http://127.0.0.1:20685/v1/chat/completions --data-binary @req_text-resp-drop.jsoninput_textparts as case A, upstream 200,input_tokens: 113728(113,408 of them a prompt-cache hit on case A's prefix)Case C: control, openai/gpt-audio-mini on plain chat completions
curl ... http://127.0.0.1:20685/v1/chat/completions --data-binary @req_audio-chat.jsonPOST /v1/chat/completions, modelgpt-audio-mini, thetextandinput_audioparts intact, upstream 200 withaudio_tokens: 26After (fb9fdca)
Case A: text + input_audio to openai/responses/gpt-5.4-mini, no drop_params
curl ... http://127.0.0.1:34502/v1/chat/completions --data-binary @req_text-resp.jsonPOST /v1/responses, modelgpt-5.4-mini, parts input_text(64), input_audio(wav, 169,660 chars), upstream 400Case B: same deployment with drop_params: true
curl ... http://127.0.0.1:34502/v1/chat/completions --data-binary @req_text-resp-drop.jsonPOST /v1/responses, modelgpt-5.4-mini, parts input_text(64), upstream 200Case C: control, openai/gpt-audio-mini on plain chat completions
curl ... http://127.0.0.1:34502/v1/chat/completions --data-binary @req_audio-chat.jsonPOST /v1/chat/completions, modelgpt-audio-mini, chat parts intact, upstream 200Supporting cells, before b970e41 vs after fb9fdca
Same proxies and recorders as the three cases above. Request shapes are the Case A body with the named change
stream: truestream: trueinput_audio: "not-a-dict"input_audio: 7prompt_cache_breakpoint[]Audit, deterministic cells on the scripted upstream
Three rigs on one box (real Postgres, Redis, a two-worker proxy each, a scripted OpenAI Responses upstream, no
.env): base b970e41, head fb9fdca, controls fb9fdca. Run throughtests/integration/run.py providers <node ids>, seeds 4106601 / 0, one worker like CircleCI. The head selection ran twice with the same collected and passed set. Files:tests/integration/providers/test_responses_bridge_input_audio_wire.py(audio), the chaos file's two newlitellm_settings.drop_paramscells (chaos), and the three audio cells of the sibling marker file (marker)The two base greens are the rows the fix leaves alone on purpose: the Anthropic SDK through
/v1/messages(the adapter has no audio block, so the bridge never sees one) and native/v1/responses(no bridge). Every red on base asserts the stringifiedinput_textrepr where the head forwards or drops the parttest_audio_part_is_dropped_under_drop_paramstest_audio_part_is_forwarded_as_input_audio_without_drop_paramstest_openai_sdk_stream_shapes_the_audio_part_by_mode[on]test_openai_sdk_stream_shapes_the_audio_part_by_mode[off]test_async_openai_sdk_shapes_the_audio_part_by_mode[on]test_async_openai_sdk_shapes_the_audio_part_by_mode[off]test_audio_capable_model_keeps_the_audio_part_under_drop_paramstest_base_model_in_litellm_params_keeps_the_audio_part_under_drop_paramstest_base_model_in_model_info_keeps_the_audio_part_under_drop_paramstest_tool_output_audio_part_follows_the_mode[on]test_tool_output_audio_part_follows_the_mode[off]test_injected_system_marker_lands_on_a_trailing_audio_part_without_drop_paramstest_assistant_audio_part_follows_the_mode[on]test_assistant_audio_part_follows_the_mode[off]test_anthropic_sdk_request_carries_no_audio_part_into_the_bridgetest_native_responses_audio_part_never_enters_the_bridgetest_hostile_audio_value_is_forwarded_verbatim_without_drop_params[int]test_hostile_audio_value_is_forwarded_verbatim_without_drop_params[list]test_hostile_audio_value_is_forwarded_verbatim_without_drop_params[empty-string]test_hostile_audio_value_is_forwarded_verbatim_without_drop_params[5kb-string]test_hostile_audio_value_is_dropped_under_drop_params[int]test_hostile_audio_value_is_dropped_under_drop_params[list]test_hostile_audio_value_is_dropped_under_drop_params[empty-string]test_hostile_audio_value_is_dropped_under_drop_params[5kb-string]test_audio_part_without_a_payload_follows_the_mode[on]test_audio_part_without_a_payload_follows_the_mode[off]test_two_identical_audio_parts_follow_the_mode[on]test_two_identical_audio_parts_follow_the_mode[off]test_audio_only_message_is_forwarded_with_empty_content_under_drop_paramstest_leading_audio_marker_has_no_preceding_part_to_carry_totest_each_dropped_audio_marker_moves_to_its_own_preceding_texttest_text_marker_wins_over_the_dropped_audio_markertest_null_drop_params_forwards_the_audio_parttest_mixed_audio_burst_shapes_every_upstream_request_by_its_modetest_dropped_upstream_connections_fail_only_their_own_callstest_global_drop_params_drops_the_audio_part_and_carries_its_marker[deployment-unset]test_global_drop_params_drops_the_audio_part_and_carries_its_marker[deployment-false]test_input_audio_block_is_forwarded_with_its_marker_without_drop_paramstest_input_audio_block_is_dropped_under_drop_params_and_its_marker_moves_to_the_texttest_injected_system_marker_survives_a_trailing_audio_blockControls, once on the head:
test_openai_sdk_sends_a_valid_marker_through_the_bridge,test_valid_marker_is_carried_on_every_block_kindx8,test_tool_output_markerx4,test_injected_marker_on_a_string_system_message,test_anthropic_sdk_marker_on_user_textx4,test_native_responses_request_never_enters_the_bridge, chaostest_global_drop_params_drops_a_malformed_markerx2 andtest_mixed_burst_carries_every_marker_once, andtests/integration/messages_endpoint/responses_bridge/test_anthropic_messages_openai_bridge_wire.py::test_midturn_system_correction_is_forwarded_to_openai_responses, all greenThe tests-only commit 642ada1 made the dropped-connection cell retry-agnostic (every upstream attempt of a doomed call is checked for the dropped audio shape, instead of requiring one attempt per call), so the two cells it changed reran on both legs at that tip with the same seeds: base 0 of 2, head 2 of 2 in both runs. Every other row keeps its fb9fdca result, since the product code is unchanged
Live cells A to K above are the same audit's third-party rows: real api.openai.com through the recorder, one run per leg
Type
🐛 Bug Fix
Caveats (if any)
Medium
openai/responses/gpt-audio-minimain's stringified request gotmodel_not_found("not supported with the Responses API"); the real audio part gets "Audio input is not available." (cell D)openai/gpt-audio-mini) is untouched and still bills the clip as 26 audio tokensdrop_paramsgate is thesupports_audio_inputcost-map flag of the model or the deployment'sbase_modelgpt-4o-audio-previewhave no entry today, so they lose it toodrop_params; rejected since a capable provider would lose real audioLow
contentlist underdrop_params(OpenAI accepts it)input_audiodict is forwarded as sent,formatincluded; the provider validates it, not the bridgeinput_audiopart'sprompt_cache_breakpointgoes through its wire helper, so a malformed marker drops underdrop_paramslike on text and image partsinput_audioas the unmappable example; it now uses avideo_urlpart, sinceinput_audiois mappeddrop_paramsdrops the audio part, its marker moves to the nearest preceding kept part that has none of its own (thecache_control_injection_pointshook marks the last block of a message, audio included, so without this the injected system marker vanished whileprompt_cache_optionsstayed explicit); a marker on a leading or audio-only part has no such neighbour and is dropped with the parttests/integration/providers/test_responses_bridge_prompt_cache_breakpoint_wire.pypinned the stringified audio shape, and CircleCI never runs on a PR, so they are updated here:video_urlis the stringified kind, and two audio tests cover the forwarded part and the drop_params carry-over. Through the integration harness on this tip the file passes 67 of 67; the pre-update file on this tip fails 4 (test_injected_system_marker_survives_a_trailing_audio_block,test_malformed_marker_is_dropped_on_every_block_kind[input_audio],test_valid_marker_is_carried_on_every_block_kind[input_audio-on]and[input_audio-off]); the updated file on main's code fails 3 (the two audio tests andtest_injected_system_marker_survives_a_trailing_audio_block)convert_chat_completion_messages_to_responses_apioutside the bridge now receive a structuredinput_audiopart where they got aninput_textrepr: the Noma guardrail's Responses translation, the/v1/responsesguardrail translation handler (whose reverse converter already mapsinput_audioback toinput_audio), and the complexity router's native classifier payload (every caller enumerated acrosslitellm/,enterprise/, andtests/; none inenterprise/). Traced, not driven live; special-casing audio there would bring the repr backuse_openai_responses_path, Azure) now receive a realinput_audiopart and answer on their ownLive dependency check
Breaking:
drop_paramsnow answers 400 to a chat request carryinginput_audiowhere main answered 200 and billed the base64 as text: cells A, D, F (streaming, before any chunk) and G (input_audioa string). Intentional: it is the fix's stated behavior in the TLDR, the drop_params convention the requester asked for, and the convention a chat deployment already follows for an unsupported paramBackward incompatible:
convert_chat_completion_messages_to_responses_apiemits{"type": "input_audio", "input_audio": {...}}for aninput_audiopart; its three callers outside the bridge (named under Low) receive that instead of aninput_textreprdrop_params: trueon a Responses deployment now removes a content part, where before it only removed request paramsprompt_cache_breakpointmoves to the preceding kept part (cell J: before, the marker rode the stringified clip; after, it rides the 64-character text)Regression risk, untested dependents:
encrypted_taskconfigured, traced onlyDependency graph:
transform_requestand the converter: verified live (cells A to K), unit tests, and the audit's 40 deterministic cells on both legsdrop_params: verified live (cells B, E, H, I, J, K), unit tests, and the audit's drop, carry, global drop_params and burst cellstests/integrationwire tests: the audit round at fb9fdca (base red, head green twice, controls green), plus the two cells 642ada1 changed rerun there (base red, head green twice)/v1/responsesguardrail translation handler, two call sites: traced, untested liveschema.d.ts: no field changed, no dependentNot verified:
encrypted_taskconfig)use_openai_responses_pathdeploymentsFinal 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
fb9fdca passes /audit (the two cells 642ada1 changed reran there)
fb9fdca passes /live-pr-risk