{"id":9898,"library":"llama-index-llms-mistralai","title":"LlamaIndex Mistral AI LLM Integration","description":"This library provides the integration for Mistral AI's Large Language Models (LLMs) within the LlamaIndex framework. It allows LlamaIndex applications to leverage Mistral AI's powerful models for tasks like text completion and chat. The current version is 0.10.1, and being part of the LlamaIndex ecosystem, it follows a relatively rapid release cadence, often aligning with LlamaIndex core updates.","status":"active","version":"0.10.1","language":"en","source_language":"en","source_url":"https://github.com/run-llama/llama_index/tree/main/llama-index-integrations/llms/llama-index-llms-mistralai","tags":["llamaindex","llm","mistralai","ai","generative-ai"],"install":[{"cmd":"pip install llama-index-llms-mistralai","lang":"bash","label":"Install package"}],"dependencies":[{"reason":"Required as the base framework for LlamaIndex LLM integrations.","package":"llama-index-core"},{"reason":"The official Mistral AI client library used by this integration to interact with Mistral API.","package":"mistralai"}],"imports":[{"note":"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`.","wrong":"from llama_index.llms import MistralAI","symbol":"MistralAI","correct":"from llama_index.llms.mistralai import MistralAI"}],"quickstart":{"code":"import os\nfrom llama_index.llms.mistralai import MistralAI\nfrom llama_index.core import Settings\n\n# Ensure MISTRAL_API_KEY is set in your environment\n# For local testing, you might do: os.environ[\"MISTRAL_API_KEY\"] = \"your_api_key_here\"\napi_key = os.environ.get('MISTRAL_API_KEY')\n\nif not api_key:\n    raise ValueError(\"MISTRAL_API_KEY environment variable not set. Please set it to your Mistral AI API key.\")\n\n# Initialize the MistralAI LLM\nllm = MistralAI(\n    model=\"mistral-tiny\", # Choose your desired model, e.g., 'mistral-small', 'mistral-medium', 'mistral-large-latest'\n    api_key=api_key\n)\n\n# Optionally set as default LLM for LlamaIndex\nSettings.llm = llm\n\n# Use the LLM for completion\nresponse = llm.complete(\"What is the capital of France?\")\nprint(f\"MistralAI LLM Response: {response.text}\")\n\n# Use the LLM for chat (if supported by model)\nchat_response = llm.chat([\n    {\"role\": \"user\", \"content\": \"What is your favorite color?\"},\n    {\"role\": \"assistant\", \"content\": \"As an AI, I don't have preferences. What's yours?\"},\n    {\"role\": \"user\", \"content\": \"Mine is blue.\"}\n])\nprint(f\"MistralAI Chat Response: {chat_response.message.content}\")","lang":"python","description":"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."},"warnings":[{"fix":"Always 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`.","message":"LlamaIndex'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.","severity":"breaking","affected_versions":"All versions, especially when upgrading `llama-index-core` to a new major or minor version."},{"fix":"Ensure `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).","message":"The `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.","severity":"gotcha","affected_versions":"All versions."},{"fix":"Refer 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).","message":"Mistral 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.","severity":"gotcha","affected_versions":"All versions."}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install the `mistralai` package: `pip install mistralai`.","cause":"The underlying `mistralai` Python client library, which is a dependency for `llama-index-llms-mistralai`, has not been installed.","error":"ModuleNotFoundError: No module named 'mistralai'"},{"fix":"Set 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\")`.","cause":"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.","error":"ValueError: MISTRAL_API_KEY environment variable not set. Please set it to your Mistral AI API key."},{"fix":"Check 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`).","cause":"You have specified a model name in the `MistralAI` constructor that does not exist or is not valid for the Mistral AI API.","error":"mistralai.exceptions.MistralException: Model 'non-existent-model' not found."}]}