Mistral AI Provider

The Mistral AI provider contains language model support for the Mistral chat API. It creates language model objects that can be used with the generateText, streamText, generateObject, and streamObject AI functions.

Setup

The Mistral provider is available in the @ai-sdk/mistral module. You can install it with

pnpm
npm
yarn
pnpm install @ai-sdk/mistral

Provider Instance

You can import the default provider instance mistral from @ai-sdk/mistral:

import { mistral } from '@ai-sdk/mistral';

If you need a customized setup, you can import createMistral from @ai-sdk/mistral and create a provider instance with your settings:

import { createMistral } from '@ai-sdk/mistral';
const mistral = createMistral({
// custom settings
});

You can use the following optional settings to customize the Mistral provider instance:

  • baseURL string

    Use a different URL prefix for API calls, e.g. to use proxy servers. The default prefix is https://api.mistral.ai/v1.

  • apiKey string

    API key that is being send using the Authorization header. It defaults to the MISTRAL_API_KEY environment variable.

  • headers Record<string,string>

    Custom headers to include in the requests.

Language Models

You can create models that call the Mistral chat API using provider instance. The first argument is the model id, e.g. mistral-large-latest. Some Mistral chat models support tool calls.

const model = mistral('mistral-large-latest');

Mistral chat models also support additional model settings that are not part of the standard call settings. You can pass them as an options argument:

const model = mistral('mistral-large-latest', {
safePrompt: true, // optional safety prompt injection
});

The following optional settings are available for Mistral models:

  • safePrompt boolean

    Whether to inject a safety prompt before all conversations.

    Defaults to false.

Model Capabilities

ModelImage InputObject GenerationTool UsageTool Streaming
mistral-large-latest
mistral-small-latest

Embedding Models

You can create models that call the Mistral embeddings API using the .embedding() factory method.

const model = mistral.embedding('mistral-embed');