Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Environment:Mistralai Client python Python SDK Environment

From Leeroopedia
Knowledge Sources
Domains Infrastructure, API_Client
Last Updated 2026-02-15 14:00 GMT

Overview

Python 3.10+ environment with httpx, Pydantic v2, and OpenTelemetry for the Mistral AI Python SDK.

Description

This environment provides the core runtime context for all Mistral AI SDK operations. It requires Python 3.10 or higher and is built around httpx for async/sync HTTP communication, Pydantic v2 for request/response model validation, and OpenTelemetry for distributed tracing. The SDK follows a monorepo structure where the main `mistralai` package also includes the `mistralai_azure` and `mistralai_gcp` sub-packages.

Usage

Use this environment for any interaction with the Mistral AI API, including chat completions, embeddings, fine-tuning, OCR, and file management. This is the mandatory base environment for all Mistral SDK workflows.

System Requirements

Category Requirement Notes
OS Linux, macOS, Windows Ubuntu latest used in CI
Python >= 3.10 Supported: 3.10, 3.11, 3.12, 3.13; 3-month grace period after EOL
Build System hatchling Used for package building
Package Manager pip, uv, or poetry uv recommended for development

Dependencies

System Packages

  • No system-level packages required for core SDK

Python Packages

  • `httpx` >= 0.28.1
  • `pydantic` >= 2.10.3
  • `eval-type-backport` >= 0.2.0
  • `python-dateutil` >= 2.8.2
  • `typing-inspection` >= 0.4.0
  • `pyyaml` >= 6.0.2, < 7.0.0
  • `invoke` >= 2.2.0, < 3.0.0
  • `opentelemetry-sdk` >= 1.33.1, < 2.0.0
  • `opentelemetry-api` >= 1.33.1, < 2.0.0
  • `opentelemetry-exporter-otlp-proto-http` >= 1.37.0, < 2.0.0
  • `opentelemetry-semantic-conventions` >= 0.59b0, < 0.61

Credentials

The following environment variables must be set:

  • `MISTRAL_API_KEY`: Mistral AI API key for authentication. Auto-detected by the SDK from environment if not passed explicitly.

Optional:

  • `MISTRAL_DEBUG`: Enable debug logging (any truthy value).
  • `MISTRAL_SDK_DEBUG_TRACING`: Enable OpenTelemetry debug tracing (set to `"true"`; default `"false"`).
  • `MISTRAL_BASE_URL`: Override the default API base URL (default: `https://api.mistral.ai`).

Quick Install

# Install core SDK
pip install mistralai

# Or with optional extras
pip install "mistralai[gcp]"        # For Google Cloud support
pip install "mistralai[agents]"     # For agent/MCP features
pip install "mistralai[realtime]"   # For real-time transcription

Code Evidence

API key auto-detection from environment in `src/mistralai/client/utils/security.py:67-68`:

if os.getenv("MISTRAL_API_KEY"):
    security_dict["api_key"] = os.getenv("MISTRAL_API_KEY")

Debug mode detection in `src/mistralai/client/utils/logger.py:23-27`:

def get_default_logger() -> Logger:
    if os.getenv("MISTRAL_DEBUG"):
        logging.basicConfig(level=logging.DEBUG)
        return logging.getLogger("mistralai.client")
    return NoOpLogger()

OpenTelemetry debug tracing flag in `src/mistralai/extra/observability/otel.py:23`:

MISTRAL_SDK_DEBUG_TRACING: bool = os.getenv("MISTRAL_SDK_DEBUG_TRACING", "false").lower() == "true"

Python version requirement from `pyproject.toml:6`:

requires-python = ">=3.10"

Common Errors

Error Message Cause Solution
`ImportError: Failed to import {attr_name} from {module_name}` Lazy-loaded module not installed Ensure all core dependencies are installed: `pip install mistralai`
`MistralError` (HTTP 401) Invalid or missing API key Set `MISTRAL_API_KEY` environment variable or pass `api_key` to `Mistral()` constructor
`httpx.ConnectError` Network connectivity issue Check internet connection and firewall settings; verify `server_url` if overridden

Compatibility Notes

  • Python 3.9: Not supported despite some README examples showing `requires-python = ">=3.9"`. The actual minimum is Python 3.10.
  • Pydantic v1: Not supported. The SDK requires Pydantic v2 (>= 2.10.3).
  • httpx < 0.28.1: Not supported. The SDK relies on httpx features from 0.28.1+.
  • OpenTelemetry: Tracing is opt-in. Without a configured `TracerProvider`, the SDK uses a NoOp tracer.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment