The AI SDK Mistral Provider is a TypeScript library that integrates Mistral AI's language models with the AI SDK framework. It provides comprehensive support for text generation through chat models, text embeddings, and follows the AI SDK's standardized provider interface with full type safety.
npm i @ai-sdk/mistralimport { mistral, createMistral } from '@ai-sdk/mistral';For CommonJS:
const { mistral, createMistral } = require('@ai-sdk/mistral');import { mistral } from '@ai-sdk/mistral';
import { generateText } from 'ai';
// Use the default provider instance
const { text } = await generateText({
model: mistral('mistral-large-latest'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});
// Create embeddings
const embedding = mistral.textEmbedding('mistral-embed');
const { values } = await embedding.doEmbed({
values: ['Hello, world!', 'AI is amazing'],
});The Mistral provider is built around several key components:
createMistral() for configurable provider instances and mistral default instanceCore provider functionality for creating and configuring Mistral AI integrations. Supports custom API endpoints, authentication, and request middleware.
function createMistral(options?: MistralProviderSettings): MistralProvider;
interface MistralProviderSettings {
baseURL?: string;
apiKey?: string;
headers?: Record<string, string>;
fetch?: FetchFunction;
generateId?: () => string;
}
interface MistralProvider extends ProviderV2 {
(modelId: MistralChatModelId): LanguageModelV2;
languageModel(modelId: MistralChatModelId): LanguageModelV2;
chat(modelId: MistralChatModelId): LanguageModelV2;
embedding(modelId: MistralEmbeddingModelId): EmbeddingModelV2<string>;
textEmbedding(modelId: MistralEmbeddingModelId): EmbeddingModelV2<string>;
textEmbeddingModel(modelId: MistralEmbeddingModelId): EmbeddingModelV2<string>;
}Text generation and conversation capabilities using Mistral's chat models. Supports 15+ different model variants including latest, reasoning, and legacy models.
type MistralChatModelId =
| 'ministral-3b-latest'
| 'ministral-8b-latest'
| 'mistral-large-latest'
| 'mistral-medium-latest'
| 'mistral-medium-2508'
| 'mistral-medium-2505'
| 'mistral-small-latest'
| 'pixtral-large-latest'
| 'magistral-small-2507'
| 'magistral-medium-2507'
| 'magistral-small-2506'
| 'magistral-medium-2506'
| 'pixtral-12b-2409'
| 'open-mistral-7b'
| 'open-mixtral-8x7b'
| 'open-mixtral-8x22b'
| (string & {});
interface MistralLanguageModelOptions {
safePrompt?: boolean;
documentImageLimit?: number;
documentPageLimit?: number;
structuredOutputs?: boolean;
strictJsonSchema?: boolean;
}Text vectorization capabilities for semantic search, similarity matching, and retrieval-augmented generation (RAG) applications.
type MistralEmbeddingModelId = 'mistral-embed' | (string & {});Comprehensive error response processing for Mistral API errors with structured error data and proper error handling patterns.
interface MistralErrorData {
object: 'error';
message: string;
type: string;
param: string | null;
code: string | null;
}
const mistralFailedResponseHandler: JsonErrorResponseHandler<MistralErrorData>;Usage Examples:
import { mistral } from '@ai-sdk/mistral';
import { generateText } from 'ai';
try {
const { text } = await generateText({
model: mistral('mistral-large-latest'),
prompt: 'Your prompt here',
});
} catch (error) {
if (error.name === 'API_INVALID_ARGUMENT_ERROR') {
console.error('Invalid argument:', error.message);
} else if (error.name === 'API_AUTHENTICATION_ERROR') {
console.error('Authentication failed:', error.message);
} else {
console.error('Unexpected error:', error);
}
}const mistral: MistralProvider;The package exports a default mistral provider instance configured with standard settings. Uses the MISTRAL_API_KEY environment variable for authentication and the official Mistral API endpoint https://api.mistral.ai/v1.