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]

Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_mistral_voxtral_tts_speech

mateo-berribba75c7ce91b
diff --cc tests/test_litellm/test_cost_calculator.py
index db08ee486bf,6dc3b2790c9..6f9548dc1d7
--- a/tests/test_litellm/test_cost_calculator.py
+++ b/tests/test_litellm/test_cost_calculator.py
@@@ -4475,13 -4475,15 +4475,27 @@@ def test_explicit_pricing_precedes_priv
assert selected == expected
+def test_cost_per_token_mistral_voxtral_tts_bills_per_input_character(_local_model_cost_map):
+ prompt_usd, completion_usd = cost_per_token(
+ model="voxtral-mini-tts-2603",
+ custom_llm_provider="mistral",
+ call_type="speech",
+ prompt_characters=1000,
+ )
+
+ assert prompt_usd == pytest.approx(1000 * 1.6e-05)
+ assert completion_usd == 0.0
++
++
+ def test_batch_cost_calculator_gpt_6_astra_bills_half_the_standard_rate(_local_model_cost_map):
+ """gpt-6-astra batch pricing is 50% off the standard $10 input and $50 output rates per 1M tokens."""
+ from litellm.cost_calculator import batch_cost_calculator
+
+ usage = Usage(prompt_tokens=1000, completion_tokens=500, total_tokens=1500)
+
+ prompt_cost, completion_cost = batch_cost_calculator(
+ usage=usage, model="gpt-6-astra", custom_llm_provider="openai"
+ )
+
+ assert prompt_cost == pytest.approx(1000 * 5e-6)
+ assert completion_cost == pytest.approx(500 * 2.5e-5)
diff --cc tests/test_litellm/test_main.py
index e01679048e6,f228df1eb17..7682a6412b9
--- a/tests/test_litellm/test_main.py
+++ b/tests/test_litellm/test_main.py
@@@ -3261,47 -3337,41 +3337,87 @@@ def test_stream_chunk_builder_leaves_xa
assert logging_obj._response_cost_calculator(result=response) == pytest.approx(0.63)
+def test_speech_mistral_dispatches_and_decodes_audio(respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch):
+ monkeypatch.setenv("MISTRAL_API_KEY", "sk-mistral-test")
+ audio_bytes: Final = b"ID3-fake-mp3-bytes"
+ mock_route: Final = respx_mock.post("https://api.mistral.ai/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",
+ response_format="wav",
+ speed=2,
+ instructions="sound cheerful",
+ )
+
+ assert mock_route.called
+ request_body: Final = json.loads(mock_route.calls.last.request.content)
+ assert request_body == {
+ "model": "voxtral-mini-tts-2603",
+ "input": "hello from litellm",
+ "voice_id": "en_paul_neutral",
+ "response_format": "wav",
+ }
+ 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
++
++
+ FOUNDRY_HOST: Final = "https://my-project.services.ai.azure.com"
+
+
+ def test_azure_ai_transcription_on_a_foundry_host_uses_the_azure_openai_deployment_route(
+ respx_mock: respx.MockRouter,
+ ):
+ route: Final = respx_mock.post(
+ url__regex=r"https://my-project\.services\.ai\.azure\.com/openai/deployments/whisper-1/audio/transcriptions\?api-version=.+"
+ ).mock(return_value=httpx.Response(200, json={"text": "hello"}))
+
+ response: Final = litellm.transcription(
+ model="azure_ai/whisper-1",
+ file=("tone.wav", b"RIFF\x00\x00\x00\x00WAVE", "audio/wav"),
+ api_base=FOUNDRY_HOST,
+ api_key="fake-key",
+ )
+
+ assert route.called
+ assert response.text == "hello"
+
+
+ def test_azure_ai_speech_on_a_foundry_host_uses_the_azure_openai_deployment_route(
+ respx_mock: respx.MockRouter,
+ ):
+ route: Final = respx_mock.post(
+ url__regex=r"https://my-project\.services\.ai\.azure\.com/openai/deployments/tts-1/audio/speech\?api-version=.+"
+ ).mock(return_value=httpx.Response(200, content=b"mp3-bytes"))
+
+ response: Final = litellm.speech(
+ model="azure_ai/tts-1",
+ input="hello",
+ voice="alloy",
+ api_base=FOUNDRY_HOST,
+ api_key="fake-key",
+ )
+
+ assert route.called
+ assert response.content == b"mp3-bytes"