Mistral AI Dart Client

pub package License: MIT

Dart client for the Mistral AI API with chat completions, streaming, tool calling, multimodal inputs, TTS, voice management, reasoning effort, embeddings, OCR, and more. It gives Dart and Flutter applications a pure Dart, type-safe client across iOS, Android, macOS, Windows, Linux, Web, and server-side Dart.

Tip

Coding agents: start with llms.txt. It links to the package docs, examples, and optional references in a compact format.

Table of Contents

Features

Coverage: See API Coverage for supported resources and availability.

Generation and streaming

  • Chat completions with streaming, tool calling, vision, JSON mode, and structured output
  • Stateless Responses with SSE, multimodal input, function tools, and token counting
  • Embeddings, FIM code completions, and reasoning effort control
  • Model management and discovery

Tools and media

  • Built-in web search, code interpreter, and document library tools
  • Audio transcription, text-to-speech, voice management, realtime WebSockets, and Voice Agents
  • OCR, moderations, and classifications

Operational APIs

  • Files, fine-tuned model management, and batch processing
  • Legacy Agents and Conversations (beta), connectors, and libraries
  • Prompts and skills: versioned, shareable templates and instructions (beta)
  • Observability traces, datasets, and evaluations (Enterprise Public Preview)
  • Workflows: execution, scheduling, management, and managed deployments (Public Preview)
  • Managed Search indexes, document ingestion, and retrieval (Mistral-hosted Public Preview)
  • RAG ingestion pipeline configuration (beta)
  • Caller identity, user memberships, service accounts, and billing (beta)
  • Triggers and webhook event sources for deployed workflows (beta)
  • Organization directory, SCIM, usage, limits, audit logs, API keys, and Vibe analytics (Admin API Enterprise Preview)

Why choose this client?

  • Pure Dart with no Flutter dependency — works in mobile apps, backends, and CLIs.
  • Type-safe request and response models with http, web_socket, crypto, logging, and meta.
  • Streaming, retries, interceptors, and error handling built into the client.
  • Resource APIs for inference, media, workflows, document storage, and managed search.
  • Strict semver versioning so downstream packages can depend on stable, predictable version ranges.

Quickstart

Requires Dart 3.12 or later. See the Migration Guide for upgrade instructions.

dependencies:
  mistralai_dart: ^9.0.0
import 'package:mistralai_dart/mistralai_dart.dart';

Future<void> main() async {
  final client = MistralClient.fromEnvironment();

  try {
    final response = await client.chat.create(
      request: ChatCompletionRequest(
        model: 'mistral-small-latest',
        messages: [
          ChatMessage.user('Hello! How are you?'),
        ],
      ),
    );

    print(response.text);
  } finally {
    client.close();
  }
}

Configuration

Configure auth, retries, and custom endpoints

Use MistralClient.fromEnvironment() when MISTRAL_API_KEY is available. Switch to MistralConfig when you need a proxy, custom timeout, or a non-default retry policy.

// Simple API key authentication
final client = MistralClient.withApiKey('your-api-key');

// From environment variables (reads MISTRAL_API_KEY and optional MISTRAL_BASE_URL)
final client = MistralClient.fromEnvironment();

// Custom base URL (for proxies or self-hosted)
final client = MistralClient.withApiKey(
  'your-api-key',
  baseUrl: 'https://my-proxy.example.com',
);

// Full configuration
final client = MistralClient(
  config: MistralConfig(
    authProvider: ApiKeyProvider('your-api-key'),
    baseUrl: 'https://api.mistral.ai',
    retryPolicy: RetryPolicy(
      maxRetries: 3,
      initialDelay: Duration(seconds: 1),
    ),
  ),
);

// Always close when done
client.close();

Environment variables:

  • MISTRAL_API_KEY
  • MISTRAL_BASE_URL

Use explicit configuration on web builds where runtime environment variables are not available.

By default the client does not send an X-Request-ID header — Mistral's CORS allow-list excludes it, so sending it breaks the preflight in browser targets (Flutter Web / dart2wasm). A request ID is still generated internally for logging and error correlation. Set MistralConfig(sendRequestIdHeader: true) to emit the header when talking to an intermediary (e.g. a reverse proxy) you've configured to accept it.

Usage

How do I use chat completions?

Show example

Use client.chat.create(...) to send messages and receive a completion. Set reasoningEffort on reasoning-capable models to control how deeply the model thinks.

// Basic chat
final response = await client.chat.create(
  request: ChatCompletionRequest(
    model: 'mistral-small-latest',
    messages: [
      ChatMessage.system('You are a helpful assistant.'),
      ChatMessage.user('What is the capital of France?'),
    ],
    temperature: 0.7,
    maxTokens: 500,
  ),
);

print(response.text);
// Control reasoning depth for reasoning-capable models
final response = await client.chat.create(
  request: ChatCompletionRequest(
    model: 'mistral-large-latest',
    messages: [
      ChatMessage.user('Solve this step by step: what is 23 * 47?'),
    ],
    reasoningEffort: ReasoningEffort.high,
  ),
);

print(response.text);

On models that support log probabilities, set logprobs: true and optionally topLogprobs. Read the generated-token scores from choice.logprobs?.content. Use promptLogprobs: true and optionally topPromptLogprobs for input-token scores. These choices appear in both JSON responses and streaming chunks when the model returns them. Sampling controls such as minTokens, topK, and repetitionPenalty, and the supported reasoning levels, depend on the model.

Set serviceTier: RequestedServiceTier.auto to request Priority Tier when available. Check response.usage?.serviceTier or the final stream chunk's usage for the actual tier. Priority Tier depends on account entitlement, model, and region. Omitting the field uses standard capacity. Mistral Priority Tier

Chat and Agent completions accept function, image generation, document library, and custom connector tools. Mistral accepts legacy prediction but ignores it. Use guardrails in new code in place of the deprecated safePrompt flag.

Run the example with --logprobs to print token scores or --priority to request Priority Tier. Set MISTRAL_CHAT_MODEL to a supported model if needed.

→ Full example

How do I stream responses?

Show example

