Get startedGet started for free

Prompting with Images from URLs

You're building an automated product cataloging system for an online marketplace. The system needs to analyze product images and generate accurate descriptions for the catalog. You'll use role-based messages to send an image URL to the model and request both a classification and a description.

A URL string to a photo of a winter jacket has been stored as image_url, and the visualize_image() function has been defined for you to compare the image with the generated description.

This exercise is part of the course

Working with the OpenAI Responses API

View Course

Exercise instructions

  • Add a user message containing both a text prompt asking to classify and describe the product, and the image URL (image_url) using the appropriate content types.
  • Create the request to the "gpt-5-mini" model using your messages list and extract the output text.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

messages = [{"role": "system", "content": "You are a product cataloging expert who provides concise classifications and descriptions."}]

# Add user message with text and image
messages.append({
    "role": "____",
    "content": [
        {"type": "____", "____": "Classify this product and write a brief but punchy description for our catalog."},
        {"type": "____", "image_url": "____"}
    ]
})

# Create the response
response = ____

print(response.output_text)
visualize_image(image_url)
Edit and Run Code