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]

fix(mistral): keep the deployment voice default and drop the unreachable api base fallback

mateo-berri0a2581c14caa
diff --git a/litellm/llms/mistral/audio_speech/transformation.py b/litellm/llms/mistral/audio_speech/transformation.py
index 7f5a659bd08..2b3264dc756 100644
--- a/litellm/llms/mistral/audio_speech/transformation.py
+++ b/litellm/llms/mistral/audio_speech/transformation.py
@@ -115,7 +115,7 @@ class MistralTextToSpeechConfig(BaseTextToSpeechConfig):
api_base: str | None,
litellm_params: Mapping[str, object],
) -> str:
- configured_base: Final = (api_base or get_secret_str("MISTRAL_API_BASE") or self.TTS_BASE_URL).rstrip("/")
+ configured_base: Final = (api_base or self.TTS_BASE_URL).rstrip("/")
versioned_base: Final = configured_base if configured_base.endswith("/v1") else f"{configured_base}/v1"
return f"{versioned_base}/audio/speech"
diff --git a/litellm/router.py b/litellm/router.py
index ee3a3ced023..b1357374f5c 100644
--- a/litellm/router.py
+++ b/litellm/router.py
@@ -4422,7 +4422,7 @@ class Router:
**{
**data,
"input": input,
- "voice": voice,
+ **({"voice": voice} if voice is not None else {}),
"client": model_client,
**kwargs,
}
diff --git a/tests/test_litellm/llms/mistral/audio_speech/test_mistral_audio_speech_transformation.py b/tests/test_litellm/llms/mistral/audio_speech/test_mistral_audio_speech_transformation.py
index 108d4107db1..d819a79cef1 100644
--- a/tests/test_litellm/llms/mistral/audio_speech/test_mistral_audio_speech_transformation.py
+++ b/tests/test_litellm/llms/mistral/audio_speech/test_mistral_audio_speech_transformation.py
@@ -84,8 +84,7 @@ def test_transform_request_omits_voice_for_ref_audio_cloning():
}
-def test_get_complete_url_default_base(monkeypatch: pytest.MonkeyPatch):
- monkeypatch.delenv("MISTRAL_API_BASE", raising=False)
+def test_get_complete_url_default_base():
config: Final = MistralTextToSpeechConfig()
url: Final = config.get_complete_url(model="voxtral-mini-tts-2603", api_base=None, litellm_params={})
assert url == SPEECH_URL
@@ -101,13 +100,6 @@ def test_get_complete_url_custom_base_always_versioned(api_base: str):
assert url == "https://custom.api.example.com/v1/audio/speech"
-def test_get_complete_url_host_only_env_base_gets_v1(monkeypatch: pytest.MonkeyPatch):
- monkeypatch.setenv("MISTRAL_API_BASE", "https://api.mistral.ai")
- config: Final = MistralTextToSpeechConfig()
- url: Final = config.get_complete_url(model="voxtral-mini-tts-2603", api_base=None, litellm_params={})
- assert url == SPEECH_URL
-
-
def test_validate_environment_sets_bearer_header():
config: Final = MistralTextToSpeechConfig()
headers: Final = config.validate_environment(
diff --git a/tests/test_litellm/test_main.py b/tests/test_litellm/test_main.py
index 9b5122c3f75..e01679048e6 100644
--- a/tests/test_litellm/test_main.py
+++ b/tests/test_litellm/test_main.py
@@ -3287,3 +3287,21 @@ def test_speech_mistral_dispatches_and_decodes_audio(respx_mock: respx.MockRoute
}
assert mock_route.calls.last.request.headers["authorization"] == "Bearer sk-mistral-test"
assert response.content == audio_bytes
+
+
+def test_speech_mistral_routes_to_configured_api_base(respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch):
+ monkeypatch.setenv("MISTRAL_API_KEY", "sk-mistral-test")
+ audio_bytes: Final = b"ID3-gateway-bytes"
+ gateway_route: Final = respx_mock.post("https://mistral.gateway.internal/v1/audio/speech").mock(
+ return_value=httpx.Response(200, json={"audio_data": base64.b64encode(audio_bytes).decode()})
+ )
+
+ response: Final = litellm.speech(
+ model="mistral/voxtral-mini-tts-2603",
+ input="hello from litellm",
+ voice="en_paul_neutral",
+ api_base="https://mistral.gateway.internal",
+ )
+
+ assert gateway_route.called
+ assert response.content == audio_bytes
diff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.py
index 048536d887f..014937b35cd 100644
--- a/tests/test_litellm/test_router.py
+++ b/tests/test_litellm/test_router.py
@@ -12278,6 +12278,56 @@ async def test_router_aspeech_without_voice_dispatches_ref_audio_cloning(respx_m
assert response.content == audio_bytes
+async def test_router_aspeech_without_voice_keeps_deployment_default_voice(respx_mock, monkeypatch):
+ import base64
+
+ monkeypatch.setenv("MISTRAL_API_KEY", "sk-mistral-test")
+ monkeypatch.setattr(litellm, "disable_aiohttp_transport", True)
+ audio_bytes = b"RIFFfake-wav-bytes"
+ respx_mock.post("https://api.mistral.ai/v1/audio/speech").respond(
+ json={"audio_data": base64.b64encode(audio_bytes).decode()}
+ )
+ router = Router(
+ model_list=[
+ {
+ "model_name": "voxtral-tts",
+ "litellm_params": {"model": "mistral/voxtral-mini-tts-2603", "voice": "en_paul_neutral"},
+ }
+ ]
+ )
+
+ await router.aspeech(model="voxtral-tts", input="use my default")
+
+ request_body = json.loads(respx_mock.calls.last.request.content)
+ assert request_body["voice_id"] == "en_paul_neutral"
+
+
+async def test_router_aspeech_request_voice_overrides_deployment_default(respx_mock, monkeypatch):
+ import base64
+
+ monkeypatch.setenv("MISTRAL_API_KEY", "sk-mistral-test")
+ monkeypatch.setattr(litellm, "disable_aiohttp_transport", True)
+ audio_bytes = b"RIFFfake-wav-bytes"
+ respx_mock.post("https://api.mistral.ai/v1/audio/speech").respond(
+ json={"audio_data": base64.b64encode(audio_bytes).decode()}
+ )
+ router = Router(
+ model_list=[
+ {
+ "model_name": "voxtral-tts",
+ "litellm_params": {"model": "mistral/voxtral-mini-tts-2603", "voice": "en_paul_neutral"},
+ }
+ ]
+ )
+
+ await router.aspeech(model="voxtral-tts", input="override me", voice="gb_oliver_neutral")
+
+ request_body = json.loads(respx_mock.calls.last.request.content)
+ assert request_body["voice_id"] == "gb_oliver_neutral"
+
+
class TestPreRoutingTierDrivesFallbacks:
"""#38832: a complexity/auto router picks a tier behind the router name, but fallback
lookup stayed on the router name, so the tier's configured chain never ran and a