mistralM

Docs

sideBar

Quickstart: analyze an image

Send an image with a question to a Mistral model and get a description, in about 5 minutes.
flagThis step takes ~5 minutes to complete.

In this quickstart, you send an image and a question in the same message, and the model answers about the image. It takes about 5 minutes. For image formats, sizes, and base64 input, see Vision.

Before you begin

Set up your environment

Create a project, install the Mistral SDK, and export your API key:

uv init analyze-image --python 3.12 && cd analyze-image
uv add mistralai
export MISTRAL_API_KEY="your-api-key"

1. Write the script

Create image.py. The message has two parts: the question as text, and the image as a URL:

import os

from mistralai.client import Mistral

client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])

response = client.chat.complete(
    model="mistral-small-latest",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What is in this image? Answer in one sentence."},
                {"type": "image_url", "image_url": "/images/eiffel-tower-paris.jpg"},
            ],
        }
    ],
)

print(response.choices[0].message.content)

To use one of your own images, replace the URL with a public image URL. For local files, see Vision.

2. Run it

uv run image.py

You should see

One sentence that describes the photo. The wording varies between runs:

The image shows the Eiffel Tower, a famous landmark in Paris, France.

If you get an error about the image, check that the URL opens in a browser without signing in.

Going further

Vision
illustrationImage

Vision

Send images to vision-capable models through the Chat Completions API and analyze visual content alongside text.

Process documents with OCR
illustrationFileAi

Process documents with OCR

Process documents with OCR and extract structured data through the OCR endpoint, using the OCR processor, annotations, and Document QnA.

Quickstart: get structured output
illustrationRocket

Quickstart: get structured output

Extract a validated Python object from free text with a Pydantic schema, in about 5 minutes.