OpenAI GPT Image generation

Generate images from text with the GPT Image family (gpt-image-2.5, 2, 1.5, and 1) using the OpenAI SDK.

POST /v1/images/generations

Auth: {'type': 'bearer', 'prefix': 'sk-', 'description': 'Pass your API key in the `Authorization: Bearer sk-xxx` header.'}

> **This endpoint supports only text-to-image (t2i)**. For image-to-image (i2i / image-to-image) generation based on existing images, please use [`/v1/images/edits`](./openai-gpt-image-edit) (multipart protocol). OpenAI GPT Image Series Image Generation — `gpt-image-2.5-flare` / `gpt-image-2.5-sunburst` (Latest) / `gpt-image-2` / `gpt-image-1.5` / `gpt-image-1`. ## Model matrix | Model | Features | |---|---| | `gpt-image-2.5-flare` | Speed mode, suitable for high-frequency daily generation and rapid sketching | | `gpt-image-2.5-sunburst` | Accuracy mode, suitable for detailed creations requiring precise editing | | `gpt-image-2` | Supports complex compositions and high resolution (up to 3840px), strong reasoning capability | | `gpt-image-1.5` | Balances quality and speed | | `gpt-image-1` | Classic version, with the broadest compatibility | ## Supported sizes (by model) | size | gpt-image-1 / 1.5 | gpt-image-2 / 2.5 | |---|---|---| | `auto` | ✅ (model default) | ✅ (model default) | | `1024x1024` | ✅ | ✅ | | `1024x1536` / `1536x1024` | ✅ | ✅ | | `2048x2048` / `2048x1152` | — | ✅ | | `3840x2160` / `2160x3840` (4K) | — | ✅ | | `1792x1024` / `1024x1792` (DALL-E 3 compatible) | ⚠️ Partial | — | | `256x256` / `512x512` (DALL-E 2 compatible) | ⚠️ Partial | — | ⚠️ **size constraint (`gpt-image-2` and `gpt-image-2.5-*`)**: Both width and height must be multiples of 16, the longest side ≤ 3840px, total pixels between 655,360 and 8,294,400, aspect ratio ≤ 3:1. ## quality tier | quality | Description | |---|---| | `auto` (default) | Model automatically selected | | `low` / `medium` / `high` | gpt-image-* native three tiers | | `standard` / `hd` | OpenAI SDK compatible alias (customers migrated from DALL-E 3 can use it directly) | > Different tiers have significant impacts on image details and generated token count. ## response format `gpt-image-*` always returns inline base64 (`data[].b64_json`), does not support `url` format. The `response_format` field is retained for backward compatibility with SDKs, but is actually ignored by upstream. Returns top-level containing `created / data / background / output_format / quality / size / usage`. The `usage.input_tokens_details` field provides detailed breakdown of text and image tokens. ## Usage tips - Call `client.images.generate(model='gpt-image-2.5-sunburst', prompt='...', size='1024x1024', quality='high')` via client SDK - Compatible with OpenAI Python SDK / Node SDK standard usage - Single base64 image size can reach hundreds of KB to 1 MB+, clients must decode and save it themselves - Does not support streaming (`stream` / `partial_images` fields will be ignored) - `style` (DALL-E 3 fields) is ineffective in `gpt-image-*`, automatically selected by model

Request body

modelstringrequiredImage model ID, such as `gpt-image-2.5-flare` / `gpt-image-2.5-sunburst` / `gpt-image-2` / `gpt-image-1.5` / `gpt-image-1`
promptstringrequiredText description, supports both Chinese and English; more specific descriptions lead to higher generation quality
nintegerNumber of generated images
sizestringImage size (width × height). Supported ranges vary by model — `gpt-image-2` supports 4K + custom (width and height multiples of 16, ≤3840px), `gpt-image-1` only supports 1024² / 1024×1536 / 1536×1024 plus partial compatibility with DALL-E
qualitystringQuality level; affects detail and inference token count. `low/medium/high` has native three levels; `standard/hd` is an OpenAI SDK-compatible alias (DALL-E style); `auto` is automatically selected by the model
response_formatstringResponse format. `gpt-image-*` always returns `b64_json` (upstream ignores this field); `url` only applies to DALL-E series
output_formatstringOutput image encoding format (only supported by `gpt-image-*`)
output_compressionintegerCompression level (0-100, higher quality means lower volume); only effective for `jpeg` / `webp`
backgroundstringBackground type; `transparent` requires pairing with `output_format=png` or `webp`
moderationstringContent moderation strictness; `auto` is default, `low` is more lenient (still subject to upstream review)
userstringOptional client-provided user identifier for upstream abuse detection

Responses

Example

curl https://api.router.ai/v1/images/generations \
  -H "Authorization: Bearer sk-xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-sunburst",
    "prompt": "雪夜中的东京街头, 霓虹灯倒影在湿润的柏油路上, 电影感",
    "size": "1024x1024",
    "quality": "high",
    "n": 1
  }'

API reference