0PricingLogin
AI Prompt Engineering · Lesson

Multi-Image Comparison Prompts

Comparing two or more images: differences, similarities, changes over time.

Multi-Image Prompts

Vision models can process multiple images in a single API call. This enables powerful comparison tasks:

  • Before/after analysis (product photos, room renovations, medical imaging)
  • Product variant comparison (color options, size comparisons)
  • Quality comparison (selecting the best photo for a listing)
  • Change detection (two versions of a document, two time-stamped images)

Multi-image prompts require careful structure so the model knows which image is which and what relationship to analyze.

Sending Multiple Images in One Call

The API accepts multiple images as a list of content items. Label each image explicitly:

import anthropic, base64

client = anthropic.Anthropic(api_key='YOUR_API_KEY')

def compare_images(image_path_1, image_path_2, comparison_prompt):
    def encode(path):
        with open(path, 'rb') as f:
            return base64.standard_b64encode(f.read()).decode('utf-8')

    r = client.messages.create(
        model='claude-opus-4-5', max_tokens=600,
        messages=[{'role': 'user', 'content': [
            {'type': 'text', 'text': 'IMAGE 1:'},
            {'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/jpeg', 'data': encode(image_path_1)}},
            {'type': 'text', 'text': 'IMAGE 2:'},
            {'type': 'image', 'source': {'type': 'base64', 'media_type': 'image/jpeg', 'data': encode(image_path_2)}},
            {'type': 'text', 'text': comparison_prompt}
        ]}]
    )
    return r.content[0].text

print('Multi-image comparison function defined.')

All lessons in this course

  1. Image Description and Captioning Prompts
  2. Visual Question Answering
  3. Multi-Image Comparison Prompts
  4. OCR and Document Analysis Prompts
← Back to AI Prompt Engineering