Install & Compatibility
Where this runs
tested against v1.1.6 · 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.95 runs
installs and imports cleanly · install 0.0s · import 2.538s · 119.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 9.1s · import 2.366s · 110MB
116MB installed
● package 116MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ChatMistralAI
✓ from langchain_mistralai import ChatMistralAI
✗ from langchain.chat_models import ChatMistralAI
Following LangChain's modularization (post v0.1.0 and v1.0), chat models are imported directly from their respective integration packages, not the top-level `langchain` package.
MistralAIEmbeddings
✓ from langchain_mistralai import MistralAIEmbeddings
✗ from langchain.embeddings import MistralAIEmbeddings
Similar to chat models, embedding models are imported from their dedicated integration packages after LangChain's modular updates.
This quickstart demonstrates how to initialize `ChatMistralAI` and use it to invoke a chat completion. It emphasizes setting the `MISTRAL_API_KEY` environment variable for authentication, which is crucial for interacting with the Mistral API.
import os
from langchain_mistralai import ChatMistralAI
from langchain_core.messages import HumanMessage, SystemMessage
# Ensure MISTRAL_API_KEY is set in your environment
# Example: os.environ['MISTRAL_API_KEY'] = 'your_mistral_api_key'
# For quickstart, we use os.environ.get with a default empty string for CI/CD environments.
# In production, ensure the key is properly set.
mistral_api_key = os.environ.get('MISTRAL_API_KEY', '')
if not mistral_api_key:
print("Warning: MISTRAL_API_KEY environment variable not set. Please set it to run the example.")
else:
chat = ChatMistralAI(
model="mistral-large-latest",
temperature=0,
mistral_api_key=mistral_api_key # Pass key directly or rely on env var
)
messages = [
SystemMessage(content="You are a helpful assistant that translates English to French."),
HumanMessage(content="I love programming."),
]
try:
response = chat.invoke(messages)
print(response.content)
except Exception as e:
print(f"An error occurred: {e}")
Debug
Known issues
gotchaAPI Key Management: Always ensure your `MISTRAL_API_KEY` is correctly set as an environment variable or passed explicitly to the model constructor. Forgetting to set it or providing an invalid key will result in authentication errors.fixSet `os.environ['MISTRAL_API_KEY'] = 'your_key'` before initialization, or pass `mistral_api_key='your_key'` to the `ChatMistralAI` or `MistralAIEmbeddings` constructor.
affects: All versions
breakingLangChain Modularization and Import Paths: LangChain underwent significant architectural changes, particularly with versions 0.1.0 and 1.0. Older tutorials or code snippets might use deprecated import paths (e.g., `from langchain.llms import MistralAI`). Always use the dedicated integration package for imports, like `from langchain_mistralai import ChatMistralAI`.fixUpdate import statements to reflect the modular structure of LangChain, importing directly from `langchain_mistralai` for Mistral-specific components. Refer to the official LangChain documentation for the correct import paths.
affects: Versions < 0.1.0 (for old `langchain` package imports), 0.1.0 onwards (for modular imports)
gotchaMistral API 400 Errors for Chat/Embeddings: Encountering `httpx.HTTPStatusError: Error response 400` can indicate various issues, including invalid request parameters, rate limiting, or malformed input. For chat models, ensure messages alternate between 'human' and 'assistant' and do not end with an 'assistant' or 'system' message, and that assistant messages don't have both content and tool_calls.fixReview API key validity, check for rate limits, validate input data format, and ensure message history adheres to the expected conversational structure for Mistral AI models. For embeddings, consider batching documents if processing large volumes.
affects: All versions
gotchaSilent Dropping of Citation Metadata in ChatMistralAI: When using Mistral's native citation feature (e.g., `citations=True` in the raw API), `ChatMistralAI` might currently treat the response content as a plain string, potentially dropping detailed citation metadata (references, source mapping).fixIf citation details are critical for RAG, consider accessing the Mistral AI SDK directly or implementing a post-processing step to re-parse the raw API response until an official fix is released in `langchain-mistralai`. Monitor issue #36427 on GitHub for updates.
affects: Versions prior to a fix for #36427 (as of April 2026, this is an open issue).
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'langchain_mistralai'
The 'langchain-mistralai' package is not installed.
fixInstall the package using 'pip install langchain-mistralai'.
ImportError: cannot import name 'ChatMistralAI' from 'langchain_mistralai'
Incorrect import statement; 'ChatMistralAI' is located in the 'chat_models' submodule.
fixUse 'from langchain_mistralai.chat_models import ChatMistralAI'.
ValueError: Model mistralai/Mistral-7B-Instruct-v0.2 is not supported for task text-generation and provider featherless-ai. Supported task: conversational.
The specified model is configured for the 'conversational' task, but the code requests 'text-generation'.
fixEnsure the model and task are compatible; consider using a model that supports 'text-generation' or adjust the task to 'conversational'.
KeyError: 'MISTRAL_API_KEY'
The 'MISTRAL_API_KEY' environment variable is not set.
fixSet the environment variable using 'export MISTRAL_API_KEY="your-api-key"' or set it programmatically in your code.
from langchain_mistralai import chatmistralai
The class name `ChatMistralAI` uses PascalCase, but it's being imported with an incorrect lowercase or snake_case name.
fixfrom langchain_mistralai import ChatMistralAI
Upgrade
Version history
1.1.6latest on PyPI · released Jul 5, 2026
Audit
Dependencies
langchain-corerequiredAll LangChain integration packages depend on langchain-core for core functionalities and abstractions.
mistralairequiredThis package is an integration layer and directly uses the official Mistral AI SDK.