fix(proxy): narrow audio_speech response before reading upstream content-type

This commit is contained in:
mateo-berri 2026-08-30 12:46:11 -07:00
parent 2420e3f202
commit 99a6dd02af
2 changed files with 12 additions and 14 deletions

View file

@ -11068,8 +11068,11 @@ async def audio_speech(
custom_headers.update(callback_headers)
requested_format: Final = data.get("response_format")
upstream_content_type: Final = (
response.response.headers.get("content-type") if isinstance(response, HttpxBinaryResponseContent) else None
)
media_type: Final = resolve_speech_media_type(
upstream_content_type=response.response.headers.get("content-type"),
upstream_content_type=upstream_content_type,
response_format=requested_format if isinstance(requested_format, str) else None,
)

View file

@ -16,6 +16,7 @@ import httpx
import pytest
from litellm.proxy import proxy_server
from litellm.types.llms.openai import HttpxBinaryResponseContent
@pytest.fixture
@ -38,20 +39,14 @@ def patched_speech(monkeypatch, request):
monkeypatch.setattr(proxy_server, "add_litellm_data_to_request", _add_data)
class _FakeBinaryResp:
response = httpx.Response(
status_code=200,
headers={} if upstream_content_type is None else {"content-type": upstream_content_type},
)
async def aiter_bytes(self, chunk_size: int = 8192):
async def _gen():
yield b"\x00\x01\x02"
return _gen()
async def _llm_call():
return _FakeBinaryResp()
return HttpxBinaryResponseContent(
httpx.Response(
status_code=200,
headers={} if upstream_content_type is None else {"content-type": upstream_content_type},
content=b"\x00\x01\x02",
)
)
async def _fake_route_request(*args, **kwargs):
return _llm_call()