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-2 is 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 — prefer gemini-3-pro-image-preview for top quality, or gemini-3.1-flash-image-preview when latency and cost matter.

Capabilities

FeatureSupport
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 Tierslow · medium · high · auto

Pricing

Credits per image, by output size × quality. Quality auto is billed at the same rate as high.

TierLong edgelowmediumhigh / auto
1K≤ 1536px1414
2K≤ 2048px21767
4K≤ 3840px434133

Pricing notice. Medium / high tiers are priced at roughly 80% of OpenAI's official per-image cost (source). The low tier 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. The size=auto request defaults to the 1K tier; quality=auto is treated as high. The displayed costCredits for a request equals (matrix value) × n.

Examples

RequestTierQualityCredits / image
size: "auto", quality: "auto" (default)1Khigh14
size: "1024x1024", quality: "low"1Klow1
size: "1536x1024", quality: "medium"1Kmedium4
size: "2048x1152", quality: "high"2Khigh67
size: "3840x2160", quality: "high"4Khigh133

Supported Sizes

You can either pass one of the popular presets or specify a fully custom WIDTHxHEIGHT.

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

ValueDescription
lowFastest generation, lowest fidelity
mediumBalanced speed and quality
highBest detail and fidelity
autoModel 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

ParameterTypeRequiredDescription
modelstringYesMust be gpt-image-2
promptstringYesText description, up to 2000 characters
imagestring | string[]Edit onlyPublic 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.
nintegerNoNumber 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.
sizestringNoA popular preset, custom WIDTHxHEIGHT, or auto (default auto)
qualitystringNolow · 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 auto first: 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, not 3840x1024).
  • 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.