Developer guide

GPT Image 2 API Guide

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.

API reference

GPT Image 2 API – Key Endpoints

Everything you need to integrate GPT Image 2 via the OpenAI API — from authentication to Batch API cost optimization.

01

Authentication

All API requests require an OpenAI API key passed in the Authorization header. Get your key from the OpenAI platform dashboard.

02

Image Generation Endpoint

Generate a new image from a text prompt using POST /v1/images/generations.

03

Image Editing Endpoint

Edit an existing image with a text instruction using POST /v1/images/edits. You pass the original image and a prompt describing the change.

04

Reference Images

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.

05

Batch API – 50% Cost Savings

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.

06

Error Handling

Common errors when working with the GPT Image 2 API and how to handle them.

Quickstart Code Examples (gpt-image-2)

Python (OpenAI SDK)

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)

JavaScript / TypeScript (Node.js)

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"));

Batch API Cost Savings

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.

FAQ

GPT Image 2 API – Frequently Asked Questions

Common questions about the GPT Image 2 API, endpoints, authentication, and cost optimization.

What is the GPT Image 2 API model ID?

The model ID is gpt-image-2. Use it in the model parameter when calling /v1/images/generations or /v1/images/edits.

How do I authenticate with the GPT Image 2 API?

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.

What endpoints does the GPT Image 2 API support?

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.

How do I use the GPT Image 2 Batch API?

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.

What image sizes does the GPT Image 2 API support?

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.

Does GPT Image 2 API support transparent backgrounds?

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.

What are the GPT Image 2 API rate limits?

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.

What features are not supported by the GPT Image 2 API?

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.

Start Building with GPT Image 2 API

Get your OpenAI API key and start generating images in minutes. Free trial credits available for new accounts.