GPTMap

GPT Image 2 API in Practice: From Text-to-Image to Image Editing

The official image API after DALL·E's exit. This tutorial covers GPT Image 2 generation and editing calls, saving b64 output to disk, quality parameters, and the API-versus-ChatGPT split.

TL;DR
GPT Image 2 is the official image model now: client.images.generate(model="gpt-image-2", prompt=...) for generation, images.edit with the original for editing; responses return base64 (result.data[0].b64_json) to decode and save. quality parameters shape the output. DALL·E is fully retired (API models 5-12, ChatGPT GPT 8-30) -- GPT Image 2 is the only path.
The GPT Image 2 API is OpenAI's image generation and editing interface: natural-language prompts drive generation (images.generate) or editing (images.edit), and images return as base64 for direct disk writes or downstream processing.

How to

  1. Write the prompt and call generate

    client.images.generate(model="gpt-image-2", prompt=...) -- the more specific the prompt (subject, style, composition, lighting), the more stable the output.

  2. Decode the base64 and save

    Take result.data[0].b64_json, decode with base64.b64decode (Python) or Buffer.from (Node), and write the PNG to disk.

  3. Add parameters as needed

    quality controls the output tier. For batches, draft at low quality and re-render picks at high quality.

  4. Edit existing images with edit

    images.edit takes the original image plus an edit instruction -- ideal for local changes and variants; it also returns b64_json.

The GPT Image 2 API is OpenAI's image generation and editing interface: natural-language prompts drive generation or editing, and images return as base64. With DALL·E fully retired -- the API models removed on 2026-05-12 and the in-ChatGPT DALL·E GPT retired on 2026-08-30 -- GPT Image 2 is the only carrier of OpenAI image generation. This tutorial provides Python and Node examples for generation, disk writes, and editing, verified line-by-line against the official Image generation guide.

Note: the code here was checked against the official guide (docs-checked version); lastTestedAt marks the verification date. Parameter values follow the official guide.

1. Your First Image (Python)

The official guide's Python example takes this shape -- model explicitly set to gpt-image-2, output taken from result.data[0].b64_json and decoded to disk:

import base64
from openai import OpenAI

client = OpenAI()
prompt = "A watercolor otter reading in a library, warm light"

result = client.images.generate(
    model="gpt-image-2",
    prompt=prompt,
)

image_base64 = result.data[0].b64_json
image_bytes = base64.b64decode(image_base64)
with open("otter.png", "wb") as f:
    f.write(image_bytes)

Three things people get wrong: model="gpt-image-2" must be explicit; prompt is the only required creative input; the output lives in data[0].b64_json -- an encoded string, not binary, so writing it directly produces a corrupted image.

2. The Node.js Equivalent

import fs from "fs";
import OpenAI from "openai";

const client = new OpenAI();

const prompt = "A watercolor otter reading in a library, warm light";

const result = await client.images.generate({
  model: "gpt-image-2",
  prompt,
});

const image_base64 = result.data[0].b64_json;
const image_bytes = Buffer.from(image_base64, "base64");
fs.writeFileSync("otter.png", image_bytes);

3. Editing: images.edit

Editing goes through images.edit -- the difference from generation is the original image:

const response = await client.images.edit({
  model: "gpt-image-2",
  image: images, // the original image(s) to edit
  prompt,        // e.g. "replace the background with a snowy night, keep the subject"
});

const image_base64 = response.data[0].b64_json;

Typical uses: local changes ("swap the background"), product-image variants, consistency rewrites that keep the subject. Edit quality depends heavily on how clearly the instruction says what to change and what to preserve.

4. The quality Parameter

Common parameters from the official guide:

  • quality: the output tier (the examples show "high" / "low"). Batch pipelines should be two-stage -- draft at low quality, re-render picks at high; the cost difference is easy to see.

Trust the official guide for parameter combinations; do not guess parameter names from DALL·E-era memory -- the two API generations are not the same surface.

5. API or ChatGPT's Built-in Generation?

This week (2026-08-30) the official DALL·E GPT inside ChatGPT retired on schedule, making ChatGPT Images the product-side entry. How the two paths split:

DimensionChatGPT (ChatGPT Images)API (GPT Image 2)
InteractionConversational iteration, human picksProgrammatic calls, batch-friendly
AutomationNone (manual)Fully orchestrable
CostWithin subscription allowanceBilled per use
DownstreamManual exportStraight into pipelines (base64 is a file)

Both run on GPT Image 2 and prompts transfer -- a prompt tuned in ChatGPT moves directly into the API.

Frequently Asked Questions

1. How does GPT Image 2 relate to DALL·E?

It replaces it. The DALL·E 2/3 API models were hard-removed on 2026-05-12, and the official DALL·E GPT inside ChatGPT retired on 2026-08-30. On both the product and API sides, OpenAI image generation is now carried by GPT Image 2 -- changing the model parameter from dall-e-3 to gpt-image-2 is step one of any migration.

2. How do I handle the base64 response?

result.data[0].b64_json holds the base64-encoded image. Decode with base64.b64decode in Python and write as binary; in Node use Buffer.from(image_base64, "base64") then fs.writeFileSync. The official guide demonstrates both disk-write patterns.

3. How do I edit an image?

Use images.edit: pass model (gpt-image-2), image (the original), and prompt (the edit instruction); the response is b64_json again. Ideal for local changes, style transfers, and variants of an existing image.

4. What does quality do?

quality sets the output tier (the official examples show "high" / "low"); higher quality costs more -- batch pipelines can draft at low quality, then re-render picks at high quality. Other parameter values follow the official guide.

5. Should I use the API or ChatGPT's built-in generation?

Split by workflow: interactive, single-image, conversation-driven creation belongs in ChatGPT Images; programmatic, batch, product-integrated generation belongs in the API. Both run on GPT Image 2, so prompts transfer between them.

6. Can generated images go straight to production?

Technically yes (base64 is just a file), but keep a human-review or content-filtering step for content -- how well the model follows a prompt varies with prompt quality, so validate prompt stability on a small sample before scaling batches.

Next Steps

Key points

  • Generation: client.images.generate(model="gpt-image-2", prompt=...) -- the model must be explicitly set to gpt-image-2
  • Responses are base64: result.data[0].b64_json, decoded with base64.b64decode (Python) or Buffer.from (Node) before saving
  • Editing: images.edit({ model: "gpt-image-2", image: original, prompt: instruction }) -- original image plus instruction
  • Parameters like quality ("high" / "low") shape the output; higher quality costs more
  • DALL·E is fully gone: API models removed 2026-05-12, the ChatGPT DALL·E GPT retired 2026-08-30 -- GPT Image 2 is the only path for new work
  • Division of labor: interactive creation in ChatGPT Images, programmatic batches via the API

Frequently asked questions

It replaces it. The DALL·E 2/3 API models were hard-removed on 2026-05-12, and the official DALL·E GPT inside ChatGPT retired on 2026-08-30. On both the product and API sides, OpenAI image generation is now carried by GPT Image 2 -- changing the model parameter from dall-e-3 to gpt-image-2 is step one of any migration.

Official references

Related articles

Subscribe to GPTMap Weekly

One email every Monday: curated OpenAI updates, deep dives, and best practices. No ads, unsubscribe anytime.

GPTMap EditorialPublished 2026-08-31 5 min read
Test environment (EEAT)
Last tested: 2026-08-31
Model used: gpt-5.6