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-berri25bb8c92e351
diff --cc tests/test_litellm/test_main.py
index 47293d9c413,7c2b9d0be05..cb7f117f937
--- a/tests/test_litellm/test_main.py
+++ b/tests/test_litellm/test_main.py
@@@ -3180,32 -3214,26 +3214,54 @@@ def test_stream_chunk_builder_keeps_pro
)
assert response is not None
- assert response._hidden_params.get("response_cost") is None
+ assert getattr(response.usage, "cost", None) == pytest.approx(0.5)
+ assert response._hidden_params["response_cost"] == pytest.approx(0.5)
+
+
+ def test_stream_chunk_builder_prices_alias_from_openai_sdk_usage_chunk():
+ from openai.types.completion_usage import CompletionUsage
+
+ usage_chunk: Final = _stream_builder_text_chunk("mantle-claude", "")
+ usage_chunk.usage = CompletionUsage(prompt_tokens=20, completion_tokens=60, total_tokens=80, cost=0.000704)
+ assert type(usage_chunk.usage) is CompletionUsage
+ chunks: Final = [
+ _stream_builder_text_chunk("mantle-claude", "Hello "),
+ _stream_builder_text_chunk("mantle-claude", "world.", finish_reason="stop"),
+ usage_chunk,
+ ]
+
+ response: Final = litellm.stream_chunk_builder(chunks=chunks, messages=[{"role": "user", "content": "hi"}])
+
+ assert response is not None
+ assert response.usage.prompt_tokens == 20
+ assert response.usage.completion_tokens == 60
+ assert getattr(response.usage, "cost", None) == pytest.approx(0.000704)
+ assert response._hidden_params["response_cost"] == pytest.approx(0.000704)
+
+
+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