Skip to main content

Mistral AI API

https://docs.mistral.ai/api/

API Key​

# env variable
os.environ['MISTRAL_API_KEY']

Sample Usage​

from litellm import completion
import os

os.environ['MISTRAL_API_KEY'] = ""
response = completion(
model="mistral/mistral-tiny",
messages=[
{"role": "user", "content": "hello from litellm"}
],
)
print(response)

Sample Usage - Streaming​

from litellm import completion
import os

os.environ['MISTRAL_API_KEY'] = ""
response = completion(
model="mistral/mistral-tiny",
messages=[
{"role": "user", "content": "hello from litellm"}
],
stream=True
)

for chunk in response:
print(chunk)

Usage with LiteLLM Proxy​

1. Set Mistral Models on config.yaml​

model_list:
- model_name: mistral-small-latest
litellm_params:
model: mistral/mistral-small-latest
api_key: "os.environ/MISTRAL_API_KEY" # ensure you have `MISTRAL_API_KEY` in your .env

2. Start Proxy​

litellm --config config.yaml

3. Test it​

curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Content-Type: application/json' \
--data ' {
"model": "mistral-small-latest",
"messages": [
{
"role": "user",
"content": "what llm are you"
}
]
}
'

Supported Models​

info

All models listed here https://docs.mistral.ai/platform/endpoints are supported. We actively maintain the list of models, pricing, token window, etc. here.

Model NameFunction CallReasoning Support
Mistral Smallcompletion(model="mistral/mistral-small-latest", messages)No
Mistral Mediumcompletion(model="mistral/mistral-medium-latest", messages)No
Mistral Large 2completion(model="mistral/mistral-large-2407", messages)No
Mistral Large Latestcompletion(model="mistral/mistral-large-latest", messages)No
Magistral Smallcompletion(model="mistral/magistral-small-2506", messages)Yes
Magistral Mediumcompletion(model="mistral/magistral-medium-2506", messages)Yes
Mistral 7Bcompletion(model="mistral/open-mistral-7b", messages)No
Mixtral 8x7Bcompletion(model="mistral/open-mixtral-8x7b", messages)No
Mixtral 8x22Bcompletion(model="mistral/open-mixtral-8x22b", messages)No
Codestralcompletion(model="mistral/codestral-latest", messages)No
Mistral NeMocompletion(model="mistral/open-mistral-nemo", messages)No
Mistral NeMo 2407completion(model="mistral/open-mistral-nemo-2407", messages)No
Codestral Mambacompletion(model="mistral/open-codestral-mamba", messages)No
Codestral Mambacompletion(model="mistral/codestral-mamba-latest"", messages)No

Function Calling​

from litellm import completion

# set env
os.environ["MISTRAL_API_KEY"] = "your-api-key"

tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
},
}
]
messages = [{"role": "user", "content": "What's the weather like in Boston today?"}]

response = completion(
model="mistral/mistral-large-latest",
messages=messages,
tools=tools,
tool_choice="auto",
)
# Add any assertions, here to check response args
print(response)
assert isinstance(response.choices[0].message.tool_calls[0].function.name, str)
assert isinstance(
response.choices[0].message.tool_calls[0].function.arguments, str
)

Reasoning​

Mistral does not directly support reasoning, instead it recommends a specific system prompt to use with their magistral models. By setting the reasoning_effort parameter, LiteLLM will prepend the system prompt to the request.

If an existing system message is provided, LiteLLM will send both as a list of system messages (you can verify this by enabling litellm._turn_on_debug()).

Supported Models​

Model NameFunction Call
Magistral Smallcompletion(model="mistral/magistral-small-2506", messages)
Magistral Mediumcompletion(model="mistral/magistral-medium-2506", messages)

Using Reasoning Effort​

The reasoning_effort parameter controls how much effort the model puts into reasoning. When used with magistral models.

from litellm import completion
import os

os.environ['MISTRAL_API_KEY'] = "your-api-key"

response = completion(
model="mistral/magistral-medium-2506",
messages=[
{"role": "user", "content": "What is 15 multiplied by 7?"}
],
reasoning_effort="medium" # Options: "low", "medium", "high"
)

print(response)

Example with System Message​

If you already have a system message, LiteLLM will prepend the reasoning instructions:

response = completion(
model="mistral/magistral-medium-2506",
messages=[
{"role": "system", "content": "You are a helpful math tutor."},
{"role": "user", "content": "Explain how to solve quadratic equations."}
],
reasoning_effort="high"
)

# The system message becomes:
# "When solving problems, think step-by-step in <think> tags before providing your final answer...
#
# You are a helpful math tutor."

Usage with LiteLLM Proxy​

You can also use reasoning capabilities through the LiteLLM proxy:

curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Content-Type: application/json' \
--data '{
"model": "magistral-medium-2506",
"messages": [
{
"role": "user",
"content": "What is the square root of 144? Show your reasoning."
}
],
"reasoning_effort": "medium"
}'

Important Notes​

  • Model Compatibility: Reasoning parameters only work with magistral models
  • Backward Compatibility: Non-magistral models will ignore reasoning parameters and work normally

Audio Transcription​

Use Mistral's Voxtral models for audio transcription via litellm.transcription().

SDK Usage​

from litellm import transcription
import os

os.environ["MISTRAL_API_KEY"] = ""

audio_file = open("path/to/audio.wav", "rb")

response = transcription(
model="mistral/voxtral-mini-latest",
file=audio_file,
)