Use client.chat.createStream(...) to receive tokens as they are generated via SSE. Each chunk exposes a text extension for easy access.

final stream = client.chat.createStream(
  request: ChatCompletionRequest(
    model: 'mistral-small-latest',
    messages: [
      ChatMessage.user('Tell me a story'),
    ],
  ),
);

await for (final chunk in stream) {
  if (chunk.text != null) {
    stdout.write(chunk.text); // Extension method
  }
}

→ Full example

How do I use the Responses API?

Show example

Use client.responses to create a stateless response, stream server-sent events, or count input tokens. Keep conversation state in your app. Send the ordered history, prior output items and client-executed tool results in the next request. Requests run in the foreground.

const request = CreateResponseRequest(
  model: 'mistral-large-latest',
  input: ResponseInput.text('Summarize how Dart streams work.'),
);

final result = await client.responses.create(request: request);
print(result.outputText);

await for (final event in client.responses.createStream(request: request)) {
  if (event is ResponseTextDeltaEvent) {
    print(event.delta);
  }
}

Use ResponseInput.items for text, image and file messages or tool results, and ResponseTextConfig for structured output. Mistral's API supports JSON and SSE with the same request. For migration from a stored Responses API, replay the full history instead of passing a previous response ID.

→ Full example

How do I use vision?

Show example

Pass multimodal content parts (text + image URLs or base64 data URLs) using ChatMessage.userMultimodal(...) with a vision-capable model like Pixtral.

final response = await client.chat.create(
  request: ChatCompletionRequest(
    model: 'pixtral-12b-2409',
    messages: [
      ChatMessage.userMultimodal([
        ContentPart.text('Describe this image'),
        ContentPart.imageUrl('https://example.com/image.jpg'),
        // Or use base64 via data URL
        // ContentPart.imageUrl('data:image/png;base64,$base64Data'),
      ]),
    ],
  ),
);

→ Full example

How do I use tool calling?

Show example

Define custom functions with JSON Schema parameters and send their results in a follow-up message. Chat Completions also accepts image generation, document library, and connector tools where available.

// Define tools
final weatherTool = Tool.function(
  name: 'get_weather',
  description: 'Get weather for a location',
  parameters: {
    'type': 'object',
    'properties': {
      'location': {'type': 'string'},
      'unit': {'type': 'string', 'enum': ['celsius', 'fahrenheit']},
    },
    'required': ['location'],
  },
);

// Request with tools
final response = await client.chat.create(
  request: ChatCompletionRequest(
    model: 'mistral-large-latest',
    messages: [ChatMessage.user('What is the weather in Paris?')],
    tools: [weatherTool],
    toolChoice: const ToolChoiceAuto(),
  ),
);

// Check for tool calls using extension
if (response.hasToolCalls) {
  for (final toolCall in response.toolCalls) {
    print('Function: ${toolCall.function.name}');
    print('Arguments: ${toolCall.function.arguments}');

    // Execute tool and send result back
    final toolResult = await executeFunction(toolCall);

    // Continue conversation with tool result
    final followUp = await client.chat.create(
      request: ChatCompletionRequest(
        model: 'mistral-large-latest',
        messages: [
          ChatMessage.user('What is the weather in Paris?'),
          ChatMessage.assistant(null, toolCalls: response.toolCalls),
          ChatMessage.tool(
            toolCallId: toolCall.id,
            content: toolResult,
          ),
        ],
        tools: [weatherTool],
      ),
    );
  }
}

→ Full example

How do I use structured output?

Show example

Use ResponseFormatJsonObject for simple JSON mode or ResponseFormatJsonSchema to enforce a specific schema on the response.

// Simple JSON mode
final response = await client.chat.create(
  request: ChatCompletionRequest(
    model: 'mistral-small-latest',
    messages: [
      ChatMessage.system('Respond in JSON format.'),
      ChatMessage.user('List 3 programming languages'),
    ],
    responseFormat: const ResponseFormatJsonObject(),
  ),
);

// JSON with schema validation
final response = await client.chat.create(
  request: ChatCompletionRequest(
    model: 'mistral-small-latest',
    messages: [ChatMessage.user('Generate a product')],
    responseFormat: ResponseFormatJsonSchema(
      name: 'product',
      schema: {
        'type': 'object',
        'properties': {
          'name': {'type': 'string'},
          'price': {'type': 'number'},
          'in_stock': {'type': 'boolean'},
        },
        'required': ['name', 'price'],
      },
    ),
  ),
);

→ Full example

How do I create embeddings?

Show example

Use client.embeddings.create(...) with a single text or a batch of texts. The response contains embedding vectors you can use for search, clustering, or classification.

// Single text
final response = await client.embeddings.create(
  request: EmbeddingRequest.single(
    model: 'mistral-embed',
    input: 'Hello, world!',
  ),
);
print('Dimensions: ${response.data.first.embedding.length}');

// Batch embeddings
final response = await client.embeddings.create(
  request: EmbeddingRequest.batch(
    model: 'mistral-embed',
    input: ['Text 1', 'Text 2', 'Text 3'],
  ),
);

For multimodal embeddings, pass the model ID available to your account. Mistral Multimodal Embed is in public preview. Supported models accept text and image chunks. The API also defines audio chunks for models that accept audio. Mistral Multimodal Embed model card · Embeddings API

final response = await client.embeddings.create(
  request: EmbeddingRequest(
    model: multimodalModelId,
    input: const EmbedInput.batch([
      EmbedInputString('A product photo'),
      EmbedInputImage(ImageUrlContentPart('https://example.com/product.png')),
    ]),
    encodingFormat: 'base64',
  ),
);
final encoded = response.data.first.embeddingBase64;

Use EmbeddingData.embedding for numeric vectors and embeddingBase64 for encoded vectors. The byte layout depends on outputDtype.

Set MISTRAL_MULTIMODAL_EMBED_MODEL and MISTRAL_EMBED_IMAGE_URL to run the multimodal part of the example.

→ Full example

How do I use code completions?

Show example

Use client.fim.create(...) for fill-in-the-middle code completion with Codestral. Provide a prompt and optional suffix to generate the middle portion.

