Skip to content

Mistral AI

Mistral AI is a research lab building the best open source models in the world.

Mistral AI offers both premier models and free models, driving innovation and convenience for the developer community. Mistral AI models are state-of-the-art for their multilingual, code generation, maths, and advanced reasoning capabilities.

Mistral API is configured as an optional dependency in Strands Agents. To install, run:

Terminal window
pip install 'strands-agents[mistral]' strands-agents-tools

After installing mistral, you can import and initialize Strands Agents’ Mistral API provider as follows:

from strands import Agent
from strands.models.mistral import MistralModel
from strands_tools import calculator
model = MistralModel(
api_key="<YOUR_MISTRAL_API_KEY>",
# **model_config
model_id="mistral-large-latest",
)
agent = Agent(model=model, tools=[calculator])
response = agent("What is 2+2")
print(response)

The client_args configure the underlying Mistral client. You can pass additional arguments to customize the client behavior:

model = MistralModel(
api_key="<YOUR_MISTRAL_API_KEY>",
client_args={
"timeout": 30,
# Additional client configuration options
},
model_id="mistral-large-latest"
)

For a complete list of available client arguments, please refer to the Mistral AI documentation.

The model_config configures the underlying model selected for inference. The supported configurations are:

ParameterDescriptionExampleOptions
model_idID of a Mistral model to usemistral-large-latestreference
max_tokensMaximum number of tokens to generate in the response1000Positive integer
temperatureControls randomness in generation (0.0 to 1.0)0.7Float between 0.0 and 1.0
top_pControls diversity via nucleus sampling0.9Float between 0.0 and 1.0
streamWhether to enable streaming responsestruetrue or false

You can set your Mistral API key as an environment variable instead of passing it directly:

Terminal window
export MISTRAL_API_KEY="your_api_key_here"

Then initialize the model without the API key parameter:

model = MistralModel(model_id="mistral-large-latest")

If you encounter the error ModuleNotFoundError: No module named 'mistralai', this means you haven’t installed the mistral dependency in your environment. To fix, run pip install 'strands-agents[mistral]'.