Skip to main content
You are currently on a page documenting the use of Mistral models as text completion models. Many popular models available on Mistral are chat completion models.You may be looking for this page instead.
Want to run Mistral’s models locally? Check out our Ollama integration.
Mistral AI is a platform that offers hosting for their powerful open source models. This will help you get started with MistralAI completion models (LLMs) using LangChain. For detailed documentation on MistralAI features and configuration options, please refer to the API reference.

Overview

Integration details

Setup

To access MistralAI models you’ll need to create a MistralAI account, get an API key, and install the @langchain/mistralai integration package.

Credentials

Head to console.mistral.ai to sign up to MistralAI and generate an API key. Once you’ve done this set the MISTRAL_API_KEY environment variable:
If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:

Installation

The LangChain MistralAI integration lives in the @langchain/mistralai package:

Instantiation

Now you can instantiate the model and generate text completions:

Invocation

Hooks

Mistral AI supports custom hooks for three events: beforeRequest, requestError, and response. Examples of the function signature for each hook type can be seen below:
To add these hooks to the model, either pass them as arguments and they are automatically added:
Or assign and add them manually after instantiation:
The method addAllHooksToHttpClient clears all currently added hooks before assigning the entire updated hook lists to avoid hook duplication. Hooks can be removed one at a time, or all hooks can be cleared from the model at once.

API reference

For detailed documentation of all MistralAI features and configurations head to the API reference.