final response = await client.fim.create(
  request: FimCompletionRequest(
    model: 'codestral-latest',
    prompt: 'def fibonacci(n):',
    suffix: '\n    return result',
    maxTokens: 100,
  ),
);

print(response.choices.first.message);

// Streaming FIM
final stream = client.fim.createStream(
  request: FimCompletionRequest(
    model: 'codestral-latest',
    prompt: 'function add(a, b) {',
    suffix: '}',
  ),
);

→ Full example

How do I list and manage models?

Show example

Use client.models to list, retrieve, and delete models. Use client.fineTuning.models to update, archive, and unarchive fine-tuned models.

// List all models
final models = await client.models.list();
for (final model in models.data) {
  print('${model.id}: ${model.name}');
}

// Get a specific model
final model = await client.models.get('mistral-small-latest');
print('Max context: ${model.maxContextLength}');

// Audio model cards can report supported modes and formats.
final audio = await client.models.get(audioModelId);
print(audio.audioTranscriptionCapabilities?.modes);
print(audio.audioSpeechCapabilities?.responseFormats);
print(audio.billingModelName);

// Delete a fine-tuned model
await client.models.delete('ft:mistral-small:my-model:xyz');
// Update a fine-tuned model's metadata
final updated = await client.fineTuning.models.update(
  modelId: 'ft:mistral-small:my-model:xyz',
  name: 'My Improved Model',
  description: 'Fine-tuned for customer support',
);

// Archive a model
final archived = await client.fineTuning.models.archive(
  modelId: 'ft:mistral-small:my-model:xyz',
);

// Unarchive a model
await client.fineTuning.models.unarchive(
  modelId: 'ft:mistral-small:my-model:xyz',
);

→ Full example

How do I manage files?

Show example

Use client.files to upload, list, download, and delete files, or to request a signed download URL. File paths and input streams require a native platform. Use bytes with a filename in a browser.

// Upload a file
final file = await client.files.upload(
  filePath: 'batch_requests.jsonl',
  purpose: FilePurpose.batch,
  visibility: FileVisibility.workspace,
  mimeType: 'application/jsonl',
);

// List files from an upload
final files = await client.files.list(
  purpose: FilePurpose.batch,
  sources: ['upload'],
  pageSize: 20,
);

// Download file content
final content = await client.files.download(fileId: file.id);

final signed = await client.files.getSignedUrl(
  fileId: file.id,
  expiryHours: 1,
);
print(signed.url);

→ Full example

How do I manage fine-tuned models and batch?

Show example

Mistral retired the fine-tuning jobs API. Version 6 removed job creation and polling. Use client.fineTuning.models to update, archive, or restore existing fine-tuned models. Use client.batch.jobs for batch inference. Mistral's legacy fine-tuning notice

// Update a fine-tuned model's metadata
final updated = await client.fineTuning.models.update(
  modelId: 'ft:mistral-small:my-model:xyz',
  name: 'My Model v2',
);

// Archive / unarchive a fine-tuned model
await client.fineTuning.models.archive(modelId: updated.id);
await client.fineTuning.models.unarchive(modelId: updated.id);

// Create batch job
final job = await client.batch.jobs.create(
  request: CreateBatchJobRequest(
    inputFiles: ['file-abc123'],
    endpoint: '/v1/chat/completions',
    model: 'mistral-small-latest',
  ),
);

// Poll for completion
final poller = BatchJobPoller(client: client, jobId: job.id);
final completed = await poller.poll();

final outputFileId = completed.outputFileId;
if (outputFileId != null) {
  final results = await client.files.download(fileId: outputFileId);
  print('Downloaded ${results.length} bytes');
}

// List one page of completed or timed-out jobs.
final page = await client.batch.jobs.list(
  page: 0,
  pageSize: 20,
  statuses: [BatchJobStatus.success, BatchJobStatus.timedOut],
);
print(page.data.length);

For jobs with inline results, call retrieve(jobId: id, inline: true) and read outputs.

→ Fine-tuned models · Batch

How do I moderate content?

Show example

Use client.moderations for safety flags and scores on text or conversations. Read categoryScores.scores for the category names returned by the selected model. Use ChatModerationRequest.batch to submit multiple conversations in one request. Moderation guide

// Text moderation
final result = await client.moderations.create(
  request: ModerationRequest(
    model: 'mistral-moderation-2603',
    input: ['Check this content for safety'],
  ),
);

for (final item in result.results) {
  if (item.flagged) {
    print('Content flagged: ${item.categories}');
  }
}

// Chat-aware moderation
final result = await client.moderations.createChat(
  request: ChatModerationRequest(
    model: 'mistral-moderation-2603',
    input: [
      ChatMessage.user('Hello'),
      ChatMessage.assistant('Hi there!'),
    ],
  ),
);

Use client.classifications with the ID of an existing classifier. Each result contains a map of configured targets and their label scores. Mistral lists Classifier Factory as deprecated. Classifier API · Deprecated features

final classifications = await client.classifications.create(
  request: ClassificationRequest.text(
    model: classifierModelId,
    input: 'Please send me a copy of the invoice.',
  ),
);

for (final result in classifications.results) {
  for (final target in result.targets.entries) {
    print('${target.key}: ${target.value.scores}');
  }
}

Set MISTRAL_CLASSIFIER_MODEL to run the classifier example.

→ Moderation example · Classification example

How do I extract text from documents?

Show example

Use client.ocr.process(...) to extract Markdown and paragraph-level blocks from URLs, uploaded files, or base64-encoded documents and images. Mistral retired mistral-ocr-4-0 on September 30, 2026. Use mistral-ocr-4-1 or mistral-ocr-latest for block-level confidence scores. OCR 4.1 release · OCR 4.0 retirement

// From URL
final result = await client.ocr.process(
  request: OcrRequest(
    model: 'mistral-ocr-latest',
    document: OcrDocument.url('https://example.com/document.pdf'),
    includeBlocks: true,
    confidenceScoresGranularity: OcrConfidenceScoresGranularity.block,
  ),
);

for (final page in result.pages) {
  print('Page ${page.index}: ${page.markdown}');
  for (final block in page.blocks ?? const <OcrBlock>[]) {
    print('${block.type}: ${block.confidenceScores?.blockTypeConfidenceScore}');
  }
}

