Lesson 3 of 3 · AI Image & Video Creation

The Responses API Approach

reading12 min

The Images API generates standalone images. The Responses API does something fundamentally different -- it integrates image generation into a conversational flow, enabling multi-turn editing, partial streaming, and a more natural creative workflow.

Think of the Images API as a vending machine: put in a prompt, get an image. The Responses API is more like working with a designer: you describe what you want, they show you a draft, you give feedback, they revise. The conversation continues until you are satisfied.

Image Generation via Responses API

Instead of a dedicated images endpoint, you use the standard chat-style responses endpoint with image generation enabled:

Python
from openai import OpenAI
client = OpenAI()

response = client.responses.create(
    model="gpt-image-1",
    input="Create a watercolor illustration of a lighthouse on a rocky coast at sunset, with seagulls in the sky",
    tools=[{"type": "image_generation"}]
)

# The response contains both text and image
for block in response.output:
    if block.type == "image":
        # Save the image
        image_bytes = base64.b64decode(block.image.b64_json)
        Path("lighthouse.png").write_bytes(image_bytes)
    elif block.type == "text":
        print(block.text)  # Model's description of what it generated

The key difference: the model can reason about the image, describe what it created, and respond to follow-up instructions -- because the image generation happens within a conversation context.

Multi-Turn Editing

This is where the Responses API shines. You can iteratively refine an image through conversation:

Python
# Turn 1: Generate initial image
response = client.responses.create(
    model="gpt-image-1",
    input="Create a modern logo for a fitness app called 'PulseTrack' -- minimalist, using blue and white",
    tools=[{"type": "image_generation"}]
)

# Turn 2: Refine based on the first result
response = client.responses.create(
    model="gpt-image-1",
    input="I like the direction but make the blue darker, more navy. And add a subtle heartbeat line integrated into the text.",
    tools=[{"type": "image_generation"}],
    previous_response_id=response.id  # Links to previous turn
)

# Turn 3: Final adjustment
response = client.responses.create(
    model="gpt-image-1",
    input="Perfect. Now create a version with a transparent background for use on dark surfaces.",
    tools=[{"type": "image_generation"}],
    previous_response_id=response.id
)
Conversational Iteration Is Powerful

Multi-turn editing through the Responses API is often faster and cheaper than generating multiple independent images and picking the best one. Each turn builds on the previous context, so the model understands your preferences and maintains consistency. It is the difference between giving a designer one vague brief versus having a 5-minute conversation.

Partial Image Streaming

The Responses API supports partial image streaming -- the image is delivered in stages as it generates. This is valuable for user-facing applications where showing progressive results keeps users engaged during the 5-15 second generation time.

Python
# Stream the response with partial images
stream = client.responses.create(
    model="gpt-image-1",
    input="A detailed fantasy map of a medieval kingdom with mountains, rivers, and labeled cities",
    tools=[{"type": "image_generation"}],
    stream=True,
    image_generation={"partial_images": 3}  # Request 3 partial previews
)

partial_count = 0
for event in stream:
    if event.type == "response.image.partial":
        partial_count += 1
        # Show low-res preview to user
        preview_bytes = base64.b64decode(event.image.partial_b64_json)
        save_preview(f"preview_{partial_count}.png", preview_bytes)
        print(f"Partial {partial_count}/3 received")
    elif event.type == "response.image.done":
        # Final full-quality image
        final_bytes = base64.b64decode(event.image.b64_json)
        Path("fantasy_map.png").write_bytes(final_bytes)
        print("Final image received")

You can request 0 to 3 partial image previews. Each partial is a lower-resolution version of the in-progress image. This creates a satisfying "reveal" effect in user interfaces:

Transparent Backgrounds

The Responses API supports generating images with transparent backgrounds -- essential for logos, product overlays, stickers, and any image that needs to be composited onto other content.

Python
response = client.responses.create(
    model="gpt-image-1",
    input="A cute cartoon robot mascot waving, with a transparent background",
    tools=[{"type": "image_generation"}],
    image_generation={"background": "transparent"}
)

# Save as PNG to preserve transparency
for block in response.output:
    if block.type == "image":
        image_bytes = base64.b64decode(block.image.b64_json)
        Path("robot_mascot.png").write_bytes(image_bytes)
Do

Request transparent backgrounds for any image that will be placed on top of other content -- logos, icons, product cutouts, character art, stickers. Save as PNG to preserve the alpha channel.

Don't

Generate images with backgrounds and then try to remove them in post-processing. AI background removal is imperfect. It is much better to generate with transparency from the start when the option is available.

Output Format Options

The Responses API supports both JPEG and PNG output:

  • PNG: Lossless compression, supports transparency, larger file sizes. Use for images with text, logos, or anything needing transparency.
  • JPEG: Lossy compression, smaller file sizes, no transparency. Use for photographs and content images where file size matters.
Python
response = client.responses.create(
    model="gpt-image-1",
    input="A professional headshot of a friendly businesswoman in a modern office",
    tools=[{"type": "image_generation"}],
    image_generation={"output_format": "jpeg"}  # Smaller file size for photos
)

When to Use Responses API vs Images API

ScenarioBest ChoiceWhy
Single image, no iteration neededImages APISimpler, direct
Iterative design refinementResponses APIMulti-turn context
User-facing with loading statesResponses APIPartial streaming
Transparent backgrounds neededResponses APINative support
Batch generation of similar imagesImages APIParallel calls
Integrated text + image outputResponses APICombined response
The Logo Iteration Workflow
Concept Card

beginner

Design a 4-turn multi-turn conversation flow for creating a company logo using the Responses API. Write out the exact input text for each turn, following the refinement pattern: Turn 1 (composition), Turn 2 (color and style), Turn 3 (text and details), Turn 4 (final polish and transparent background). Include the previous_response_id linkage in your pseudocode.