or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

chat-models.mdembeddings.mdindex.mdprovider-configuration.md
tile.json

tessl/npm-ai-sdk--mistral

AI SDK provider for Mistral AI language models with chat, embeddings, and generation capabilities

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@ai-sdk/mistral@2.0.x

To install, run

npx @tessl/cli install tessl/npm-ai-sdk--mistral@2.0.0

index.mddocs/

AI SDK - Mistral Provider

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.

Package Information

  • Package Name: @ai-sdk/mistral
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm i @ai-sdk/mistral

Core Imports

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

For CommonJS:

const { mistral, createMistral } = require('@ai-sdk/mistral');

Basic Usage

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'],
});

Architecture

The Mistral provider is built around several key components:

  • Provider Factory: createMistral() for configurable provider instances and mistral default instance
  • Model Creation: Methods for creating chat and embedding models with specific model IDs
  • Chat Models: Full LanguageModelV2 interface for text generation and conversation
  • Embedding Models: EmbeddingModelV2 interface for text vectorization
  • Error Handling: Comprehensive error response processing for Mistral API errors
  • Type Safety: Complete TypeScript definitions for all model IDs and configuration options

Capabilities

Provider Instance and Configuration

Core 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>;
}

Provider Configuration

Chat Language Models

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;
}

Chat Models

Text Embeddings

Text vectorization capabilities for semantic search, similarity matching, and retrieval-augmented generation (RAG) applications.

type MistralEmbeddingModelId = 'mistral-embed' | (string & {});

Text Embeddings

Error Handling

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);
  }
}

Default Instance

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.