As of November 10, 2026, gpt-image-1 is no longer available through the direct OpenAI API. OpenAI lists it as shut down on October 23, 2026. For a new integration or migration, use a currently supported model such as gpt-image-2.6-flare or gpt-image-2.6-sunburst. OpenAI describes Flare as the faster-iteration choice and Sunburst as the option for more detailed work or precise edits. (OpenAI API model reference, OpenAI image prompting guide)
Call the direct OpenAI Images API
For a single image generated from a prompt, use the Images API. Its generation operation is POST /v1/images/generations; the direct OpenAI endpoint is https://api.openai.com/v1/images/generations. Send an Authorization: Bearer $OPENAI_API_KEY header and Content-Type: application/json. The model goes in the JSON body. Do not substitute an Azure resource endpoint or a third-party gateway URL. (OpenAI Images API reference, OpenAI API authentication reference)
Before you run the example
- Create an OpenAI API key and make it available to your server-side application as
OPENAI_API_KEY. - Install the Python SDK with
pip install --upgrade openai. - Check model access: OpenAI says you may need to complete API Organization Verification in the developer console before using GPT Image models. (Image generation guide)
- Keep the key on your server; do not embed it in browser or mobile-app code. (API authentication reference)
On macOS or Linux, set the key in your shell session:
export OPENAI_API_KEY="your_api_key"
Python: generate and save a PNG
This example explicitly requests PNG output, then decodes the returned image data and writes generated.png in the current directory. The API reference documents b64_json as the generated-image field returned by default for GPT Image models; 1024x1024 and medium are documented size and quality options for GPT Image 2.6. (Images API reference, image prompting guide)
import base64
from openai import OpenAI
client = OpenAI() # Reads OPENAI_API_KEY from the environment
result = client.images.generate(
model="gpt-image-2.6-flare",
prompt="A small glass greenhouse in a garden at sunrise, editorial illustration",
size="1024x1024",
quality="medium",
output_format="png",
)
image_bytes = base64.b64decode(result.data[0].b64_json)
with open("generated.png", "wb") as image_file:
image_file.write(image_bytes)
print("Saved generated.png")
To try Sunburst instead, change model to gpt-image-2.6-sunburst. For a different output type, check the current Image API options: the guide lists PNG, JPEG, WebP, SVG, and GIF generation. (Image prompting guide)
Migrating an existing gpt-image-1 integration
- Replace the retired model ID. Select a supported model, such as
gpt-image-2.6-flareorgpt-image-2.6-sunburst; do not continue sending requests togpt-image-1. (Images API reference) - Check request options and output handling. Explicitly set the output format if your application expects a particular file type. Decode
b64_jsonfor GPT Image output rather than assuming the response contains an image URL. (Images API reference) - Test before switching production traffic. Compare your existing prompts and reference images, output dimensions, edit behavior, latency, and downstream file handling. Treat this as a migration test, not a guarantee that different models produce identical results.
- Protect the production credential. Keep it in server-side environment configuration or a secrets manager. For an application workload, OpenAI documents project service accounts as a separate identity option from a developer’s personal key. (API keys and service accounts)
Access and common request failures
GPT Image use may require API Organization Verification; check the notice in your developer console if a request reports an access restriction. If you receive a 401, check that the key is correct and that the request is using the intended organization. (Image generation guide, OpenAI error codes)
For a 429, read the response error details before retrying. OpenAI’s guidance distinguishes rate-limit responses from exhausted credits or organization/project spending limits. Check the applicable model and current limits in your organization’s Limits page; pace requests and use retry guidance for rate limits, but address the balance or spending limit when the error identifies billing as the cause. (OpenAI rate-limit troubleshooting)
Direct OpenAI, Azure, and gateways are different
This walkthrough uses the direct OpenAI API. Azure OpenAI uses Azure resource endpoints, deployments, and Azure authentication; a third-party gateway uses its own endpoint and credentials. Keep each provider’s model identifier, URL, authentication, and response handling paired with that provider’s documentation.
Sources
Create image — OpenAI API Reference
API Overview — OpenAI API Reference
Troubleshooting API rate limits and 429 errors — OpenAI Help Center