print(response.text)

With Optional Parameters​

response = transcription(
model="mistral/voxtral-mini-latest",
file=audio_file,
language="en",
temperature=0.0,
response_format="json",
)

Mistral-Specific Parameters​

Mistral supports additional parameters beyond the OpenAI-compatible ones:

ParameterTypeDescription
diarizeboolEnable speaker diarization
response = transcription(
model="mistral/voxtral-mini-latest",
file=audio_file,
diarize=True,
)

Usage with LiteLLM Proxy​

model_list:
- model_name: voxtral
litellm_params:
model: mistral/voxtral-mini-latest
api_key: os.environ/MISTRAL_API_KEY
model_info:
mode: audio_transcription
litellm --config /path/to/config.yaml
curl --location 'http://0.0.0.0:4000/v1/audio/transcriptions' \
--header "Authorization: Bearer $LITELLM_API_KEY" \
--form 'file=@"audio.wav"' \
--form 'model="voxtral"'

Text to Speech​

Mistral's Voxtral TTS models turn text into audio through litellm.speech() and the proxy's /v1/audio/speech route. Both mistral/voxtral-mini-tts-2603 and mistral/voxtral-mini-tts-latest are supported. Available from v1.102.0.

SDK Usage​

from litellm import speech
import os

os.environ["MISTRAL_API_KEY"] = ""

response = speech(
model="mistral/voxtral-mini-tts-2603",
input="The quick brown fox jumped over the lazy dog.",
voice="alloy",
)

response.write_to_file("speech.mp3")

Voices​

voice takes either an OpenAI voice name or a native Mistral voice id. LiteLLM maps these six OpenAI names onto Mistral voices, so an integration that uses one of them keeps working without a change:

OpenAI voiceMistral voice
alloyen_paul_neutral
echogb_oliver_neutral
fableen_paul_cheerful
onyxen_paul_confident
novagb_jane_sarcasm
shimmergb_jane_sarcasm

Any other value passes through to Mistral untouched, so a native id such as en_paul_excited works as-is. Newer OpenAI voices such as coral or ash are not mapped, and Mistral answers them, like any voice it does not know, with a 404 invalid_voice error. nova and shimmer both map to a sarcastic voice, so pass gb_jane_neutral directly when you want a neutral female voice. GET https://api.mistral.ai/v1/audio/voices?limit=100 lists the voices your account can use. The endpoint is paginated and returns 10 voices when you leave limit out.

Response Formats​

response_format accepts mp3, wav, pcm, flac, and opus, and defaults to mp3 when you leave it out. LiteLLM sets the response content-type to match the format you asked for, so opus comes back as audio/ogg and the other four as audio/mpeg, audio/wav, audio/pcm, and audio/flac. OpenAI's aac format is not supported, and Mistral rejects it with a 422. Mistral's pcm is raw 32-bit float little-endian samples at 24 kHz mono, not the 16-bit signed samples OpenAI's pcm returns, so read it as float32 or ask for wav instead.

Voice Cloning​

Pass a base64 encoded audio sample as ref_audio, and Voxtral speaks the input in the sampled voice:

import base64
from litellm import speech

with open("sample.wav", "rb") as sample:
ref_audio = base64.b64encode(sample.read()).decode()

response = speech(
model="mistral/voxtral-mini-tts-2603",
input="This sentence comes back in the sampled voice.",
ref_audio=ref_audio,
)

response.write_to_file("cloned.mp3")

On the proxy, send the same ref_audio field in the JSON body of /v1/audio/speech. When a request also carries a voice, including a default voice set on the deployment, Mistral uses ref_audio, so a client that requires voice, such as the OpenAI SDK, can pass any voice and send ref_audio through extra_body.

Unsupported Parameters​

Mistral's speech API rejects speed and instructions with a 422, so LiteLLM drops both before sending the request instead of failing it. A call that passes either one still returns audio, generated from the parameters Mistral does accept.

Usage with LiteLLM Proxy​

model_list:
- model_name: voxtral-tts
litellm_params:
model: mistral/voxtral-mini-tts-2603
api_key: os.environ/MISTRAL_API_KEY
litellm --config /path/to/config.yaml
curl --location 'http://0.0.0.0:4000/v1/audio/speech' \
--header "Authorization: Bearer $LITELLM_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "voxtral-tts",
"input": "The quick brown fox jumped over the lazy dog.",
"voice": "alloy"
}' \
--output speech.mp3

Cost Tracking​

Voxtral TTS is priced per input character, at the input_cost_per_character rate in the model cost map. LiteLLM counts the non-whitespace characters of input, so a 19 character sentence holding 2 spaces is tracked as 17 characters. Mistral's own character meter, reported in the x-ratelimit-input-characters-query-cost response header, counts the spaces too, so whenever input contains whitespace, the spend LiteLLM tracks is lower than what Mistral meters.

Files and Batches API​

LiteLLM routes the OpenAI-compatible /v1/files and /v1/batches endpoints to Mistral's Files and Batch APIs. See Mistral AI Batch API for the full flow and cost tracking.

Sample Usage - Embedding​

from litellm import embedding
import os

os.environ['MISTRAL_API_KEY'] = ""
response = embedding(
model="mistral/mistral-embed",
input=["good morning from litellm"],
)
print(response)

Supported Models​

All models listed here https://docs.mistral.ai/platform/endpoints are supported

Model NameFunction Call
Mistral Embeddingsembedding(model="mistral/mistral-embed", input)