or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

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

provider-configuration.mddocs/

Provider Configuration

Configuration and provider instance creation for Mistral AI integration, including custom endpoints, authentication, and request middleware.

Capabilities

Create Custom Provider

Creates a configurable Mistral provider instance with custom settings.

/**
 * Create a Mistral AI provider instance with custom configuration
 * @param options - Configuration options for the provider
 * @returns Configured MistralProvider instance
 */
function createMistral(options?: MistralProviderSettings): MistralProvider;

Usage Examples:

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

// Custom API key and base URL
const customMistral = createMistral({
  apiKey: 'your-api-key-here',
  baseURL: 'https://your-proxy.com/v1',
});

// With custom headers and fetch middleware
const enterpriseMistral = createMistral({
  apiKey: process.env.MISTRAL_API_KEY,
  headers: {
    'User-Agent': 'MyApp/1.0',
    'X-Environment': 'production',
  },
  fetch: async (url, options) => {
    console.log('Making API request to:', url);
    return fetch(url, options);
  },
});

Provider Settings Interface

Configuration options for customizing the Mistral provider behavior.

interface MistralProviderSettings {
  /** 
   * Use a different URL prefix for API calls, e.g. to use proxy servers.
   * The default prefix is `https://api.mistral.ai/v1`.
   */
  baseURL?: string;
  
  /** 
   * API key that is being send using the `Authorization` header.
   * It defaults to the `MISTRAL_API_KEY` environment variable.
   */
  apiKey?: string;
  
  /** Custom headers to include in the requests. */
  headers?: Record<string, string>;
  
  /** 
   * Custom fetch implementation. You can use it as a middleware to intercept requests,
   * or to provide a custom fetch implementation for e.g. testing.
   */
  fetch?: FetchFunction;
  
  /** Custom ID generation function for request tracking */
  generateId?: () => string;
}

Provider Interface

The main provider interface that supports multiple ways to create models.

interface MistralProvider extends ProviderV2 {
  /** Direct call operator for creating chat models */
  (modelId: MistralChatModelId): LanguageModelV2;
  
  /** Creates a model for text generation */
  languageModel(modelId: MistralChatModelId): LanguageModelV2;
  
  /** Creates a model for text generation (alias for languageModel) */
  chat(modelId: MistralChatModelId): LanguageModelV2;
  
  /** @deprecated Use `textEmbedding()` instead */
  embedding(modelId: MistralEmbeddingModelId): EmbeddingModelV2<string>;
  
  /** Creates a text embedding model */
  textEmbedding(modelId: MistralEmbeddingModelId): EmbeddingModelV2<string>;
  
  /** Creates a text embedding model (alternative method) */
  textEmbeddingModel(modelId: MistralEmbeddingModelId): EmbeddingModelV2<string>;
}

Usage Examples:

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

const provider = createMistral();

// Multiple ways to create the same chat model
const model1 = provider('mistral-large-latest');
const model2 = provider.languageModel('mistral-large-latest');
const model3 = provider.chat('mistral-large-latest');

// Create embedding model
const embedder = provider.textEmbedding('mistral-embed');

Default Provider Instance

Pre-configured provider instance for immediate use.

/**
 * Default Mistral provider instance.
 * Uses MISTRAL_API_KEY environment variable and official API endpoint.
 */
const mistral: MistralProvider;

Usage Examples:

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

// Use directly without configuration
const { text } = await generateText({
  model: mistral('mistral-large-latest'),
  prompt: 'Hello, world!',
});

Authentication

The provider handles authentication automatically using Bearer token authentication with the Mistral API.

Environment Variable: Set MISTRAL_API_KEY in your environment for the default provider instance.

export MISTRAL_API_KEY="your-mistral-api-key"

Custom API Key: Pass the API key directly when creating a custom provider instance.

const customProvider = createMistral({
  apiKey: 'your-custom-api-key',
});