// From base64
final result = await client.ocr.process(
  request: OcrRequest(
    model: 'mistral-ocr-latest',
    document: OcrDocument.base64(data: base64Data, mimeType: 'application/pdf'),
  ),
);

Pass a local PDF path to the example to request block confidence.

→ Full example

How do I use audio?

Show example

Use client.audio.transcriptions for speech-to-text, client.audio.speech for text-to-speech, and client.audio.voices to manage voices. Voxtral 3 models are in Public Preview. Their HTTP streams return results as they are generated from a complete recording or text input.

// Transcribe bytes without uploading them to the Files store.
final bytes = await File('recording.wav').readAsBytes();
final request = TranscriptionRequest(
  model: 'voxtral-mini-transcribe-3-0',
  fileBytes: bytes,
  fileName: 'recording.wav',
  diarize: true,
  timestampGranularityOptions: [TranscriptionTimestampGranularity.segment],
  contextBias: ['Mistral', 'Voxtral'],
);

final result = await client.audio.transcriptions.create(request: request);
print(result.text);
for (final segment in result.segments ?? <TranscriptionSegment>[]) {
  print('${segment.speakerId ?? 'speaker'}: ${segment.text}');
}

// A fileUrl or an uploaded file ID (file) can also identify the recording.
await for (final event in client.audio.transcriptions.createStream(request: request)) {
  if (event.type == 'transcription.text.delta') {
    stdout.write(event.text ?? '');
  }
}

Voxtral 3 supports segment timestamps. Keep the legacy word granularity for models that support it. Speaker reference clips go in TranscriptionRequest.speakerReferences with diarize: true.

// Find preset voices, then download a sample or generate speech.
final page = await client.audio.voices.search(type: 'preset', language: ['en']);
if (page.data.isNotEmpty) {
  final voiceId = page.data.first.id;
  final sample = await client.audio.voices.getSampleAudio(voiceId: voiceId);
  await File('sample.wav').writeAsBytes(sample);

  final response = await client.audio.speech.create(
    request: SpeechRequest(
      model: 'voxtral-mini-tts-3-0',
      voiceId: voiceId,
      input: 'Hello, world!',
      responseFormat: SpeechOutputFormat.wav,
      expressiveness: 1.5,
    ),
  );
  await File('speech.wav').writeAsBytes(base64Decode(response.audioData));
}

Use SpeechRequest.phonemeHints for pronunciation and conversationHistory with eligible preset PVC voices for contextual delivery. Use client.audio.speech.createStream() to receive audio chunks.

Pass the returned nextPageToken as pageToken with the same search filters to retrieve the next page. The offset-based voices.list() endpoint is scheduled to retire on March 31, 2027.

→ Full example

How do I use realtime audio?

Show example

Voxtral 3 realtime transcription and speech run over WebSockets in Public Preview. Use client.audio.realtime.transcribeStream() for incoming audio and client.audio.realtimeSpeech.speakStream() for incoming text. Ending the input stream lets the server finish and report usage. Cancel the subscription to stop both the input and the socket.

// pcmFrames is a Stream<List<int>> of raw 16 kHz signed 16-bit mono PCM.
await for (final event in client.audio.realtime.transcribeStream(
  model: 'voxtral-mini-transcribe-realtime-3-0',
  audio: pcmFrames,
  options: const RealtimeTranscriptionOptions(
    audioFormat: RealtimeAudioFormat(
      encoding: RealtimeAudioEncoding.pcmS16le,
      sampleRate: 16000,
    ),
  ),
)) {
  if (event.type == 'transcription.text.delta') {
    stdout.write(event.text ?? '');
  }
}

Use connect() to manage session updates, turn detection, intermediate flushes, or multiple speech generations on one socket. Close a connection you open directly. Transcription consumes raw mono PCM. When speech uses SpeechOutputFormat.pcm, its base64 chunks decode to raw float32 little-endian mono.

Native Dart clients use bearer credentials for both sockets. Browser transcription uses a short-lived, model-scoped credential. Use a server-side API key with create_client_session permission to call backend.realtime.sessions.create(), then pass only the secret value to the authenticated browser. Mistral documents the subprotocol handshake in its realtime transcription client authentication guide. Mint the token for the exact model your browser connects to. Realtime speech uses the native bearer path.

const model = 'voxtral-mini-transcribe-realtime-3-0';
// Backend, using your workspace API key.
final session = await backend.realtime.sessions.create(
  request: const CreateRealtimeClientSessionRequest(model: model),
);
final token = session.clientSecret.value; // Return to the authenticated browser.

// Browser, after retrieving token from your backend.
final connection = await browser.audio.realtime.connect(
  model: model,
  clientToken: token,
);

→ Full example

How do I use Voice Agents?

Show example

Use client.audio.agents to manage versioned voice agents and client.audio.sessions to create, inspect, update, and stop their sessions on Mistral-hosted infrastructure. The session API also starts sessions with inline settings. Both are separate from the text agent API at client.agents.

// Backend. Authenticate the app user before creating a room.
final session = await backend.audio.sessions.create(
  request: CreateAudioSessionRequest(agentId: agentId),
);
final handoff = VoiceAgentRoomCredentials.fromSession(session).toJson();
// Return handoff only to the authenticated app user.

The app joins LiveKit using the server URL and short-lived participant token. Keep the workspace API key on the backend. Treat the handoff as a credential. Use your LiveKit media SDK to capture microphone audio and play the remote tracks. An adapter supplied to VoiceAgentConnection translates room packets and RPC calls into Dart types without adding a media dependency to this package.

final connection = await VoiceAgentConnection.connect(
  credentials: VoiceAgentRoomCredentials.fromJson(handoff),
  transport: liveKitAdapter, // Implements VoiceAgentRoomTransport.
  closeSession: closeSessionOnBackend,
  functions: {
    'lookup_order': (args) => lookupOrderOnBackend(args['order_id'] as String),
  },
);
try {
  await for (final event in connection.events) {
    if (event case VoiceAgentTranscriptEvent(isFinal: true, :final content)) {
      print(content);
    }
  }
} finally {
  await connection.close();
}

