Session 1· H7· 10 min

Compare Two Images

What you'll learn
  • Send multiple images in a single request
  • Ask the model to reason across them
  • Format multi-image prompts cleanly

What you will build

A script that accepts --image1 and --image2 and asks "what changed between these?". Great for A/B design reviews, before/after shots, spot-the-difference, or UI regression checks.

The code

src/07_image_analysis_compare.py (excerpt)
response = client.responses.create(
    model=env_model("MODEL_VISION", "gpt-4.1-mini"),
    input=[{"role": "user", "content": [                       ①
        {"type": "input_text",  "text": "Compare these two images. What changed?"},
        {"type": "input_image", "image_url": to_data_url(args.image1)},
        {"type": "input_image", "image_url": to_data_url(args.image2)},  ②
    ]}],
)
print(response.output_text)
Same user-content-list pattern as H6, but with more items.
Just append more input_image items. The model sees them in order.

Run it

$ python src/07_image_analysis_compare.py --image1 assets/a.png --image2 assets/b.png

Knowledge check

Knowledge Check
How does the model know which image to call "the first one"?
Recap — what you just learned
  • Multi-image is just more input_image items in the same content list
  • Order matters — first in the list is "image 1" to the model
  • No limit on mixing text and image items in a user message
Next up: H8 — Image Generation