Quickstart: analyze an image

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

Before you begin

Set up your environment

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

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": "https://docs.mistral.ai/img/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

2. Run it

uv run image.py
You should see

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

Going further