Your adapter should identify the agent from trusted LiveKit participant metadata, subscribe to its voice_agent.events packets, and close the packet stream when the room disconnects. Register mistral.function_tool before publishing the microphone. Convert VoiceAgentRpcError to the media SDK's RPC error with the same code. Function handlers should enforce application permissions. Save their declarations on the agent or include them when creating the session.

For a runtime update, call backend.audio.sessions.update() over REST or connection.update() to send mistral.session_update to the room's agent. The room RPC returns the committed configuration as a VoiceAgentSessionUpdatedEvent. Instructions and tools apply at the next turn boundary. The app owns the connection and calls close() to release the LiveKit room and stop the server session through the backend callback.

SIP calling requires Enterprise access. The Mistral account team sets up phone numbers and binds them to agents. Dart exposes session metadata and the transfer and hang-up declarations published in the REST schema. Mistral's telephony guide currently lists transfer to a person as unavailable. Mistral browser guide · Telephony guide

Voice Agent webhooks deliver call_started, call_ended, and call_failed to your backend. Use the endpoint signing secret and verify the original request bytes against the x-mistral-signature header.

final verifier = VoiceAgentWebhookVerifier(signingSecret: endpointSecret);
final event = verifier.verifyAndParse(
  rawBody: rawRequestBytes,
  signature: signatureHeader,
);
if (event case VoiceAgentCallEndedEvent(:final sessionId, :final transcript)) {
  // Acknowledge the request, then process the optional transcript.
}

Use the session ID and event type to deduplicate retried deliveries. Configure webhook endpoints and subscriptions in the Mistral console. Signed Voice Agent deliveries

→ Session management example · Offline webhook example

How do I use agents?

Show example

Use client.agents for the legacy Agents API (beta). An agent can follow custom instructions and use configured tools. Use complete(...) for agent completions and listPages(...) for cursor pagination.

// Create an agent
final agent = await client.agents.create(
  request: CreateAgentRequest(
    name: 'Research Assistant',
    model: 'mistral-large-latest',
    instructions: 'You are a helpful research assistant.',
    tools: [Tool.webSearch()],
  ),
);

// Chat with agent
final response = await client.agents.complete(
  request: AgentCompletionRequest(
    agentId: agent.id,
    messages: [ChatMessage.user('Search for latest AI papers')],
  ),
);
print(response.text); // Extension for output text content

// List agents. Pass agents.nextPageToken to fetch the next page.
final agents = await client.agents.listPages(pageSize: 20);

// Update agent
await client.agents.update(
  agentId: agent.id,
  request: UpdateAgentRequest(name: 'Updated Name'),
);

// Delete agent
await client.agents.delete(agentId: agent.id);

Mistral directs new Managed Agents projects to its separate mistralai-agents Python runtime. See the Mistral migration guide.

→ Full example

How do I use conversations?

Show example

Use client.conversations for the legacy Conversations API (beta). Mistral keeps state for a stored conversation, allowing requests by conversation ID.

final conversation = await client.conversations.start(
  request: const StartConversationRequest(
    model: 'mistral-large-latest',
    inputText: 'Describe one way to learn Dart.',
    completionArgs: CompletionArgs(maxTokens: 256),
  ),
);
print(conversation.text);

await for (final event in client.conversations.appendStream(
  conversationId: conversation.conversationId,
  request: const AppendConversationRequest(inputText: 'Give me an example.'),
)) {
  if (event is ConversationMessageDelta) {
    print(event.text);
  }
}

final history = await client.conversations.getHistory(
  conversationId: conversation.conversationId,
);
print(history.entries.length);

Use getMessages for just message inputs and outputs. startStream, appendStream, and restartStream return typed events for text, tools, handoffs, usage, and service errors. Supply an abortTrigger or cancel the subscription to stop a stream.

→ Full example

How do I use libraries?

Show example

Use client.libraries (beta) to create document libraries for retrieval. Upload document bytes and wait for processing before querying with Tool.documentLibrary(...).

// Create a library
final library = await client.libraries.create(
  name: 'Research Papers',
);

// Upload a document directly. This example uses ASCII bytes for "AI notes".
final doc = await client.libraries.documents.upload(
  libraryId: library.id,
  bytes: [65, 73, 32, 110, 111, 116, 101, 115],
  fileName: 'notes.txt',
  mimeType: 'text/plain',
);

final docs = await client.libraries.documents.list(libraryId: library.id);
print(docs.data.firstOrNull?.processingStatus);

// Once the document is processed, use the library with Chat Completions.
final response = await client.chat.create(
  request: ChatCompletionRequest(
    model: 'mistral-large-latest',
    messages: [ChatMessage.user('What does the paper say about AI?')],
    tools: [Tool.documentLibrary(libraryIds: [library.id])],
  ),
);

// Delete library
await client.libraries.delete(libraryId: library.id);

deleteSharing returns the deleted access record on HTTP 200 and null when the API confirms removal with HTTP 204.

→ Full example

How do I use prompts?

Show example

Use client.prompts to manage versioned, shareable prompt templates (Beta). Each prompt has one or more versions; aliases (e.g. production) let you point consumers at a specific version without changing their code.

Use sortBy and sortDirection to order lists. Select the fields you need with fields. For a workspace prompt, set workspaceRelation: RegistryShareRelation.reader to grant read access. Omitting the relation uses Mistral's writer default.

// Create a prompt
final prompt = await client.prompts.create(
  request: const CreatePromptRequest(
    name: 'greeting',
    definition: PromptDefinition(content: 'Hello, {{name}}!'),
  ),
);

// List prompts
final prompts = await client.prompts.list(pageSize: 10);

// Create a new version
final version = await client.prompts.createVersion(
  promptId: prompt.id,
  request: const CreatePromptVersionRequest(
    definition: PromptDefinition(content: 'Hi there, {{name}}!'),
  ),
);

// Point an alias at the new version
await client.prompts.updateVersion(
  promptId: prompt.id,
  version: version.version ?? 2,
  request: const UpdatePromptVersionRequest(
    aliases: AliasList(values: ['production']),
  ),
);

