Skip to content
Fondazione ITS INCOM

Examples · General

A screenshot of an error

Send Ministral the screenshot of an error from your terminal, your browser or your editor, and get the cause and the steps to fix it.

Beginner · 15 min

What you need

A key and the openai library, as in Your first API call in Python, and a screenshot of an error.

The model

Ministral 3 14B (ministral-3-14b), the European model of Mistral AI. It reads images, like Gemma 4 26B and Qwen3.6 35B: try all three on the same screenshot.

The program

Save it as error.py:

import base64
import mimetypes
import os
import sys

from openai import OpenAI

client = OpenAI(
    base_url="https://api.ai.itsincom.org/v1",
    api_key=os.environ["API_KEY"],
)

path = sys.argv[1]
mime = mimetypes.guess_type(path)[0] or "image/png"
with open(path, "rb") as f:
    image = base64.b64encode(f.read()).decode()

answer = client.chat.completions.create(
    model="ministral-3-14b",
    temperature=0.2,
    messages=[
        {"role": "system", "content": "You are a help desk technician for students. Read the error in the "
                                      "screenshot. Say what it means in one sentence, the most likely cause, "
                                      "and the steps to fix it. If you cannot read it, say so."},
        {"role": "user", "content": [
            {"type": "text", "text": "What is this error and how do I fix it?"},
            {"type": "image_url", "image_url": {"url": f"data:{mime};base64,{image}"}},
        ]},
    ],
)

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

Run it:

python3 error.py screenshot.png

Before you send it

Look at the whole screenshot. Terminals and browsers show more than the error: passwords, tokens, API keys, addresses, names of other people. Crop the image to the error only. PNG, JPEG, WebP or GIF; at most 8 MB.

Exercise

All examples