Repository navigation
feat(mistral): add text-to-speech support for /v1/audio/speech - #38755
Conversation
Greptile SummaryThis PR adds Mistral Voxtral text-to-speech support through the shared speech transport.
Confidence Score: 5/5The PR appears safe to merge; no new actionable issue remains in the Mistral speech path. The adapter uses the shared HTTP handler, strictly validates encoded audio, preserves upstream error handling, supports optional and deployment-default voices, and has aligned input-character pricing and focused tests. All previous Greptile threads are resolved, including two findings Greptile explicitly withdrew.
|
| Filename | Overview |
|---|---|
| litellm/llms/mistral/audio_speech/transformation.py | Implements Mistral TTS request, authentication, URL, voice alias, response decoding, header, and error transformations using the shared transport. |
| litellm/main.py | Dispatches Mistral speech calls through the new provider adapter and shared text-to-speech handler. |
| litellm/router.py | Allows speech calls without an explicit voice while preserving a deployment-configured default. |
| litellm/utils.py | Registers the Mistral text-to-speech adapter with the provider configuration manager. |
| model_prices_and_context_window.json | Moves Voxtral TTS pricing to input-character accounting. |
| tests/test_litellm/llms/mistral/audio_speech/test_mistral_audio_speech_transformation.py | Covers parameter mapping, URL construction, credentials, request generation, binary decoding, voice aliases, and strict base64 validation. |
Reviews (12): Last reviewed commit: "chore: merge litellm_internal_staging in..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
bugbot run |
# Conflicts: # tests/test_litellm/test_router.py
…itellm_mistral_voxtral_tts_speech
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: TTS URL omits required /v1
- get_complete_url now normalizes the resolved base by appending /v1 when missing (matching the OCR/chat convention) so host-only api_base or MISTRAL_API_BASE values yield /v1/audio/speech.
Or push these changes by commenting:
@cursor push 04f9904f69
Preview (04f9904f69)
diff --git a/litellm/llms/mistral/audio_speech/transformation.py b/litellm/llms/mistral/audio_speech/transformation.py
--- a/litellm/llms/mistral/audio_speech/transformation.py
+++ b/litellm/llms/mistral/audio_speech/transformation.py
@@ -115,8 +115,9 @@
api_base: str | None,
litellm_params: Mapping[str, object],
) -> str:
- base_url: Final = api_base or get_secret_str("MISTRAL_API_BASE") or self.TTS_BASE_URL
- return f"{base_url.rstrip('/')}/audio/speech"
+ base_url: Final = (api_base or get_secret_str("MISTRAL_API_BASE") or self.TTS_BASE_URL).rstrip("/")
+ normalized_base: Final = base_url if base_url.endswith("/v1") else f"{base_url}/v1"
+ return f"{normalized_base}/audio/speech"
def transform_text_to_speech_request(
self,
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
--- 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
@@ -101,6 +101,24 @@
assert url == "https://custom.api.example.com/v1/audio/speech"
+def test_get_complete_url_host_only_base_adds_v1(monkeypatch: pytest.MonkeyPatch):
+ monkeypatch.delenv("MISTRAL_API_BASE", raising=False)
+ config: Final = MistralTextToSpeechConfig()
+ url: Final = config.get_complete_url(
+ model="voxtral-mini-tts-2603",
+ api_base="https://custom.api.example.com",
+ litellm_params={},
+ )
+ assert url == "https://custom.api.example.com/v1/audio/speech"
+
+
+def test_get_complete_url_env_base_without_v1_adds_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(You can send follow-ups to the cloud agent here.
A host-only api_base or MISTRAL_API_BASE (the documented form, https://api.mistral.ai) built https://api.mistral.ai/audio/speech and 404ed. Match the chat and OCR configs by appending /v1 when the configured base does not already end with it.
|
bugbot run |
…itellm_mistral_voxtral_tts_speech Resolves the tests/test_litellm/test_main.py collision, where both sides appended a new test at the end of the file, by keeping both. Also carries the one-line fix from #39502: staging arrived with a duplicate embedding_executor kwarg in the Bedrock KB fake handler, which ruff rejects as a syntax error, so every commit here would otherwise fail lint. The change is byte identical to #39502, so that PR merges cleanly once it lands.
|
bugbot run |
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
…itellm_mistral_voxtral_tts_speech
|
bugbot run |
|
bugbot run |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 5825cc7. Configure here.
1c7b13b
into
litellm_internal_staging

TLDR
Problem this solves:
/v1/audio/speechwith a 500How it solves it:
POST /v1/audio/speechat api.mistral.aivoiceto Mistralvoice_id, dropsspeed/instructions(Mistral 422s on them)alloy,nova, ...) to real Mistral voicesvoiceoptional onrouter.aspeechsoref_audiovoice cloning works, and leaves a deployment's configuredvoicealone when the caller omits oneUser Flow
Before: a developer who routes Mistral through LiteLLM gets a 500 on every text-to-speech call, while transcription with the same key works
mistral/voxtral-mini-tts-2603to their proxy's model list and start the proxy{"model": "voxtral-mini-tts-2603", "input": "hello", "voice": "en_paul_neutral"}{"error": {"message": "Internal server error", "type": "internal_server_error"}}, and the proxy log shows "Unable to map the custom llm provider=mistral to a known provider"voxtral-mini-2602returns 200 with the spoken textAfter: the same speech call returns playable audio with real spend attached
mistral/voxtral-mini-tts-2603to their proxy's model list and start the proxy{"model": "voxtral-mini-tts-2603", "input": "hello", "voice": "en_paul_neutral"}x-litellm-response-costheader; sending"response_format": "wav"returns WAV instead"voice": "alloy"(the OpenAI default many clients hardcode) also returns audio instead of a Mistral 400 about an unknown voicevoiceon the deployment itself, leavingvoiceout of the request uses that configured voice rather than failingRelevant issues
Linear ticket
Resolves LIT-6367
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
QA run at the PR tip
93fa989238(withlitellm_internal_stagingmerged in atdf3b8a699d) against that merge basedf3b8a699d. Both legs ran the same way: own worktree and.venv(make bootstrap), 2 uvicorn workers, own Postgres container, real Mistral and OpenAI keys, the same config and the same 16 steps in the same order. Env vars:OPENAI_API_KEY,MISTRAL_API_KEY,LITELLM_MASTER_KEY=sk-lit6367drive,LITELLM_LOCAL_MODEL_COST_MAP=True,DATABASE_URL. Boot, with the worktree's.venv/binprepended toPATHso the prisma migrations run:Every step below uses
H='Authorization: Bearer sk-lit6367drive'andJ='Content-Type: application/json',$Sis the leg's scratch dir, and every speech input ishello there(11 characters, 10 without the space). Each speech step is the same curl shape, followed by the response headers andfileon the saved body:Before (df3b8a6, the merge base, port 41842)
Steps 1 to 5, 12 and 13, every Mistral speech call with a
voice:All seven came back the same way (6289 to 6294 bytes, only the
Model Groupdiffers), no cost or model-id header:Step 6a, reference audio from the OpenAI control model:
-d '{"model":"tts-1","input":"hello there","voice":"alloy","response_format":"wav"}'Steps 6b (voice cloning:
ref_audio= standard base64 ofref.wav, novoice), 7 (deployment default voice, novoicein the request), 8 (novoice, noref_audio) and 10 (OpenAItts-1, novoice):All four:
Step 9, OpenAI control:
-d '{"model":"tts-1","input":"hello there","voice":"alloy"}'Step 11, transcription control with the same key:
After (93fa989, the PR tip, port 25589)
Step 1, default format:
-d '{"model":"voxtral-mini-tts-2603","input":"hello there","voice":"en_paul_neutral"}'Step 2,
response_format: mp3:-d '{"model":"voxtral-mini-tts-2603","input":"hello there","voice":"en_paul_neutral","response_format":"mp3"}'Step 3,
voxtral-mini-tts-latestas wav:-d '{"model":"voxtral-mini-tts-latest","input":"hello there","voice":"en_paul_neutral","response_format":"wav"}'Step 4, the OpenAI voice name
alloyon the Mistral model:-d '{"model":"voxtral-mini-tts-2603","input":"hello there","voice":"alloy"}'Step 5, deployment with
api_base: https://api.mistral.ai(no/v1):-d '{"model":"voxtral-tts-hostbase","input":"hello there","voice":"en_paul_neutral"}'Step 6a, reference audio from the OpenAI control model:
-d '{"model":"tts-1","input":"hello there","voice":"alloy","response_format":"wav"}'Step 6b, voice cloning with
ref_audio(standard base64 ofref.wav, 36860 chars, no newlines) and novoice:Step 7, deployment default voice, no
voicein the request:-d '{"model":"voxtral-tts-default-voice","input":"hello there"}'Step 8, no
voiceand noref_audio(Mistral's own 400 now comes through as a 400):-d '{"model":"voxtral-mini-tts-2603","input":"hello there"}'Step 9, OpenAI control:
-d '{"model":"tts-1","input":"hello there","voice":"alloy"}'Step 10, OpenAI with no
voice(the OpenAI branch's own 400 instead of the Router TypeError):-d '{"model":"tts-1","input":"hello there"}'Step 11, transcription control, unchanged:
Step 12, upstream error with a bad key:
-d '{"model":"voxtral-tts-badkey","input":"hello there","voice":"en_paul_neutral"}'Step 13, upstream error with an unknown voice:
-d '{"model":"voxtral-mini-tts-2603","input":"hello there","voice":"totally_not_a_voice_id"}'Spend attribution (step 14, both legs, 20 seconds after step 13)
Before (4 rows: the transcription, the two OpenAI calls, and a single failure row for all eleven failed speech calls):
After (11 rows, newest first: steps 11, 9, 8, 7, 6b, 6a, 5, 4, 3, 2, 1; every successful Mistral speech call carries 0.00016 spend):
Health check (step 15, both legs)
Present in the config from the first boot of each leg (so step 15 ran against the same 2 workers as every other step, no restart):
Before:
After:
Model info (step 16, both legs)
Blast radius (live-pr-risk at 93fa989)
Breaking: none observed. Every path that worked at the merge base (OpenAI speech, transcription, spend rows, health, model info) answers the same way at the tip
Backward incompatible:
Router.aspeech/Router._aspeechtakevoice: str | None = Noneinstead of a requiredstr(a loosening; a request-level voice still wins, and when the request passes none the deployment's configuredvoiceis forwarded instead ofNone, so a deployment default survives), and the twomistral/voxtral-mini-tts-*cost-map entries move their price fromoutput_cost_per_charactertoinput_cost_per_character(the speech cost path bills characters of input withcustom_completion_cost=0, so the old key was never applied to a speech call;/model/infonow reports it under the new key, and no dashboard code reads either key)Dependency graph: proxy
POST /v1/audio/speech->Router.aspeech->litellm.aspeech->speech()mistral branch (tested by the PR's router and main tests, verified live in steps 1 to 8, 10); the health check helper's directlitellm.aspeechcall inaudio_speechmode (untested for mistral, verified live in step 15); the cost pathcost_calculator->_generic_cost_per_character(tested bytest_cost_calculator, verified live through the cost header and/spend/logs); theget_model_info//model/infowire contract (verified live in step 16); the other TTS branches inspeech()(untouched, OpenAI verified live in steps 6a, 9, 10);ProviderConfigManager.get_provider_text_to_speech_config(single caller, tested); no subclass overridesRouter.aspeech; the legacytests/llm_translationandtests/local_testingsuites pin nothing this PR changes, and CircleCI ran them at the tipNot verified: none
Observations
Type
🆕 New Feature
Caveats (if any)
Low
speedandinstructionsare dropped silently instead of raising. Net negative to fix: every shipped TTS config (OpenAI-compatible, Azure, Vertex, ElevenLabs, MiniMax, Polly, Runway) maps or drops unsupported params the same way and none raisesUnsupportedParamsError,speech()hardcodesdrop_params=Falsefor every provider, and raising here would make Mistral the one provider that errors on a defaultspeedmany OpenAI clients always send; honoringdrop_paramsfor TTS is a shared-layer change for a separate PRwith_streaming_response) is not wired for Mistral: the response is fully buffered before it is returned. Mistral's endpoint returns one JSON document with base64 audio, so there is nothing to stream through yetnovaandshimmerboth alias togb_jane_sarcasmbecause Mistral ships two English female voices and both were taken by the closer matches; pass a Mistralvoice_iddirectly for a specific voicemp3andwavwent through the proxy legs above; the other three formats were verified directly againsthttps://api.mistral.ai/v1/audio/speechwith the same key and payload shape (flac-> FLAC 24 bit mono 24 kHz,pcm-> raw data,opus-> Ogg Opus mono 24 kHz, all 200, andaac-> 422 naming exactlypcm,wav,mp3,flac,opusas the accepted values)hello there); that is_count_charactersbehavior shared by every TTS provider, not this PR'sMISTRAL_API_BASEis not read by this path;api_baseinlitellm_params(or on the call) andMISTRAL_AZURE_API_BASEare, matching whatMistralConfigreads for chatvoicethat is not one of the six OpenAI aliases is forwarded to Mistral asvoice_idunchanged, the same way ElevenLabs forwards voice ids; Mistral answers 404invalid_voicefor an unknown one (step 13)usage: nullandsegments: []on both legs; pre-existing and untouched here/v1/audio/speech: LIT-7001 tracks the docs follow-up in the docs repoFinal Attestation
Reviewed at
93fa989238(the tip,litellm_internal_stagingmerged in atdf3b8a699d). All 33 required checks on the base branch's ruleset are green at that commit, includingproxy-infra / Run tests (Python 3.10), which went green once #39780 landed on staging (LIT-6947). One non-required job is red and it fails identically onlitellm_internal_stagingwithout this branch: therun-ciCircleCI pipeline 89157 at the tip (workflowec1f947d, 43 jobs, 42 green) has onlyproxy_store_model_in_db_testsred ontest_chat_completion_bad_model_with_spend_logs(assert '' == 'non-existent-model'), the same failure staging pipelines 89097 and 89104 show (LIT-6949); no CircleCI job is required and this branch touches neither that test nor failure spend logging. Greptile 5/5 and bugbot "no new issues" both at93fa989238, every review thread resolvedNote
Low Risk
Additive provider path with tests; the only behavioral broadening is optional
Router.aspeechvoice and a cost-map key rename for two Mistral TTS models.Overview
Adds Mistral Voxtral TTS so
litellm.speech/ proxy/v1/audio/speechcan call Mistral’sPOST /v1/audio/speechinstead of failing with an unmapped provider error.The new
MistralTextToSpeechConfigbuilds the JSON request (voice_id, optionalresponse_formatandref_audio), maps OpenAI-style voices (including aliases likealloy) to Mistral IDs, strips unsupported params such asspeed/instructions, and turns Mistral’s JSONaudio_datainto binary audio with the rightcontent-type.Router
aspeechnow accepts an optionalvoice: when omitted, the deployment’s configuredvoiceis used (needed forref_audiocloning without a voice argument).Pricing for
mistral/voxtral-mini-tts-*moves fromoutput_cost_per_charactertoinput_cost_per_characterso speech calls bill on input text length.Reviewed by Cursor Bugbot for commit 5825cc7. Bugbot is set up for automated code reviews on this repo. Configure here.