Mistral
Use Mistral models with Agno agents.
Mistral provides API endpoints for its large language models. See their library of models here.
We recommend experimenting to find the best-suited model for your use-case. Here are some general recommendations:
codestralmodel is good for code generation and editing.mistral-large-latestmodel is good for most use-cases.- For a smaller model, consult the current catalog. Mistral NeMo is deprecated; Mistral recommends Ministral 3 8B for new integrations.
ministral-14b-2512supports vision tasks such as OCR, document transcription, and image comparison.
Check your Mistral account for current usage limits and the pricing guide for hosted inference costs.
Installation
uv pip install -U mistralai agnoAuthentication
Set your MISTRAL_API_KEY environment variable. Get your key from here.
export MISTRAL_API_KEY="YOUR_API_KEY"Example
Use MistralChat with your Agent:
import os
from agno.agent import Agent
from agno.models.mistral import MistralChat
mistral_api_key = os.getenv("MISTRAL_API_KEY")
agent = Agent(
model=MistralChat(
id="mistral-large-latest",
api_key=mistral_api_key,
),
markdown=True
)
# Print the response in the terminal
agent.print_response("Share a 2 sentence horror story.")
Params
| Parameter | Type | Default | Description |
|---|---|---|---|
id | str | "mistral-large-latest" | The id of the Mistral model to use |
name | str | "MistralChat" | The name of the model |
provider | str | "Mistral" | The provider of the model |
temperature | Optional[float] | None | Controls randomness in the model's output |
max_tokens | Optional[int] | None | Maximum number of tokens to generate |
top_p | Optional[float] | None | Controls diversity via nucleus sampling |
random_seed | Optional[int] | None | Random seed for reproducibility |
safe_mode | bool | False | Legacy field; True is rejected by the current Mistral SDK. Leave False. |
safe_prompt | bool | False | Forward Mistral's legacy safety-prompt option; this is not an application guardrail. |
request_params | Optional[Dict[str, Any]] | None | Additional parameters for the request |
api_key | Optional[str] | None | The API key for Mistral (defaults to MISTRAL_API_KEY env var) |
endpoint | Optional[str] | None | Declared field rejected by Mistral SDK 2 when set. Leave None and use the current SDK configuration below. |
max_retries | Optional[int] | None | Declared field rejected by Mistral SDK 2 when set. Leave None and use the current SDK configuration below. |
timeout | Optional[int] | None | Declared field rejected by Mistral SDK 2 when set. Leave None and use the current SDK configuration below. |
client_params | Optional[Dict[str, Any]] | None | Additional parameters for client configuration |
mistral_client | Optional[Mistral] | None | A pre-configured Mistral client instance to use |
Configure the Mistral SDK
With Mistral SDK 2, pass supported constructor options through client_params while leaving endpoint, timeout and max_retries unset. For example, set a 15-second timeout and disable SDK retries:
model = MistralChat(
client_params={
"server_url": "https://api.mistral.ai",
"timeout_ms": 15000,
"retry_config": None,
},
)timeout_ms is in milliseconds. For custom retries, pass the SDK's RetryConfig object as retry_config; it is not an integer retry count. You can also supply a configured mistralai.client.Mistral through mistral_client. See the official Python SDK.
MistralChat is a subclass of the Model class and has access to the same params.