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
Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_mistral_voxtral_tts_speech
mateo-berri9f806be6e870
diff --cc tests/test_litellm/test_router.pyindex 014937b35cd,3b4c80b6b4f..ca806cfedd1--- a/tests/test_litellm/test_router.py+++ b/tests/test_litellm/test_router.py@@@ -12252,82 -12254,120 +12254,196 @@@ class TestTierParamsTheTargetAcceptsassert accepted == {"reasoning_effort": "max"}+async def test_router_aspeech_without_voice_dispatches_ref_audio_cloning(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"},+ }+ ]+ )++ response = await router.aspeech(model="voxtral-tts", input="clone me", ref_audio="ZmFrZQ==")++ request_body = json.loads(respx_mock.calls.last.request.content)+ assert request_body == {"model": "voxtral-mini-tts-2603", "input": "clone me", "ref_audio": "ZmFrZQ=="}+ 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 TestRequestReasoningEffortOverride:+ def test_drop_effort_from_nested_carrier_preserves_other_nested_values(self):+ params: dict[str, object] = {"output_config": {"effort": "high", "format": "json"}}++ litellm.Router._pop_effort_from_nested_carrier(params, "output_config")++ assert params == {"output_config": {"format": "json"}}++ @pytest.mark.parametrize("metadata_key", ["metadata", "litellm_metadata"])+ def test_is_classifier_internal_call_recognizes_both_metadata_carriers(self, metadata_key):+ kwargs = {metadata_key: {"internal_call_origin": "autorouter_classifier"}}++ assert litellm.Router._is_classifier_internal_call(kwargs) is True+ assert litellm.Router._is_classifier_internal_call({metadata_key: {}}) is False++ def test_removes_every_deployment_native_effort_carrier_without_mutating_shared_config(self):+ extra_body: dict[str, object] = {+ "reasoning_effort": "high",+ "thinking": {"type": "enabled"},+ "output_config": {"effort": "high", "format": "json"},+ "reasoning": {"effort": "high", "summary": "detailed"},+ "provider_option": True,+ }+ deployment_params: dict[str, object] = {+ "model": "bedrock/converse/anthropic.claude-3-7-sonnet",+ "thinking": {"type": "enabled", "budget_tokens": 2048},+ "output_config": {"effort": "high", "format": {"type": "json_schema"}},+ "reasoning": {"effort": "high", "summary": "auto"},+ "extra_body": extra_body,+ }++ sanitized = litellm.Router._deployment_params_with_request_reasoning_override(+ deployment_params, {"reasoning_effort": "low"}+ )++ assert sanitized == {+ "model": "bedrock/converse/anthropic.claude-3-7-sonnet",+ "output_config": {"format": {"type": "json_schema"}},+ "reasoning": {"summary": "auto"},+ "extra_body": {+ "output_config": {"format": "json"},+ "reasoning": {"summary": "detailed"},+ "provider_option": True,+ },+ }+ assert deployment_params["thinking"] == {"type": "enabled", "budget_tokens": 2048}+ assert deployment_params["output_config"] == {"effort": "high", "format": {"type": "json_schema"}}+ assert extra_body["reasoning_effort"] == "high"++ @pytest.mark.parametrize("request_kwargs", [{}, {"reasoning_effort": None}])+ def test_omitted_override_preserves_deployment_defaults(self, request_kwargs):+ deployment_params = {+ "model": "deepseek/deepseek-reasoner",+ "thinking": {"type": "enabled"},+ "output_config": {"effort": "high"},+ }++ assert (+ litellm.Router._deployment_params_with_request_reasoning_override(deployment_params, request_kwargs)+ == deployment_params+ )++ @pytest.mark.asyncio+ async def test_280_concurrent_overrides_never_mutate_or_leak_through_shared_deployment_params(self):+ deployment_params = {+ "model": "fireworks_ai/accounts/fireworks/models/kimi-k2-thinking",+ "thinking": {"type": "enabled"},+ "output_config": {"effort": "high", "format": "json"},+ "extra_body": {"reasoning_effort": "high", "tenant": "shared"},+ }+ efforts = ("none", "minimal", "low", "medium", "high", "xhigh", "max")++ results = await asyncio.gather(+ *(+ asyncio.to_thread(+ litellm.Router._deployment_params_with_request_reasoning_override,+ deployment_params,+ {"reasoning_effort": efforts[index % len(efforts)]},+ )+ for index in range(280)+ )+ )++ assert all("thinking" not in result for result in results)+ assert all(result["output_config"] == {"format": "json"} for result in results)+ assert all(result["extra_body"] == {"tenant": "shared"} for result in results)+ assert deployment_params["thinking"] == {"type": "enabled"}+ assert deployment_params["output_config"] == {"effort": "high", "format": "json"}+ assert deployment_params["extra_body"] == {"reasoning_effort": "high", "tenant": "shared"}++ @pytest.mark.parametrize(+ ("metadata", "should_drop"),+ [({"internal_call_origin": "autorouter_classifier"}, True), ({}, False)],+ ids=["classifier", "ordinary-request"],+ )+ def test_only_classifier_calls_drop_effort_for_an_unsupported_fallback(self, metadata, should_drop):+ router = litellm.Router(model_list=[])+ body: dict[str, object] = {"model": "classifier", "reasoning_effort": "low"}+ kwargs: dict[str, object] = {+ "reasoning_effort": "low",+ "metadata": metadata,+ "proxy_server_request": {"body": body},+ }+ deployment: DeploymentTypedDict = {+ "model_name": "fallback",+ "litellm_params": {"model": "openai/gpt-4o-mini"},+ }++ router._drop_unsupported_classifier_reasoning_effort(deployment, "fallback", kwargs)++ assert ("reasoning_effort" not in kwargs) is should_drop+ assert ("reasoning_effort" not in body) is should_drop++class TestPreRoutingTierDrivesFallbacks:"""#38832: a complexity/auto router picks a tier behind the router name, but fallbacklookup stayed on the router name, so the tier's configured chain never ran and a