C.W.K.
Stream
Lesson 03 of 05 · published

Image Generation

~22 min · image-gen, gpt-image-1.5

Level 0Tokenizer
0 XP0/54 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

OpenAI's gpt-image-1.5 model generates images from text prompts. You can use it via the Images API or as a built-in tool in the Responses API.

The provider question, finally settled

For first-party image gen on OpenAI, the answer for new code is gpt-image-1.5. It understands long, structured prompts better than DALL-E 3, supports reference images natively (image-to-image, style transfer), and is the active development surface. DALL-E 3 still works for legacy code; nobody should pick it for new code.

For non-OpenAI alternatives, Google's Nano Banana Pro (gemini-3-pro-image-preview) is competitive on prompt fidelity and reference-image quality. cwkPippa's image-gen skill defaults to Nano Banana Pro and switches to gpt-image-1.5 only on explicit request — the choice is per-task, not per-vendor-loyalty.

Code

images.generate with gpt-image-1.5·python
import base64

result = client.images.generate(
    model="gpt-image-1.5",
    prompt="A photorealistic golden retriever in a field of sunflowers",
    n=1,
    size="1024x1024",       # "1024x1024", "1536x1024", "1024x1536", "auto"
    quality="high",          # "auto", "high", "medium", "low"
    output_format="png",     # "png", "jpeg", "webp"
    background="opaque",     # "transparent", "opaque", "auto"
)

image_bytes = base64.b64decode(result.data[0].b64_json)
with open("output.png", "wb") as f:
    f.write(image_bytes)
Reference-based generation (image-to-image)·python
response = client.responses.create(
    model="gpt-4.1",
    input="Draw a minimalist logo for a coffee shop called 'Dawn Brew'",
    tools=[{"type": "image_generation"}],
)

for item in response.output:
    if item.type == "image_generation_call":
        img = base64.b64decode(item.result)
        with open("logo.png", "wb") as f:
            f.write(img)

External links

Exercise

Generate 3 images from one structured prompt at sizes 1024x1024, 1792x1024, 1024x1792. Save them and embed in a small HTML report. Compare per-image cost.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.