Yes—GPT Image 2 is available through OpenAI’s API. Use the model ID gpt-image-2. OpenAI lists both image generation and image editing endpoints for this model, and identifies gpt-image-2-2026-04-21 as a dated snapshot. (developers.openai.com)
OpenAI also lists GPT Image 2.6 Flare and Sunburst as separate model offerings. This guide focuses on integrating gpt-image-2; check the current model documentation when choosing a model for a new project. (developers.openai.com)
Generate an image with the OpenAI API
You’ll need an OpenAI API key, Python, and the OpenAI Python SDK. Install the SDK with pip install openai and set OPENAI_API_KEY in your server environment. The SDK’s OpenAI() client reads that environment variable by default. Keep the key out of browser and mobile-app code. (github.com)
This example calls the Images API generation method, explicitly requests PNG output, decodes the returned Base64 image data, and saves it as image.png. OpenAI documents b64_json as the default image data for GPT image models. (developers.openai.com)
import base64
from openai import OpenAI
client = OpenAI()
result = client.images.generate(
model="gpt-image-2",
prompt="A small blue ceramic vase on a white table, soft morning light",
output_format="png",
)
image_bytes = base64.b64decode(result.data[0].b64_json)
with open("image.png", "wb") as f:
f.write(image_bytes)
Edit an existing image
For an edit, pass an open image file and an instruction to the Images API edit method. The API accepts PNG, WebP, or JPEG inputs; for GPT Image models, each input image must be under 50 MB. This single-file example saves the returned PNG as edited.png. (developers.openai.com)
import base64
from openai import OpenAI
client = OpenAI()
with open("input.png", "rb") as image_file:
result = client.images.edit(
model="gpt-image-2",
image=image_file,
prompt=(
"Change only the background to a pale blue studio backdrop; "
"preserve the product and its lighting."
),
output_format="png",
)
image_bytes = base64.b64decode(result.data[0].b64_json)
with open("edited.png", "wb") as f:
f.write(image_bytes)
The edit endpoint supports GPT Image models and documents image-file inputs; the model page lists image input and the edit endpoint for gpt-image-2. Review the returned image rather than assuming every detail will be preserved. (developers.openai.com)
Which API route should you use?
- Images API: A direct route for generating an image from a prompt or editing an existing image. GPT Image 2 supports the generation and edit endpoints. (
developers.openai.com) - Responses API: The GPT Image 2 model page also lists the Responses endpoint. OpenAI describes the Responses API image-generation tool for image creation within conversations or multi-step flows. (
developers.openai.com) - Codex or ChatGPT: These are separate product experiences; they do not replace API credentials or API request instructions.
- Third-party gateways: A gateway has its own endpoint, credentials, model-name format, response handling, and billing. For example, Inworld’s published integration uses an Inworld endpoint and key; those are not OpenAI-direct API instructions or prices.
Model availability, limits, and capabilities
OpenAI describes GPT Image 2 as supporting text and image input, image output, image generation, and editing. Use gpt-image-2 as the model alias, or the documented snapshot gpt-image-2-2026-04-21 when you need to pin that version. (developers.openai.com)
The model page lists these tier limits: (developers.openai.com)
| API tier | Tokens per minute (TPM) | Images per minute (IPM) |
|---|---|---|
| Free | Not supported | Not supported |
| Build | 250,000 | 20 |
| Launch | 3,000,000 | 150 |
| Grow | 8,000,000 | 250 |
These are published tier figures, not a guarantee that every account has the same effective capacity. Rate limits can depend on the organization’s and project’s allocation; check the limits shown for your account before planning production traffic. OpenAI’s image-generation guide says API Organization Verification may be required before using GPT Image models. (developers.openai.com)
OpenAI’s April 21, 2026 developer announcement described stronger text rendering, layout, editing, resolution, and multilingual rendering as improvements. Those are attributed capability claims, not a guarantee of exact text or identical results for every prompt.
GPT Image 2 API pricing
OpenAI’s pricing page lists these GPT Image 2 rates, in USD per 1 million tokens:
| Modality | Input | Output | Cached input |
|---|---|---|---|
| Image | $4.00 | $15.00 | $1.00 |
| Text | $2.50 | — | $0.625 |
These are token rates, not a fixed price per generated image. Total cost depends on usage; use OpenAI’s image-generation cost calculator for estimates. The listed rates were checked November 10, 2026.
Don’t substitute gateway pricing for these direct API rates. Inworld, for instance, publishes prices for its own inference offering. Those prices do not establish OpenAI-direct billing or a fixed cost per image.
Production checklist
- Confirm
gpt-image-2is the model you intend to call; GPT Image 2.6 Flare and Sunburst are separate API offerings. (developers.openai.com) - Make requests from a trusted server and keep your API key out of client-side code. (
github.com) - Check your organization’s verification status and the limits assigned to your organization and project. (
developers.openai.com) - Test representative generation and editing prompts, including text-heavy images, and review outputs before delivering them to users.
- Estimate spend using token usage and OpenAI’s image-generation cost calculator; don’t assume one flat price per image or use a gateway’s rates as OpenAI-direct pricing.
Sources
GPT-Image-2 Model | OpenAI API
Create image | OpenAI API Reference
Create image edit | OpenAI API Reference
OpenAI Developers announcement of GPT Image 2 API availability
GPT Image 2 by OpenAI — Pricing, Specs & API Access | Inworld
