Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

refactor(speech): freeze httpx response header dicts (LIT002)

mateo-berric1b5cacf1fe5
diff --git a/litellm/endpoints/speech/speech_to_completion_bridge/transformation.py b/litellm/endpoints/speech/speech_to_completion_bridge/transformation.py
index e2d3fadf852..2ed140c0208 100644
--- a/litellm/endpoints/speech/speech_to_completion_bridge/transformation.py
+++ b/litellm/endpoints/speech/speech_to_completion_bridge/transformation.py
@@ -174,7 +174,9 @@ class SpeechToCompletionBridgeTransformationHandler:
if self._is_gemini_tts_model(model)
else (decoded_audio, "audio/mpeg")
)
- response: Final = httpx.Response(status_code=200, content=content, headers={"Content-Type": content_type})
+ response: Final = httpx.Response(
+ status_code=200, content=content, headers=MappingProxyType({"Content-Type": content_type})
+ )
binary_response: Final = HttpxBinaryResponseContent(response)
binary_response.set_response_cost(_completion_response_cost(model_response))
return binary_response
diff --git a/litellm/llms/vertex_ai/text_to_speech/transformation.py b/litellm/llms/vertex_ai/text_to_speech/transformation.py
index a5ff7eca021..332f892ae6b 100644
--- a/litellm/llms/vertex_ai/text_to_speech/transformation.py
+++ b/litellm/llms/vertex_ai/text_to_speech/transformation.py
@@ -7,6 +7,7 @@ Reference: https://cloud.google.com/text-to-speech/docs/reference/rest/v1/text/s
import base64
from collections.abc import Coroutine
+from types import MappingProxyType
from typing import TYPE_CHECKING, Any, Final, Union
import httpx
@@ -464,7 +465,7 @@ class VertexAITextToSpeechConfig(BaseTextToSpeechConfig, VertexBase):
media_type: Final = speech_media_type_from_audio_bytes(binary_data)
response: Final = httpx.Response(
status_code=200,
- headers={} if media_type is None else {"content-type": media_type},
+ headers=None if media_type is None else MappingProxyType({"content-type": media_type}),
content=binary_data,
)