GPT Image 2 API: setup, parameters, and prompt patterns.
Updated 2026-07-16
GPT Image 2 is OpenAI's third-generation image model, and it is served in the APIsRouter catalog today under the id gpt-image-2. This guide covers the working setup through one OpenAI-compatible endpoint, the parameter surface as OpenAI documents it, and the prompting patterns that use what this model is actually good at.
Quick answer: one request gets you an image.
Point any OpenAI SDK at https://api.apisrouter.com/v1 with your APIsRouter key and call images.generate with model gpt-image-2. That is the entire integration: the gateway speaks the same /v1/images/generations contract as OpenAI, so code written for OpenAI's endpoint runs unchanged after the base URL swap, and code written against the gateway runs against OpenAI if you ever move it back. GPT Image 2 shipped on April 21, 2026 as the successor to gpt-image-1 (April 2025) and gpt-image-1.5 (December 2025). Its launch highlights, per OpenAI's announcement and coverage: reasoning-based generation for complex prompts, multilingual text rendering including Japanese, Korean, Chinese, Hindi, and Arabic, and structured compositions like infographics and maps. It replaced the DALL-E line, which OpenAI retired in May 2026.
import base64, os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["APISROUTER_API_KEY"],
base_url="https://api.apisrouter.com/v1",
)
result = client.images.generate(
model="gpt-image-2",
prompt="Isometric illustration of a tiny data center on a floating island, "
"soft gradients, labeled 'EDGE NODE' on the building",
size="1024x1024",
quality="high",
)
with open("edge-node.png", "wb") as f:
f.write(base64.b64decode(result.data[0].b64_json))The parameter surface, as OpenAI documents it.
GPT Image 2's request options are the most flexible of any current image model, and they are worth knowing precisely. The list below reflects OpenAI's API reference as of July 2026; when calling through a compatibility layer, verify a parameter passes through before a pipeline depends on it, and if a call 400s, reduce to model, prompt, and size first.
- size: free-form WIDTHxHEIGHT strings, for example 1536x864. Both dimensions must be divisible by 16, the aspect ratio must sit between 1:3 and 3:1, and the maximum is 3840x2160. OpenAI marks resolutions above 2560x1440 as experimental.
- quality: low, medium, or high. Quality and size together determine how many image tokens the generation consumes, so this knob directly trades fidelity against cost and latency.
- n: number of images per request, for sampling several candidates from one prompt.
- background: transparent, opaque, or auto. Transparency is a GPT-image-family exclusive among current frontier models and the reason it owns asset workflows; pair it with png or webp output.
- output_format: png, webp, or jpeg.
- stream: partial images stream during generation, so a UI can show the picture forming instead of a spinner.
| Parameter | Values | Note |
|---|---|---|
| size | WIDTHxHEIGHT, divisible by 16 | Aspect 1:3 to 3:1; max 3840x2160; above 2560x1440 experimental |
| quality | low | medium | high | Scales token consumption and latency |
| background | transparent | opaque | auto | GPT image models only; use png or webp |
| output_format | png | webp | jpeg | jpeg cannot carry transparency |
| n | integer | Multiple candidates per prompt |
| stream | boolean, default false | Partial images during generation |
Editing: the second endpoint that matters.
GPT Image 2 edits images as well as it generates them: POST /v1/images/edits takes one or more input images as multipart form data plus a text instruction, and returns the modified image. This covers background replacement, object insertion and removal, restyling, and combining elements from several inputs into one composition. The editing prompt pattern that works is instruction plus invariant: say what changes and what must not. "Replace the sky with dusk, keep the building silhouette and window lights exactly as they are." For multi-image edits, name the role of each input in the prompt, "use the first image's product and the second image's background", so the model knows which is which.
curl -s https://api.apisrouter.com/v1/images/edits \
-H "Authorization: Bearer $APISROUTER_API_KEY" \
-F model="gpt-image-2" \
-F image="@product.png" \
-F prompt="place this product on a marble countertop with soft morning light, keep the product pixels unchanged" \
-F size="1536x1024"Prompt patterns for this model specifically.
One structural tip for infographic-style output: give the model the content as structured text in the prompt, a labeled list of the exact strings and their hierarchy, rather than prose describing roughly what the graphic should say. The difference in label accuracy is large.
- Let it reason: GPT Image 2's launch differentiator is thinking before rendering. Multi-constraint prompts, "a four-panel instruction card where panel three shows the error state", are exactly what the reasoning mode is for; write the constraints out rather than simplifying them away.
- Quote rendered text and name its script: the model's multilingual text rendering covers CJK, Hindi, and Arabic per the launch notes, so "the headline in Japanese: 「夜市」" is a legitimate request, not a hope.
- Use exact dimensions as design intent: because size is free-form, ask for the artboard you actually need, a 1200x628 social card, a 1080x1920 story, instead of generating square and cropping.
- Say "transparent background" in the prompt and set the parameter: the parameter controls the output; stating it in the prompt keeps the model from painting a backdrop to cut around.
- Sample with n at low quality, finalize at high: candidates at low quality cost a fraction of finals, and quality affects rendering fidelity, not concept, so the low-priced drafts predict the expensive winner.
Cost model: tokens, not tiers.
OpenAI bills GPT Image 2 by image tokens: the number of tokens a generation consumes scales with output size and the quality setting, so cost is a continuous function of your parameters rather than a flat per-image tier. OpenAI's docs state the proportionality directly; both latency and cost track token count. The practical budgeting approach: pick your production size and quality, run twenty representative generations, and read the actual per-image cost from the usage log rather than estimating from a rate card. Through the gateway, gpt-image-2 bills per image against your prepaid balance, the current rate is on the pricing page, and the console shows per-request spend, which makes that calibration run a five-minute exercise. Cost discipline then falls out of the parameters: low quality for iteration, exact-size generation instead of oversizing and cropping, webp when the deliverable allows it, and n greater than one only when you will actually judge the candidates.
When GPT Image 2 is the right pick.
Choose it when the job leans on what is unique to it: transparent-background assets, exact arbitrary dimensions, streaming generation in an end-user UX, or instruction-dense compositions where the reasoning mode earns its latency. Its text rendering and general quality make it a strong default for product art, marketing images, and UI illustration. Look elsewhere when the job is volume at minimum unit cost, Google's Nano Banana 2 with its 512px tier and flat per-image pricing is built for that, or ultra-wide banner formats beyond 3:1, which Nano Banana 2 documents natively. For brand-critical typography and localization-grade text, Nano Banana Pro is the premium comparison point. All three sit on this endpoint, so the choice is a routing decision, not an integration project; the comparison page linked below runs the full axis-by-axis.
Failure modes and the fixes.
And the universal first check applies here too: list /v1/models with your key and confirm gpt-image-2 is in the catalog listing before debugging anything deeper. The listing is the ground truth for what your key can call.
- Invalid size errors: dimensions not divisible by 16, or an aspect ratio outside 1:3 to 3:1. Snap to the nearest valid pair; 1200x628 social cards become 1200x624.
- Parameter 400s through the gateway: reduce to model, prompt, size, confirm the call works, then reintroduce options one at a time to find the unsupported field.
- Timeouts on high quality at large sizes: token count drives latency, so 4K-class high-quality renders run tens of seconds. Raise client timeouts before shrinking your images.
- Garbled small text: text fidelity improves with size and quality; a label that fails at 512-wide low quality often renders cleanly at 1536-wide high.
- Transparency arriving as white: check output_format; jpeg flattens transparency, so use png or webp with background transparent.
- Content policy refusals: rephrase rather than retry; the same request repeated is the same refusal plus wasted time.
FAQ
How do I access the GPT Image 2 API?
Through OpenAI directly, or through APIsRouter's OpenAI-compatible endpoint where gpt-image-2 is served today: base URL https://api.apisrouter.com/v1, your gateway key, and the standard images.generate call. No OpenAI account is needed on the gateway path.
What sizes does GPT Image 2 support?
Free-form WIDTHxHEIGHT with both dimensions divisible by 16, aspect ratio between 1:3 and 3:1, up to 3840x2160. OpenAI marks resolutions above 2560x1440 as experimental. This is per OpenAI's API reference as of July 2026.
What does the quality parameter do?
It sets fidelity at low, medium, or high, and with size it determines how many image tokens the generation consumes, which is what OpenAI bills. The working pattern is low for drafts and candidate sampling, high for finals.
Can GPT Image 2 generate transparent backgrounds?
Yes, via the background parameter (transparent, opaque, auto), paired with png or webp output. This is a GPT-image-family capability that Google's Nano Banana models do not document, and it is the main reason to route layered-asset work here.
Does GPT Image 2 replace DALL-E 3?
Yes. OpenAI deprecated DALL-E 2 and 3 with retirement in May 2026, and the GPT Image line is the successor: gpt-image-1 in April 2025, gpt-image-1.5 in December 2025, and gpt-image-2 in April 2026. New integrations should target gpt-image-2.
What does GPT Image 2 cost per image?
OpenAI bills by image tokens, scaling with size and quality, so per-image cost depends on your settings. Through APIsRouter, gpt-image-2 bills per image from a prepaid balance; the current rate is on the pricing page, and the console's per-request log makes calibrating your real cost a short exercise.