// Retrieve by alias
final latest = await client.prompts.retrieve(
  promptId: prompt.id,
  alias: 'production',
);
print(latest.definition?.content);

// Delete the prompt
await client.prompts.delete(promptId: prompt.id);

→ Full example

How do I use skills?

Show example

Use client.skills to manage versioned, shareable model instructions with optional file assets (Beta). Skills follow the same version/alias model as prompts.

Skill lists can project definition.description. Retrieve an individual skill to read its body and assets. A workspace skill can grant read access with workspaceRelation: RegistryShareRelation.reader.

// Create a skill with a text asset
final skill = await client.skills.create(
  request: const CreateSkillRequest(
    name: 'summarizer',
    definition: SkillDefinition(
      description: 'Summarizes long documents.',
      body: 'Summarize the input in three bullet points.',
      assets: {
        'style_guide.txt': SkillAssetContent.text(
          textContent: 'Use concise, plain language.',
        ),
      },
    ),
  ),
);

// List skills
final skills = await client.skills.list(pageSize: 10);

// Create a new version and point an alias at it
final version = await client.skills.createVersion(
  skillId: skill.id,
  request: const CreateSkillVersionRequest(
    definition: SkillDefinition(body: 'Summarize in three short bullets.'),
  ),
);
await client.skills.updateVersion(
  skillId: skill.id,
  version: version.version ?? 2,
  request: const UpdateSkillVersionRequest(
    aliases: AliasList(values: ['production']),
  ),
);

// Delete the skill
await client.skills.delete(skillId: skill.id);

→ Full example

How do I use connectors?

Show example

Use client.connectors to manage MCP and HTTP connectors in Public Preview. Connector visibility and the API key's connector scope determine which connectors are available. Organization sharing requires the relevant organization permission. Connector access and management

final connectors = await client.connectors.list(
  queryFilters: const ConnectorsQueryFilters(supportsMcp: true),
  pageSize: 20,
);
final connector = connectors.items.first;
final tools = await client.connectors.listMcpTools(
  connectorIdOrName: connector.id,
);
print(tools.map((tool) => tool.name));

Use CreateConnectorRequest(protocol: 'http', ...) and UpdateConnectorRequest(protocol: 'http', ...) for HTTP connector CRUD. Import the OpenAPI document in Studio. Read its source from connector.openapiSpec when Mistral exposes it. HTTP connector setup

Use createCredentials to create credentials at user or workspace scope, and updateCredentials to create or update them at any supported scope. Use getAuthUrl for delegated OAuth with the supported method and an optional credential name and title.

Mistral soft-deprecated direct callTool calls. Configure credentials through client.connectors and pass a connector in the model request's tools list. Beta Connectors API

final answer = await client.chat.create(
  request: ChatCompletionRequest(
    model: 'mistral-small-latest',
    messages: [ChatMessage.user('Find the catalog entry for a field notebook.')],
    tools: [CustomConnectorTool(connectorId: connector.id)],
  ),
);

→ Full example

How do I use observability?

Show example

Observability is in Public Preview for Enterprise organizations. Reading telemetry and managing evaluations require the corresponding workspace role. Creating a live evaluation requires a user credential with the appropriate role. Live evaluation selectors use PipelineSourceKind.span. Access requirements · Online evaluation API

final observability = client.observability;
final datasets = await observability.datasets.list(pageSize: 20);
final projects = await observability.projects.list(pageSize: 20);
final runs = await observability.evaluations.searchAllRuns(pageSize: 20);
final scorers = await observability.scorers.list(pageSize: 20);
final pipelines = await observability.pipelines.list(enabled: true);
final optimizations = await observability.optimizations.list(pageSize: 20);

final traces = await observability.traces.search(
  request: const TracesRequest(searchExpression: 'status_code = "Error"'),
);
final fields = await observability.spans.getFields();
final logs = await observability.logs.search();

Use datasets.createRecords for bulk inserts and datasets.importFromSpans to map telemetry into dataset records. A client-generated ID lets a retried bulk insert return the existing record. Use pipelines.searchResults with pipeline configuration slugs for cursor-paginated results, and spans.aggregateEvaluations for grouped scores.

Historical campaigns, judges, chatCompletionEvents, chatCompletionFields, and their related import methods remain available for existing deployments. Current integrations use OpenTelemetry traces and live evaluation scorers and pipelines. The separate Mistral Evaluation SDK runs offline jobs and manages their lifecycle. Offline evaluations

→ Full example

Show example

Managed Search runs on Mistral-hosted infrastructure in Public Preview. Use a workspace API key with access to the index. Creating, updating, and deleting an index initiate asynchronous operations. Use its status to check when it is ready.

final index = await client.managedSearchIndexes.get(indexName: 'team-notes');

if (index.status == ManagedSearchIndexStatus.ready) {
  final results = await client.managedSearchIndexes.search(
    indexName: index.name,
    request: const ManagedSearchRequest(
      retriever: KeywordRetriever(query: 'release checklist', topK: 5),
    ),
  );
  for (final hit in results.hits) {
    print(hit.chunk.content);
  }
}

Use client.managedSearchIndexes for index CRUD, document ingestion, keyword and vector search, navigation, and streamed summary generation. The old client.rag.searchIndexes wrappers refer to external index registration routes from an earlier API snapshot. Managed indexes require their own configuration and ingestion.

A rejected search can return several validation issues in ManagedSearchQueryException.errors. Each issue has typed fields, such as SearchTopKTooLarge.limit or SearchIncorrectFieldType.expectedType. ManagedSearchQueryException extends ApiException, so existing HTTP error handlers still catch it.

→ Full example

How do I configure a RAG ingestion pipeline?

Show example

The beta client.rag.ingestionPipelineConfigurations resource registers pipeline metadata and reports ingestion runs.

final config = await client.rag.ingestionPipelineConfigurations.register(
  request: const CreateIngestionPipelineConfigurationRequest(
    name: 'My ingestion pipeline',
  ),
);

