{"id":47,"library":"mistral","title":"Mistral AI Python SDK","description":"Official Python SDK for Mistral AI API. Has gone through two major breaking rewrites: v0 → v1 (MistralClient removed) and v1 → v2 (in pre-release on GitHub, not yet on PyPI). Most LLM-generated code references v0 patterns which no longer work.","status":"active","version":"1.12.4","language":"python","source_language":"en","source_url":"https://pypi.org/project/mistralai/","tags":["mistral","llm","chat","completions","agents","embeddings","ocr","france"],"install":[{"cmd":"pip install mistralai","lang":"bash","label":"pip (installs v1 — stable)"},{"cmd":"uv add mistralai","lang":"bash","label":"uv"},{"cmd":"pip install 'mistralai[agents]'","lang":"bash","label":"pip (with agents support)"},{"cmd":"pip install mistralai-azure","lang":"bash","label":"Azure deployment"},{"cmd":"pip install mistralai-gcp","lang":"bash","label":"Google Cloud deployment"}],"dependencies":[{"reason":"v0.x is fully deprecated. MistralClient class no longer exists.","package":"mistralai>=1.0.0","optional":false},{"reason":"Required for agents API (mistral.agents.complete). Python 3.10+ only.","package":"mistralai[agents]","optional":true}],"imports":[{"note":"MistralClient and MistralAsyncClient were removed in v1. Single Mistral class handles both sync and async.","wrong":"from mistralai.client import MistralClient","symbol":"Mistral","correct":"from mistralai import Mistral"},{"note":"v0 used client.chat() directly. v1+ uses client.chat.complete(). Most LLM-generated code uses the old pattern.","wrong":"client.chat(model=..., messages=[...])","symbol":"chat completion","correct":"client.chat.complete(model=..., messages=[...])"},{"note":"Streaming response structure changed in v1. chunk now wraps data — extra .data level required.","wrong":"chunk.choices[0].delta.content","symbol":"streaming chunk","correct":"chunk.data.choices[0].delta.content"},{"note":"ChatMessage class removed. Use plain dicts or UserMessage/SystemMessage/AssistantMessage classes from mistralai.","wrong":"from mistralai.models.chat_completion import ChatMessage","symbol":"ChatMessage","correct":"{'role': 'user', 'content': '...'}"}],"quickstart":{"code":"import os\nfrom mistralai import Mistral\n\nclient = Mistral(api_key=os.environ['MISTRAL_API_KEY'])\n\nresponse = client.chat.complete(\n    model='mistral-large-latest',\n    messages=[{'role': 'user', 'content': 'Hello'}]\n)\nprint(response.choices[0].message.content)","lang":"python","description":"Minimal chat completion using v1 SDK"},"warnings":[{"fix":"Replace MistralClient(api_key=...) with Mistral(api_key=...). Same constructor signature.","message":"MistralClient and MistralAsyncClient are removed. Use Mistral class for both sync and async.","severity":"breaking","affected_versions":"v0.x"},{"fix":"Change client.chat(model=m, messages=msgs) to client.chat.complete(model=m, messages=msgs)","message":"client.chat() call signature removed. Now client.chat.complete() for sync, client.chat.complete_async() for async.","severity":"breaking","affected_versions":"v0.x"},{"fix":"Add .data between chunk and .choices in all streaming handlers","message":"Streaming chunk structure changed. chunk.choices[0] no longer works — must use chunk.data.choices[0].","severity":"breaking","affected_versions":"v0.x"},{"fix":"Replace ChatMessage(role='user', content='...') with {'role': 'user', 'content': '...'}","message":"ChatMessage class removed from mistralai.models.chat_completion. Use plain dicts or new typed message classes.","severity":"breaking","affected_versions":"v0.x"},{"fix":"Always include tool_call_id in tool response messages","message":"tool_call_id is now mandatory in messages with role 'tool'. Omitting it causes API error.","severity":"breaking","affected_versions":"all v1+"},{"fix":"Use PyPI docs at pypi.org/project/mistralai for v1 reference. GitHub main = v2 pre-release.","message":"pip install mistralai installs v1 (stable). GitHub main branch shows v2 docs which are NOT on PyPI yet. Don't follow GitHub README — it documents unreleased v2.","severity":"gotcha","affected_versions":"current"},{"fix":"pip install 'mistralai[agents]' and ensure Python 3.10+","message":"Agents API requires Python 3.10+ and mistralai[agents] extra. Base install does not include it.","severity":"gotcha","affected_versions":"v1+"},{"fix":"Refer to official Mistral AI documentation for configuring Azure/GCP deployments. Do not attempt to 'pip install mistralai-azure' or 'mistralai-gcp' as these packages are not available.","message":"mistralai-azure and mistralai-gcp are not separate PyPI packages. Azure/GCP deployments are typically configured via 'base_url' or specific client initialization parameters, not by installing additional packages.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T05:52:05.894Z","next_check":"2026-03-28T00:00:00.000Z","problems":[{"fix":"Upgrade the `mistralai` library to the latest version using `pip install --upgrade mistralai`. Then, import `ChatMessage` directly from `mistralai.client` or ensure your code adapts to the current API structure, which often places `ChatMessage` directly in `mistralai.client` or uses plain dictionaries for messages.","cause":"This error typically occurs when using an outdated version of the `mistralai` library (like `0.4.2` or older) or when the `ChatMessage` model has been moved or refactored in newer versions (v1 and above) to be directly accessible from `mistralai.client` or through a simpler structure.","error":"ModuleNotFoundError: No module named 'mistralai.models.chat_completion'"},{"fix":"Access chat completion methods through the `chat` attribute of the `MistralClient` instance, for example, `client.chat.stream()` for streaming or `client.chat.completions()` for non-streaming.","cause":"This error arises because the method for interacting with the chat completion API, especially for streaming, changed in newer versions (v1 and beyond). Direct methods like `client.chat_stream()` or `client.chat()` were removed or restructured.","error":"AttributeError: 'MistralClient' object has no attribute 'chat_stream'"},{"fix":"Upgrade your Python environment to a supported version, preferably Python 3.9 or higher. If upgrading Python is not immediately possible, consider pinning an older, compatible version of the `mistralai` library if one exists that supports Python 3.8.","cause":"This error often occurs when running the `mistralai` library with older Python versions (specifically Python 3.8 or below) where type hints like `type[CustomPydanticModel]` used within the library's internal `extra` modules are not supported. This indicates a compatibility issue with the Python version and the library's type hinting syntax.","error":"TypeError: 'type' object is not subscriptable"},{"fix":"Ensure that the object you are trying to iterate over with `async for` is indeed an asynchronous iterable. If the method returns a coroutine, you might need to `await` it first to get the actual iterable object, or if it's a single result, process it directly after `await`. Check the library's documentation for the correct way to handle asynchronous streaming responses.","cause":"This error occurs when attempting to use `async for` on a coroutine object that is not an asynchronous iterator. It typically means an asynchronous function (coroutine) that returns a single result (or another coroutine) is being incorrectly treated as an async iterable (something that can be iterated over with `async for` to yield multiple items). This can happen if a streaming method returns a coroutine that needs to be awaited once to get the iterable, or if the method itself is not designed to be an async iterable.","error":"TypeError: 'async for' requires an object with __aiter__ method, got coroutine"},{"fix":"Ensure your `mistralai` library and its dependencies (like Pydantic) are up to date via `pip install --upgrade mistralai pydantic`. If the error persists, it means the `ChatMessage` object in your specific `mistralai` version expects a different serialization method (e.g., `dict()` or `json()` for Pydantic V1 models, or `model_dump_json()` for V2) or that the message structure should be a plain dictionary if the library expects it that way.","cause":"This error signifies that the `ChatMessage` object, likely from an older or incompatible version of the `mistralai` models, does not have the `model_dump` method. `model_dump` is a Pydantic V2 feature, and if `ChatMessage` is based on Pydantic V1 or a different serialization method, this attribute will be missing.","error":"AttributeError: 'ChatMessage' object has no attribute 'model_dump'"}],"ecosystem":"pypi","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"agents","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"agents","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"agents","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"agents","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"agents","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"agents","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"agents","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"agents","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"agents","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.75,"mem_mb":28.8,"disk_size":"136.1M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.98,"mem_mb":28.8,"disk_size":"109.9M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"agents","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.44,"mem_mb":27.4,"disk_size":"207M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":2.59,"mem_mb":27.4,"disk_size":"182M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}