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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(speech): forward api_key to the TTS bridge and isolate response hidden params
mateo-berrifdeab570a1a8
diff --git a/basedpyright-code-budget.json b/basedpyright-code-budget.jsonindex 225a2c04339..cd05bbdfc7a 100644--- a/basedpyright-code-budget.json+++ b/basedpyright-code-budget.json@@ -99,7 +99,7 @@"limit": 0},"reportUnknownArgumentType": {- "limit": 44530+ "limit": 44528},"reportUnknownLambdaType": {"limit": 109@@ -138,9 +138,9 @@"limit": 139},"reportUnusedImport": {- "limit": 545+ "limit": 544},"reportUnusedVariable": {- "limit": 146+ "limit": 145}}diff --git a/litellm/main.py b/litellm/main.pyindex b4cc0771152..8ee102f5d07 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -8013,7 +8013,7 @@ def speech(if max_retries is None:max_retries = litellm.num_retries or openai.DEFAULT_MAX_RETRIES- litellm_params_dict: Final = get_litellm_params(metadata=metadata, **kwargs)+ litellm_params_dict: Final = get_litellm_params(metadata=metadata, api_key=api_key or dynamic_api_key, **kwargs)# Get provider-specific text-to-speech config and map parameterstext_to_speech_provider_config = ProviderConfigManager.get_provider_text_to_speech_config(diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.pyindex ede72e5559e..45f6b5c55a9 100644--- a/litellm/types/llms/openai.py+++ b/litellm/types/llms/openai.py@@ -107,10 +107,17 @@ EmbeddingInput = str | list[str]class HttpxBinaryResponseContent(_HttpxBinaryResponseContent):- _hidden_params: dict = {}+ _hidden_params: dict++ def __init__(self, response: httpx.Response) -> None:+ super().__init__(response)+ self._hidden_params = {} # mutable-ok: mutable-dict contract shared with ModelResponse logging consumersdef set_response_cost(self, response_cost: float | None) -> None:- self._hidden_params = {"response_cost": response_cost}+ if response_cost is None:+ self._hidden_params.pop("response_cost", None)+ return+ self._hidden_params["response_cost"] = response_costclass NotGiven:diff --git a/ruff-strict-budget.json b/ruff-strict-budget.jsonindex b24335ad112..149c44ed083 100644--- a/ruff-strict-budget.json+++ b/ruff-strict-budget.json@@ -108,7 +108,7 @@"limit": 3},"F401": {- "limit": 14+ "limit": 13},"LOG015": {"limit": 5@@ -171,7 +171,7 @@"limit": 175},"RUF012": {- "limit": 240+ "limit": 239},"RUF015": {"limit": 8@@ -183,7 +183,7 @@"limit": 4},"RUF059": {- "limit": 67+ "limit": 66},"RUF100": {"limit": 0diff --git a/tests/test_litellm/test_main.py b/tests/test_litellm/test_main.pyindex 34c558db288..3eea47bcd5a 100644--- a/tests/test_litellm/test_main.py+++ b/tests/test_litellm/test_main.py@@ -3042,6 +3042,8 @@ async def test_aspeech_gemini_bridge_keeps_proxy_metadata_for_spend_tracking(respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setattr(litellm, "disable_aiohttp_transport", True)+ monkeypatch.delenv("GEMINI_API_KEY", raising=False)+ monkeypatch.delenv("GOOGLE_API_KEY", raising=False)recorder: Final = _SuccessEventRecorder()monkeypatch.setattr(litellm, "callbacks", [recorder])mock_route: Final = respx_mock.post(@@ -3057,6 +3059,7 @@ async def test_aspeech_gemini_bridge_keeps_proxy_metadata_for_spend_tracking()assert mock_route.called+ assert mock_route.calls.last.request.headers["x-goog-api-key"] == "fake-gemini-key"speech_event: Final = await _wait_for_success_event(recorder, call_type="aspeech")assert speech_event.spend_metadata["user_api_key"] == "hashed-virtual-key"assert speech_event.spend_metadata["user_api_key_user_id"] == "user-1"diff --git a/tests/test_litellm/types/llms/test_types_llms_openai.py b/tests/test_litellm/types/llms/test_types_llms_openai.pyindex 3966677e928..42719ce838b 100644--- a/tests/test_litellm/types/llms/test_types_llms_openai.py+++ b/tests/test_litellm/types/llms/test_types_llms_openai.py@@ -7,6 +7,7 @@ import pytestimport jsonimport litellm+from litellm.types.llms.openai import HttpxBinaryResponseContentdef test_generic_event():@@ -522,3 +523,34 @@ class TestOpenAIFileObjectBatchGuardrailSerialization:page = FileListPage(object="list", data=[self._file_object()], has_more=False)assert "litellm_batch_guardrail" not in page.model_dump(mode="json")["data"][0]+++def _binary_content(payload: bytes) -> HttpxBinaryResponseContent:+ import httpx++ return HttpxBinaryResponseContent(httpx.Response(200, content=payload))+++def test_httpx_binary_response_content_hidden_params_are_per_instance():+ first = _binary_content(b"first")+ second = _binary_content(b"second")++ first._hidden_params["response_cost"] = 0.5++ assert second._hidden_params == {}+++def test_set_response_cost_none_leaves_hidden_params_empty():+ binary_response = _binary_content(b"audio")++ binary_response.set_response_cost(None)++ assert "response_cost" not in binary_response._hidden_params++ binary_response.set_response_cost(0.25)++ assert binary_response._hidden_params["response_cost"] == 0.25++ binary_response.set_response_cost(None)++ assert "response_cost" not in binary_response._hidden_paramsdiff --git a/type-discipline-budget.json b/type-discipline-budget.jsonindex 4465580657b..e0c0dd8147b 100644--- a/type-discipline-budget.json+++ b/type-discipline-budget.json@@ -3,7 +3,7 @@"limit": 22733},"LIT002": {- "limit": 26864+ "limit": 26863},"LIT003": {"limit": 269