await client.rag.ingestionPipelineConfigurations.updateRunInfo(
  id: config.id,
  request: UpdateRunInfo(
    executionTime: DateTime.now().toUtc(),
    chunksCount: 128,
  ),
);

→ Full example

How do I use workflows?

Show example

Use client.workflows to manage and execute workflows via the workflow core resource (client.workflows.core), check execution status, list registrations, monitor runs, view metrics, inspect workers, and configure schedules.

// List registered workflows
final workflows = await client.workflows.core.list();
for (final wf in workflows.workflowRegistrations) {
  print('${wf.workflow?.name}: ${wf.workflowId}');
}

// Execute a workflow
final result = await client.workflows.core.executeAsync(
  workflowIdentifier: 'my-workflow',
  request: WorkflowExecutionRequest(
    input: {'key': 'value'},
  ),
);
print('Execution: ${result.executionId}');

// Get execution status
final execution = await client.workflows.executions.get(
  executionId: result.executionId,
);
print('Status: ${execution.status}');

// List runs and check metrics
final runs = await client.workflows.runs.list();
final metrics = await client.workflows.metrics.get(
  workflowName: 'my-workflow',
);

// List workers and continue with workers.nextCursor.
final workers = await client.workflows.deployments.listWorkers(
  name: 'my-deployment',
  workerStatus: 'active',
);

// List registrations
final registrations = await client.workflows.registrations.list();

// List schedules
final schedules = await client.workflows.schedules.list();

// Create, start, and monitor a managed deployment
final deployment = await client.workflows.deployments.create(
  request: const CreateDeploymentRequest(
    name: 'my-deployment',
    spec: DeploymentWorkerSpecInput(
      repositoryUrl: 'https://github.com/my-org/my-worker',
    ),
  ),
);
await client.workflows.deployments.start(name: deployment.name);

final logs = await client.workflows.deployments.getLogs(
  name: deployment.name,
  limit: 50,
);
print('Fetched ${logs.results.length} log record(s)');
await for (final log in client.workflows.deployments.streamLogs(
  name: deployment.name,
)) {
  print('${log.severityText}: ${log.body}');
}

Managed Deployments are a Mistral-hosted Public Preview for eligible paid workspaces and are subject to quotas. To deploy from an archive, request a signed URL with deployments.createArchive, PUT the raw gzipped tar file using a separate HTTP client and the signed headers, then create or update a deployment with the returned archiveId. Keep signed URLs and headers private. Mistral Managed Deployments

Use workflows.core.executeAsync or executeSync with a workflow identifier in place of the deprecated registration execution route. Use DeploymentLogType.build in deployments.getLogs for managed build output. Streamed logs expose eventId for resuming from lastEventId.

Workflow example · Archive deployment example

How do I identify the authenticated caller?

Show example

Use client.users.whoami() for a human user or service account. Use me() for the legacy human profile, or listOrganizations and listWorkspaces for user memberships.

final identity = await client.users.whoami();
switch (identity.principal) {
  case WhoamiUserPrincipal(:final id):
    print(id);
  case WhoamiServiceAccountPrincipal(:final serviceAccountId):
    print(serviceAccountId);
  case UnknownWhoamiPrincipal():
    break;
}

These beta identity routes accept the configured credential as a bearer token. Pass authInApiKeyHeader: true to use the public API key header. The membership methods accept offset and limit. Filter workspace listings by organization when needed.

→ Full example

How do I manage workspace service accounts?

Show example

Use client.serviceAccounts to list and manage workspace principals and their roles. Access depends on the caller's workspace permissions.

final page = await client.serviceAccounts.list(
  workspaceId: workspaceId,
  limit: 25,
);
final assignable = await client.serviceAccounts.listAssignableRoles(
  workspaceId: workspaceId,
);
print('${page.items.length} accounts and ${assignable.items.length} roles');

Use setRoles with the complete set of role IDs to replace existing assignments. See the Mistral service accounts guide.

→ Full example

How do I read billing settings?

Show example

The beta billing resource reads the budget and subscription for the authenticated dashboard customer. The client sends the configured public API key in the x-api-key header.

final budget = await client.billing.getBudget();
final plan = await client.billing.getSubscription();
print('${plan.planName}: ${budget.apiBudget.usagePercentage}% API usage');

→ Full example

How do I start a workflow on a webhook event?

Show example

Register an inbound event source with client.webhooks and link it to a deployed workflow with client.triggers. The webhook and its triggers share the same owner type. Mistral validates provider-specific signatures and tracks delivered events.

final trigger = await client.triggers.create(
  request: CreateTriggerRequest(
    eventSourceId: webhookId,
    handler: TriggerHandler.workflows,
    action: TriggerAction(
      primitiveId: workflowId,
      type: TriggerActionType.startWorkflow,
    ),
    ownerType: TriggerOwnerType.workspace,
    title: 'Start workflow',
  ),
);
final events = await client.triggers.listEvents(triggerId: trigger.id);
print(events.data.length);

Workflow triggers receive events from your provider. Voice Agents send call lifecycle events to your app with an x-mistral-signature header. Use the configured provider signing secret for workflow webhooks. See the Mistral triggers and webhooks guide.

→ Full example

How do I manage an organization with the Admin API?

Show example

The Admin API is available to Enterprise Preview organizations. Create an organization Admin API key in the Mistral Admin Panel and keep it server-side. Use a standalone MistralAdminClient to manage Admin users and invitations, Admin groups and their assignments, and Admin workspaces and their members. Use Admin roles to look up role IDs and Admin SCIM to manage sync runs.

final admin = MistralAdminClient.withApiKey(organizationAdminKey);

try {
  final roles = await admin.roles.list();
  final workspaces = await admin.workspaces.list(page: 1, pageSize: 10);
  print(roles.organizationRoles.map((role) => role.name).join(', '));
  print('Workspace count: ${workspaces.total}');
} finally {
  admin.close();
}

The Admin client uses the x-api-key header specified in the authentication guide. Configure SAML or SCIM in the Admin Panel before using the SCIM synchronization endpoints.

Admin example · Admin authentication

How do I read Admin usage and audit activity?

Show example

