Authentication
All API requests require an OpenAI API key passed in the Authorization header. Get your key from the OpenAI platform dashboard.
Integrate GPT Image 2 into your app using the OpenAI API. Text-to-image, image editing, reference image support, and Batch API at 50% cost savings.
Everything you need to integrate GPT Image 2 via the OpenAI API — from authentication to Batch API cost optimization.
All API requests require an OpenAI API key passed in the Authorization header. Get your key from the OpenAI platform dashboard.
Generate a new image from a text prompt using POST /v1/images/generations.
Edit an existing image with a text instruction using POST /v1/images/edits. You pass the original image and a prompt describing the change.
To pass reference images in the API, include them as file inputs alongside your prompt in the images/edits endpoint, or use the multimodal input format for generation requests. GPT Image 2 accepts up to 16 reference images.
The Batch API processes image generation requests asynchronously and charges 50% of standard rates across all token categories. Ideal for bulk generation jobs, scheduled campaigns, dataset creation, and product catalog automation.
Common errors when working with the GPT Image 2 API and how to handle them.
gpt-image-2)import base64
from openai import OpenAI
client = OpenAI()
response = client.images.generate(
model="gpt-image-2",
prompt="Studio product photo of a matte ceramic pour-over kettle on travertine stone, crisp daylight, 85mm lens",
size="1024x1024",
quality="high",
)
image_bytes = base64.b64decode(response.data[0].b64_json)
with open("output.png", "wb") as f:
f.write(image_bytes)
import fs from "node:fs";
import OpenAI from "openai";
const openai = new OpenAI();
const result = await openai.images.generate({
model: "gpt-image-2",
prompt: 'Bold Tokyo street editorial poster reading "TOKYO 2026", crisp typography, 2:3 framing',
size: "1024x1536",
quality: "high",
});
fs.writeFileSync("poster.png", Buffer.from(result.data[0].b64_json, "base64"));
For non-real-time catalogs (such as generating hundreds of Shopify product scenes overnight), submit JSONL jobs to the OpenAI Batch API to cut per-image token cost by 50% with a 24-hour SLA.
Common questions about the GPT Image 2 API, endpoints, authentication, and cost optimization.
The model ID is gpt-image-2. Use it in the model parameter when calling /v1/images/generations or /v1/images/edits.
Pass your OpenAI API key in the Authorization header: Authorization: Bearer YOUR_API_KEY. Store the key in environment variables and never expose it client-side. Get or create API keys at platform.openai.com/api-keys.
GPT Image 2 supports two main endpoints: POST /v1/images/generations for text-to-image generation and POST /v1/images/edits for instruction-based editing of an existing image. Both accept the gpt-image-2 model.
Submit a JSONL file of generation tasks to POST /v1/batches with endpoint: "/v1/images/generations". Poll the batch status until it returns "completed", then retrieve results via the output file ID. The Batch API costs 50% of standard rates across all token categories.
Supported size values: "1024x1024" (1K square), "1536x1024" (2K landscape), "1024x1536" (2K portrait), "2048x2048" (2K square), and "4096x4096" (4K). Higher resolutions generate more output tokens and cost more.
No. GPT Image 2 does not support transparent backgrounds. Passing background: "transparent" via the Responses tool will return an error. If your workflow requires transparent PNGs with alpha channels, you will need to use gpt-image-1.5 for those requests, or post-process the output to remove backgrounds.
Rate limits are organization-level and scale with usage tier. Tier 1 (new accounts): 5 images/minute (IPM). Tier 2: 20 IPM. Tier 3 (requires $100+ spend): 50 IPM. Tier 4: 150 IPM. Tier 5 (requires $1,000+ spend): 250 IPM. All projects in your organization share the same IPM budget. Batch API has a separate quota pool and 50% pricing with a 24-hour SLA.
The following are not supported: transparent backgrounds, streaming responses, function calling, structured outputs, and seed-based reproducibility. These are listed as unsupported on OpenAI's model page. Plan your integration architecture around these constraints — for example, do not build workflows that depend on exact output reproducibility across calls.
By GPT Image 2 Editorial Team · Updated · Sources: OpenAI Docs, awesome-gpt-image-2.
Get your OpenAI API key and start generating images in minutes. Free trial credits available for new accounts.