mistralai/client-python

Python client library for Mistral AI platform

What is the Mistral Python Client?

The repository provides an official Python SDK for Mistral AI’s cloud services – chat‑completion, embeddings, audio, file handling, agents, and a host of other resources. It lets developers call Mistral’s REST APIs from Python code (both synchronously and with asyncio) without having to hand‑craft HTTP requests.


Key Features (as described in the README)

Area What you can do with the SDK
Chat completions Generate text responses from models such as mistral-large-latest. Supports streaming and custom response formats.
Embeddings Obtain vector embeddings for one or many input strings via mistral-embed.
File uploads Upload files to a workspace (e.g., for fine‑tuning or retrieval‑augmented generation).
Agents Call agent endpoints that maintain stateful interactions, with both sync and async APIs.
Audio Speech synthesis (Audio.Speech) and transcription (Audio.Transcriptions), including streaming transcription via Server‑Sent Events.
Batch jobs List, create, cancel, and delete long‑running batch jobs.
Beta resources Manage agents, connectors, conversations, libraries, and documents (create, list, update, delete, pagination, etc.).
Cloud provider wrappers Ready‑made clients for Azure AI and Google Cloud (Vertex AI) that automatically handle endpoint construction, authentication, and token refresh.
Utilities Built‑in pagination, retries, error handling, custom HTTP client injection, telemetry hooks, and IDE‑friendly type hints.

Getting Started

  1. Obtain an API key from the Mistral console (or from Azure/GCP if you’re using those wrappers). Export it as MISTRAL_API_KEY (or the provider‑specific env vars).
  2. Install the package – any of the following works:
    # uv (fast installer)
    uv add mistralai
    
    # pip (default)
    pip install mistralai
    
    # poetry
    poetry add mistralai
    
    For agent‑related features add the extra: pip install "mistralai[agents]" (requires Python 3.10+).
  3. Write a tiny script (sync example):
    from mistralai.client import Mistral
    import os
    
    with Mistral(api_key=os.getenv("MISTRAL_API_KEY")) as client:
        resp = client.chat.complete(
            model="mistral-large-latest",
            messages=[{"role": "user", "content": "Who is the best French painter?"}],
            stream=False,
            response_format={"type": "text"},
        )
        print(resp)
    
    The same pattern works with async with Mistral(...): and the *_async methods.

When Would You Use This?

  • Building LLM‑powered applications (chatbots, assistants, RAG pipelines) that need a reliable, typed Python interface.
  • Integrating Mistral models into existing Python services without dealing with raw HTTP.
  • Leveraging Mistral’s extended ecosystem – audio generation, transcription, batch processing, or the newer agents and connectors features.
  • Deploying on Azure or Google Cloud – the SDK includes thin wrappers (MistralAzure, MistralGCP) that automatically handle the provider‑specific authentication and endpoint construction.

How It Is Structured

  • mistralai.client.Mistral – the core client exposing sub‑objects (chat, embeddings, files, agents, audio, etc.).
  • Provider‑specific modules (mistralai.azure.client, mistralai.gcp.client) that subclass the core client with preset base URLs and auth flows.
  • Extensive documentation in the docs/ folder for each resource, plus a examples/ directory that can be run with uv run.

TL;DR

The Mistral Python Client is a fully‑featured, officially supported SDK that wraps Mistral AI’s cloud APIs. Install it via pip (or uv/poetry), set your API key, and you can start making chat, embedding, audio, file, and agent calls directly from Python—both synchronously and asynchronously. It also includes ready‑made adapters for Azure AI and Google Cloud, making it a convenient entry point for any Python developer working with modern LLM services.

Related

  • Dispatch
  • Dispatch
  • Dispatch
  • Project