# mistralai

> Python Client SDK for the Mistral AI API.

- **URL**: https://www.freshcrate.ai/projects/mistralai
- **Author**: Mistral
- **Category**: Developer Tools
- **Latest version**: `v2.4.9` (2026-06-03)
- **License**: Unknown
- **Source**: https://github.com/mistralai/client-python.git
- **Homepage**: https://pypi.org/project/mistralai/
- **Language**: Python
- **GitHub**: 722 stars, 175 forks
- **Registry**: pypi (`mistralai`)
- **Tags**: `pypi`

## Description

# Mistral Python Client

## Migrating from v1

If you are upgrading from v1 to v2, check the [migration guide](https://github.com/mistralai/client-python/blob/main/MIGRATION.md) for details on breaking changes and how to update your code.

## API Key Setup

Before you begin, you will need a Mistral AI API key.

1. Get your own Mistral API Key: <https://docs.mistral.ai/#api-access>
2. Set your Mistral API Key as an environment variable. You only need to do this once.

```bash
# set Mistral API Key (using zsh for example)
$ echo 'export MISTRAL_API_KEY=[your_key_here]' >> ~/.zshenv

# reload the environment (or just quit and open a new terminal)
$ source ~/.zshenv
```

<!-- Start Summary [summary] -->
## Summary

Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create your account on [La Plateforme](https://console.mistral.ai) to get access and read the [docs](https://docs.mistral.ai) to learn how to use it.
<!-- End Summary [summary] -->

<!-- Start Table of Contents [toc] -->
## Table of Contents
<!-- $toc-max-depth=2 -->
* [Mistral Python Client](#mistral-python-client)
  * [Migrating from v1](#migrating-from-v1)
  * [API Key Setup](#api-key-setup)
  * [SDK Installation](#sdk-installation)
  * [SDK Example Usage](#sdk-example-usage)
  * [Providers' SDKs Example Usage](#providers-sdks-example-usage)
  * [Available Resources and Operations](#available-resources-and-operations)
  * [Server-sent event streaming](#server-sent-event-streaming)
  * [Pagination](#pagination)
  * [File uploads](#file-uploads)
  * [Retries](#retries)
  * [Error Handling](#error-handling)
  * [Server Selection](#server-selection)
  * [Custom HTTP Client](#custom-http-client)
  * [Authentication](#authentication)
  * [Resource Management](#resource-management)
  * [Debugging](#debugging)
  * [IDE Support](#ide-support)
* [Development](#development)
  * [Contributions](#contributions)

<!-- End Table of Contents [toc] -->

<!-- Start SDK Installation [installation] -->
## SDK Installation

> [!NOTE]
> **Python version upgrade policy**
>
> Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.

The SDK can be installed with *uv*, *pip*, or *poetry* package managers.

### uv

*uv* is a fast Python package installer and resolver, designed as a drop-in replacement for pip and pip-tools. It's recommended for its speed and modern Python tooling capabilities.

```bash
uv add mistralai
```

### PIP

*PIP* is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.

```bash
pip install mistralai
```

### Poetry

*Poetry* is a modern tool that simplifies dependency management and package publishing by using a single `pyproject.toml` file to handle project metadata and dependencies.

```bash
poetry add mistralai
```

### Shell and script usage with `uv`

You can use this SDK in a Python shell with [uv](https://docs.astral.sh/uv/) and the `uvx` command that comes with it like so:

```shell
uvx --from mistralai python
```

It's also possible to write a standalone Python script without needing to set up a whole project like so:

```python
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.10"
# dependencies = [
#     "mistralai",
# ]
# ///

from mistralai.client import Mistral

sdk = Mistral(
  # SDK arguments
)

# Rest of script here...
```

Once that is saved to a file, you can run it with `uv run script.py` where
`script.py` can be replaced with the actual file name.
<!-- End SDK Installation [installation] -->

### Agents extra dependencies

When using the agents related feature it is required to add the `agents` extra dependencies. This can be added when
installing the package:

```bash
pip install "mistralai[agents]"
```

> Note: These features require Python 3.10+ (the SDK minimum).

### Additional packages

Additional `mistralai-*` packages (e.g. `mistralai-workflows`) can be installed separately and are available under the `mistralai` namespace:

```bash
pip install mistralai-workflows
```

<!-- Start SDK Example Usage [usage] -->
## SDK Example Usage

### Create Chat Completions

This example shows how to create chat completions.

```python
# Synchronous Example
from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.chat.complete(model="mistral-large-latest", messages=[
        {
            "role": "user",
            "content": "Who is the best French painter? Answer in one short sentence.",
        },
    ], stream=False, response_format={
        "type": "text",
    })

    # Handle response
    print(res)
```

</br>

The same SDK client can also be used to make asynchronous requests by importing asyncio.

```python
# Asynchronous Example
impor

## Recent releases

| Version | Date | Urgency | Changes |
| --- | --- | --- | --- |
| `v2.4.9` | 2026-06-03 | High | # Generated by Speakeasy CLI  ## 2026-06-03 11:09:54 ### Changes Based on: - OpenAPI Doc   - Speakeasy CLI 1.763.6 (2.884.13) https://github.com/speakeasy-api/speakeasy ### Generated - [python v2.4.9] . ### Releases - [PyPI v2.4.9] https://pypi.org/project/mistralai/2.4.9 - .  Publishing Completed |
| `v2.4.8` | 2026-05-28 | High | # Generated by Speakeasy CLI  ## 2026-05-27 16:56:58 ### Changes Based on: - OpenAPI Doc   - Speakeasy CLI 1.763.6 (2.884.13) https://github.com/speakeasy-api/speakeasy ### Generated - [python v2.4.8] . ### Releases - [PyPI v2.4.8] https://pypi.org/project/mistralai/2.4.8 - .  Publishing Completed |
| `v2.4.7` | 2026-05-27 | High | # Generated by Speakeasy CLI  ## 2026-05-22 14:12:57 ### Changes Based on: - OpenAPI Doc   - Speakeasy CLI 1.763.6 (2.884.13) https://github.com/speakeasy-api/speakeasy ### Generated - [python v2.4.7] . ### Releases - [PyPI v2.4.7] https://pypi.org/project/mistralai/2.4.7 - .  Publishing Completed |
| `v2.4.5` | 2026-05-07 | High | # Generated by Speakeasy CLI [mistralai 2.4.5](https://pypi.org/project/mistralai/2.4.5) ## Python SDK Changes: * `mistral.workflows.executions.stream()`:  `response.[].data.data.union(CustomTaskInProgressResponse).attributes.payload` **Changed** (Breaking ⚠️) * `mistral.workflows.events.get_stream_events()`:  `response.[].data.data` **Changed** (Breaking ⚠️) * `mistral.workflows.events.get_workflow_events()`:  `response.events[]` **Changed** (Breaking ⚠️) * `mistral.events.get_stream_events()`: |
| `v2.4.4` | 2026-04-30 | High | # Generated by Speakeasy CLI [mistralai 2.4.4](https://pypi.org/project/mistralai/2.4.4) ## Python SDK Changes: * `mistral.beta.libraries.update()`:  `request.name` **Changed** (Breaking ⚠️) * `mistral.beta.libraries.documents.update()`:  `request.name` **Changed** (Breaking ⚠️) * `mistral.beta.rag.ingestion_pipeline_configurations.update_run_info()`: **Added** * `mistral.workflows.schedules.pause_schedule()`: **Added** * `mistral.workflows.schedules.resume_schedule()`: **Added** * `mistral.beta |
| `v2.4.3` | 2026-04-27 | High | # Generated by Speakeasy CLI [mistralai 2.4.3](https://pypi.org/project/mistralai/2.4.3) ## Python SDK Changes: * `mistral.ocr.process()`:  `request.id` **Removed** (Breaking ⚠️) * `mistral.beta.rag.ingestion_pipeline_configurations.register()`: **Added**  Generated with [Speakeasy CLI 1.761.1](https://github.com/speakeasy-api/speakeasy/releases)   Publishing Completed |
| `v2.4.2` | 2026-04-23 | High | # Generated by Speakeasy CLI [mistralai 2.4.2](https://pypi.org/project/mistralai/2.4.2) ## Python SDK Changes: * `mistral.beta.observability.chat_completion_events.search()`:  `response.completion_events.results[].extra_fields.Map<extra_fields>.union(Map<string>)` **Added** (Breaking ⚠️) * `mistral.beta.observability.chat_completion_events.fetch()`:  `response.extra_fields.Map<extra_fields>.union(Map<string>)` **Added** (Breaking ⚠️) * `mistral.beta.observability.chat_completion_events.fetch_si |
| `2.4.1` | 2026-04-21 | Low | Imported from PyPI (2.4.1) |
| `v2.4.1` | 2026-04-21 | High | # Generated by Speakeasy CLI [mistralai 2.4.1](https://pypi.org/project/mistralai/2.4.1) ## Python SDK Changes: * `mistral.beta.conversations.restart_stream()`:    *  `request` **Changed** (Breaking ⚠️)   *  `response.[].data.union(message.output.delta).content.union(OutputContentChunks).union(ThinkChunk).signature` **Added** * `mistral.workflows.executions.get_workflow_execution_trace_events()`:  `response` **Changed** (Breaking ⚠️) * `mistral.workflows.executions.get_workflow_execution_trace_s |
| `v2.4.0` | 2026-04-16 | High | # Generated by Speakeasy CLI  ## 2026-04-16 12:02:46 ### Changes Based on: - OpenAPI Doc 1.0.0  - Speakeasy CLI 1.761.1 (2.879.6) https://github.com/speakeasy-api/speakeasy ### Generated - [python v2.4.0] . ### Releases - [PyPI v2.4.0] https://pypi.org/project/mistralai/2.4.0 - .  Publishing Completed |

## Citation

- HTML: https://www.freshcrate.ai/projects/mistralai
- Markdown: https://www.freshcrate.ai/projects/mistralai.md
- Dependencies JSON: https://www.freshcrate.ai/api/projects/mistralai/deps

_Generated by freshcrate.ai. Indexes pypi releases for AI-agent ecosystem packages._
