GPT Image 2
Overview
GPT Image 2 is OpenAI's latest image generation model, optimized for high-resolution output, flexible aspect ratios, and quality-controlled rendering. It supports text-to-image generation as well as image-to-image editing with one or multiple reference images.
Best for: marketing creatives, ultra-wide / vertical compositions, custom-resolution renders, and product imagery requiring sharp detail.
Heads-up: keep a fallback model in production.
gpt-image-2is currently very popular and OpenAI's upstream is occasionally unstable, which may result in slower responses or transient errors. For production traffic we strongly recommend keeping a Gemini model configured as a fallback — prefergemini-3-pro-image-previewfor top quality, orgemini-3.1-flash-image-previewwhen latency and cost matter.
Capabilities
| Feature | Support |
|---|---|
| Text to Image | ✅ Supported |
| Image Editing (image-to-image) | ✅ Supported (URL only) |
| Batch Generation | ⚠️ Currently n=1 only |
| Custom Resolution | ✅ Up to 3840 long edge |
| Quality Tiers | ✅ low · medium · high · auto |
Pricing
Credits per image, by output size × quality. Quality auto is billed at the same rate as high.
| Tier | Long edge | low | medium | high / auto |
|---|---|---|---|---|
| 1K | ≤ 1536px | 1 | 4 | 14 |
| 2K | ≤ 2048px | 2 | 17 | 67 |
| 4K | ≤ 3840px | 4 | 34 | 133 |
Pricing notice. Medium / high tiers are priced at roughly 80% of OpenAI's official per-image cost (source). The
lowtier is billed as a flat 1 credit minimum / image because of credit-granularity rounding, which can be higher than 80% of official for very small generations. Thesize=autorequest defaults to the 1K tier;quality=autois treated ashigh. The displayedcostCreditsfor a request equals(matrix value) × n.
Examples
| Request | Tier | Quality | Credits / image |
|---|---|---|---|
size: "auto", quality: "auto" (default) | 1K | high | 14 |
size: "1024x1024", quality: "low" | 1K | low | 1 |
size: "1536x1024", quality: "medium" | 1K | medium | 4 |
size: "2048x1152", quality: "high" | 2K | high | 67 |
size: "3840x2160", quality: "high" | 4K | high | 133 |
Supported Sizes
You can either pass one of the popular presets or specify a fully custom WIDTHxHEIGHT.
Popular Presets
1024x1024 · 1536x1024 · 1024x1536 · 2048x2048 · 2048x1152 · 3840x2160 · 2160x3840 · auto
Custom Dimensions
Custom WIDTHxHEIGHT values must satisfy all of the following:
- Long edge no greater than 3840px
- Width and height must both be multiples of 16
- Aspect ratio must not exceed 3:1 (long edge ≤ 3 × short edge)
- Total pixel count between 655,360 and 8,294,400
If size is omitted or set to auto, the model picks the most appropriate dimensions for your prompt.
Quality Options
| Value | Description |
|---|---|
low | Fastest generation, lowest fidelity |
medium | Balanced speed and quality |
high | Best detail and fidelity |
auto | Model chooses the best tier (default) |
Quick Start
Replace YOUR_API_KEY with your actual API key. Don't have one yet? Create an API key here.
curl -X POST "https://api.nanobananaapi.dev/v1/images/generate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "An orange tabby cat wearing an orange scarf hugging an otter, warm illustration style",
"n": 1,
"size": "3840x2160",
"quality": "high"
}'const res = await fetch('https://api.nanobananaapi.dev/v1/images/generate', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'gpt-image-2',
prompt:
'An orange tabby cat wearing an orange scarf hugging an otter, warm illustration style',
n: 1,
size: '3840x2160',
quality: 'high',
}),
});
const result = await res.json();
console.log(result.data.url);import requests
res = requests.post(
'https://api.nanobananaapi.dev/v1/images/generate',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
json={
'model': 'gpt-image-2',
'prompt': 'An orange tabby cat wearing an orange scarf hugging an otter, warm illustration style',
'n': 1,
'size': '3840x2160',
'quality': 'high',
},
timeout=60,
)
result = res.json()
print(result['data']['url'])API Parameters Reference
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Must be gpt-image-2 |
prompt | string | Yes | Text description, up to 2000 characters |
image | string | string[] | Edit only | Public URL or array of public URLs of reference images. Base64 / data: URLs are NOT supported by gpt-image-2 — upload to a CDN first and pass the URL. Up to 14 images. |
n | integer | No | Number of images to generate. Currently only 1 is supported (default 1); requests with n > 1 are rejected. Call the API multiple times if you need more. |
size | string | No | A popular preset, custom WIDTHxHEIGHT, or auto (default auto) |
quality | string | No | low · medium · high · auto (default auto) |
Image Editing (image-to-image)
For editing or composing from reference images, send the request to /v1/images/edit (or the OpenAI-compatible /api/v1/images/edits) with the image field set to one or more public URLs. Base64 / data: URLs are not accepted by gpt-image-2.
curl -X POST "https://api.nanobananaapi.dev/v1/images/edit" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Replace the background with a snowy mountain at sunset, keep the subject",
"image": "https://cdn.example.com/source.png",
"n": 1,
"size": "auto",
"quality": "high"
}'const res = await fetch('https://api.nanobananaapi.dev/v1/images/edit', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'gpt-image-2',
prompt: 'Compose these two products on a clean studio background',
image: [
'https://cdn.example.com/product-a.png',
'https://cdn.example.com/product-b.png',
],
n: 1,
size: '2048x1152',
quality: 'high',
}),
});
const result = await res.json();
console.log(result.data.url);Best Practices
- Use
autofirst: Let the model choose size and quality for the best balance, then fine-tune. - Custom dimensions: Pick multiples of 16 close to a popular preset to avoid being rejected.
- Aspect ratio cap: For ultra-wide banners, keep ratio ≤ 3:1 (e.g.
3072x1024, not3840x1024). - Prompt length: Stay under 2000 characters; concise prompts often produce sharper results.
Frequently Asked Questions
Does gpt-image-2 support image editing?
Yes. Send the request to /v1/images/edit with image set to a public URL (or array of URLs). Base64 / data: URLs are not supported by gpt-image-2 — host the file on a CDN first.
Why is my custom size rejected? The most common causes are: a dimension that is not a multiple of 16, a long edge greater than 3840, an aspect ratio over 3:1, or total pixels outside the 655,360–8,294,400 range.
How are credits calculated?
Credits per image are determined by the size tier (1K / 2K / 4K, inferred from the long edge) and the quality (low / medium / high, with auto billed at the high rate). See the Pricing section. The deduction equals (matrix value) × n. All credits are priced at 80% of the official OpenAI API rate.
Related
- Text to Image API — Full API reference for image generation
- Gemini 3 Pro Image Preview — Professional studio quality
- Gemini 3.1 Flash Image Preview — High efficiency with extended resolutions
- Gemini 2.5 Flash Image — Fastest speed, lowest cost