Registry /
llm-agents / llama-index-llms-mistralai
Install & Compatibility
Where this runs
tested against v0.10.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 5.378s · 253.4MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 20.9s · import 4.893s · 250MB
265MB installed
● package 265MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
MistralAI
✓ from llama_index.llms.mistralai import MistralAI
✗ from llama_index.llms import MistralAI
Prior to LlamaIndex v0.10.x, many LLM integrations were imported directly from `llama_index.llms`. With the modularization, specific integrations are now imported from their dedicated sub-packages, e.g., `llama_index.llms.mistralai`.
This quickstart demonstrates how to initialize the Mistral AI LLM, set the API key, and perform both text completion and chat interactions using the `llama-index-llms-mistralai` integration. It highlights the importance of setting the `MISTRAL_API_KEY` environment variable and shows how to select a specific Mistral model.
import os
from llama_index.llms.mistralai import MistralAI
from llama_index.core import Settings
# Ensure MISTRAL_API_KEY is set in your environment
# For local testing, you might do: os.environ["MISTRAL_API_KEY"] = "your_api_key_here"
api_key = os.environ.get('MISTRAL_API_KEY')
if not api_key:
raise ValueError("MISTRAL_API_KEY environment variable not set. Please set it to your Mistral AI API key.")
# Initialize the MistralAI LLM
llm = MistralAI(
model="mistral-tiny", # Choose your desired model, e.g., 'mistral-small', 'mistral-medium', 'mistral-large-latest'
api_key=api_key
)
# Optionally set as default LLM for LlamaIndex
Settings.llm = llm
# Use the LLM for completion
response = llm.complete("What is the capital of France?")
print(f"MistralAI LLM Response: {response.text}")
# Use the LLM for chat (if supported by model)
chat_response = llm.chat([
{"role": "user", "content": "What is your favorite color?"},
{"role": "assistant", "content": "As an AI, I don't have preferences. What's yours?"},
{"role": "user", "content": "Mine is blue."}
])
print(f"MistralAI Chat Response: {chat_response.message.content}")
Debug
Known issues
breakingLlamaIndex's rapid development cycle can lead to breaking changes in core components that might affect integrations. While `llama-index-llms-mistralai` aims to keep up, ensure compatibility with your `llama-index-core` version.fixAlways check the release notes for both `llama-index-core` and the integration package. Pin package versions in `requirements.txt` to avoid unexpected upgrades. Upgrade `llama-index-llms-mistralai` concurrently with `llama-index-core`.
affects: All versions, especially when upgrading `llama-index-core` to a new major or minor version.
gotchaThe `MISTRAL_API_KEY` environment variable must be set for the MistralAI LLM to authenticate correctly. Forgetting to set it or using an incorrect variable name is a common oversight.fixEnsure `MISTRAL_API_KEY` is correctly set in your environment before running your application. You can set it via `export MISTRAL_API_KEY='your_key'` in your terminal or `os.environ['MISTRAL_API_KEY'] = 'your_key'` in your Python code (though environment variables are preferred for production).
affects: All versions.
gotchaMistral AI offers various models (e.g., `mistral-tiny`, `mistral-small`, `mistral-medium`, `mistral-large-latest`). The `model` parameter expects specific string identifiers, and using an incorrect or deprecated model name will result in an API error.fixRefer to the official Mistral AI documentation or the LlamaIndex integration documentation for the latest list of available model names. Ensure the chosen model supports the desired functionality (e.g., chat vs. completion).
affects: All versions.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'mistralai'
The underlying `mistralai` Python client library, which is a dependency for `llama-index-llms-mistralai`, has not been installed.
fixInstall the `mistralai` package: `pip install mistralai`.
ValueError: MISTRAL_API_KEY environment variable not set. Please set it to your Mistral AI API key.
The `MistralAI` LLM initialization requires the API key, which by default is read from the `MISTRAL_API_KEY` environment variable. This error occurs when the variable is missing or empty.
fixSet the environment variable `MISTRAL_API_KEY` to your valid Mistral AI API key. Example: `export MISTRAL_API_KEY='YOUR_KEY_HERE'` in your shell or pass it directly `MistralAI(api_key="YOUR_KEY")`.
mistralai.exceptions.MistralException: Model 'non-existent-model' not found.
You have specified a model name in the `MistralAI` constructor that does not exist or is not valid for the Mistral AI API.
fixCheck the Mistral AI documentation for the correct and current list of available model identifiers (e.g., `mistral-tiny`, `mistral-small`, `mistral-medium`, `mistral-large-latest`).
Upgrade
Version history
0.10.2latest on PyPI · released May 4, 2026
Audit
Dependencies
llama-index-corerequiredRequired as the base framework for LlamaIndex LLM integrations.
mistralairequiredThe official Mistral AI client library used by this integration to interact with Mistral API.