Use admin.usage to read monthly usage and pricing, query grouped usage, and manage spend limits. Use Admin audit logs to filter activity by actor, event, target, and time. Admin API keys can list, create, and delete workspace keys. Treat the key returned on creation as a secret.

final usage = await admin.usage.getMonthly(apiZone: AdminApiZone.eu);
final events = await admin.auditLogs.list(
  actorType: [AdminAuditActorType.human],
  limit: 10,
);
print('Usage period: ${usage.startDate} to ${usage.endDate}');
print('Recent user events: ${events.length}');

Admin Vibe analytics return Vibe Code metrics by organization or workspace, and Vibe Work metrics by agent, time, or user. Pass Unix timestamps in seconds for the query window. Enterprise Preview access and product permissions apply.

Read-only Admin usage example · Admin API authentication

Error Handling

Handle retries, validation failures, and request aborts

mistralai_dart throws typed exceptions so retry logic and validation handling stay explicit. Catch ApiException and its subclasses first, then fall back to MistralException for other transport or parsing failures.

import 'dart:io';

import 'package:mistralai_dart/mistralai_dart.dart';

Future<void> main() async {
  final client = MistralClient.fromEnvironment();

  try {
    await client.chat.create(
      request: ChatCompletionRequest(
        model: 'mistral-small-latest',
        messages: [ChatMessage.user('Ping')],
      ),
    );
  } on RateLimitException catch (error) {
    stderr.writeln('Retry after: ${error.retryAfter}');
  } on ApiException catch (error) {
    stderr.writeln('Mistral API error ${error.statusCode}: ${error.message}');
  } on MistralException catch (error) {
    stderr.writeln('Mistral client error: $error');
  } finally {
    client.close();
  }
}

→ Full example

Examples

See the example/ directory for complete examples:

Example Description
chat_example.dart Chat completions, token scores, and Priority Tier
streaming_example.dart Streaming responses
responses_example.dart Stateless Responses and token counting
tool_calling_example.dart Tool calling
json_mode_example.dart Structured output
vision_example.dart Multimodal inputs
embeddings_example.dart Text and multimodal embeddings
fim_example.dart Code completion
files_example.dart File uploads, filters, and signed URLs
fine_tuning_example.dart Fine-tuned model management
batch_example.dart Batch filtering, inline results, and polling
moderation_example.dart Content moderation
classification_example.dart Text and chat classification with target scores
ocr_example.dart OCR 4.1 with block confidence
audio_example.dart Voxtral file transcription, SSE, speech, voice search, and WAV samples
realtime_audio_example.dart Realtime Voxtral transcription and speech over WebSockets
voice_agents_example.dart Mistral-hosted Voice Agents and audio sessions
voice_agent_webhooks_example.dart Offline verification of signed Voice Agent lifecycle events
agents_example.dart Legacy Agents (beta), cursor pagination
conversations_example.dart Legacy Conversations (beta), typed streaming
libraries_example.dart Library and document uploads (beta)
prompts_example.dart Versioned prompt templates (beta)
skills_example.dart Versioned model instructions and assets (beta)
connectors_example.dart MCP and HTTP connector management (Public Preview)
observability_example.dart Observability projects, datasets, scorers, and telemetry
workflows_example.dart Workflow execution, scheduling, and management
workflow_deployment_archive_example.dart Signed archive upload and managed deployment (Public Preview)
managed_search_indexes_example.dart Mistral-hosted Managed Search
rag_index_example.dart RAG ingestion pipeline configuration (beta)
users_example.dart Legacy current user profile
platform_identity_example.dart Caller identity, memberships, billing, and workspace roles
workflow_trigger_example.dart Provider webhook setup and workflow trigger events
admin_example.dart Organization roles and workspaces (Enterprise Preview)
admin_usage_example.dart Usage, audit logs, workspace key inventory, and Vibe analytics (Enterprise Preview)
models_example.dart Model listing
error_handling_example.dart Exception handling patterns
config_example.dart Client configuration options
multi_turn_example.dart Multi-turn conversation management
parallel_requests_example.dart Parallel and concurrent requests
rag_example.dart Retrieval Augmented Generation
semantic_search_example.dart Semantic search with embeddings
system_message_example.dart System message patterns

API Coverage

API Status
Chat ✅ Full
Responses Stateless generation, streaming and input token counting
Embeddings ✅ Full
Models ✅ Full
FIM ✅ Full
Files ✅ Full
Fine-tuned models (management) ✅ Full
Batch ✅ Full
Moderations ✅ Full
Classifications ✅ Full
OCR ✅ Full
Audio (Transcription, Speech, Voices) ✅ Full
Voxtral realtime transcription and speech Public Preview. Native STT and TTS, browser STT with a scoped token
Voice Agents (audio agents and sessions) Mistral-hosted REST, LiveKit handoff, and signed webhook deliveries. Enterprise SIP access
Agents (legacy beta) Entities, versions, aliases, and completions
Conversations (legacy beta) JSON, typed SSE, history, and messages
Libraries (Beta) ✅ Full
Connectors (Public Preview) ✅ Public API
Prompts (Beta) ✅ Full
Skills (Beta) ✅ Full
Observability (Enterprise Public Preview) ✅ Public API
Workflows ✅ Supported
Managed Search Mistral-hosted Public Preview
RAG (Beta) Ingestion pipeline configuration and legacy index wrappers
Identity and memberships (Beta) Caller identity, organizations, and workspaces
Service accounts (Beta) Workspace principals and role assignments
Billing (Beta) Dashboard budget and subscription
Triggers and webhooks (Beta) Inbound event sources, trigger rules, and recent events
Admin Directory Enterprise Preview
Admin Usage, Audit Logs, API Keys, and Vibe analytics Enterprise Preview

Official Documentation

If these packages are useful to you or your company, please consider sponsoring the project. Development and maintenance are provided to the community for free, but integration tests against real APIs and the tooling required to build and verify releases still have real costs. Your support, at any level, helps keep these packages maintained and free for the Dart & Flutter community.

License

This package is licensed under the MIT License.

This is a community-maintained package and is not affiliated with or endorsed by Mistral AI.

Libraries

mistralai_dart
Dart client for the Mistral AI API.