Skip to main content
POST

Authorizations

Authorization
string
required
All endpoints require Bearer Token authenticationGet your API Key:Visit the API Key management page to get your API KeyInclude it in the request header:

Body

model
string
default:"gpt-image-2-official"
required
Image generation model nameFixed to gpt-image-2-official (OpenAI official gpt-image-2 model)
prompt
string
required
Text description for image generation
  • Supports English and Chinese, detailed descriptions recommended
  • Pre-submission content moderation / safety review — violations are rejected immediately
size
string
default:"1:1"
Image aspect ratioExternally uses ratio values; internally mapped to actual pixels according to resolution.Supported ratios, plus auto to let the server pick a suitable ratio automatically:
  • auto - Automatic (server picks a ratio based on prompt / reference images)
  • 1:1 - Square (default, social avatars / logos)
  • 3:2 - Landscape (common DSLR ratio)
  • 2:3 - Portrait (vertical posters)
  • 4:3 - Landscape (classic monitor / slideshow)
  • 3:4 - Portrait
  • 5:4 - Landscape
  • 4:5 - Portrait (Instagram vertical post)
  • 16:9 - Landscape (widescreen video thumbnail)
  • 9:16 - Portrait (phone full-screen / short video cover)
  • 2:1 - Landscape (web banner)
  • 1:2 - Portrait
  • 3:1 - Landscape (ultra-wide banner)
  • 1:3 - Portrait (extra-tall poster)
  • 21:9 - Landscape (cinematic ultra-wide)
  • 9:21 - Portrait
Pixel dimensions can also be passed directly, such as 1881x836 / 887x1774.
When size is set to auto, the default ratio is 1:1.
resolution
string
default:"1k"
Resolution tier (new field)Controls the actual output clarity.
  • 1k - 1024 baseline, cost-efficient for daily use (default)
  • 2k - 2048 baseline, suitable for posters / high-definition needs
  • 4k - 3840 baseline, supports the 15 ratios in the mapping table below
4K supports the 15 ratios in the mapping table below; you can also pass the pixel dimensions from the table directly via size.
quality
string
default:"auto"
Image quality
  • auto - Automatic (default, typically equivalent to low)
  • low - Fast and economical, sufficient for rough outlines
  • medium - Balanced
  • high - Maximum precision (4K + high can take >120s)
background
string
default:"auto"
Background mode
  • auto - Automatic (default)
  • opaque - Opaque
  • transparent - ⚠️ gpt-image-2-official does not support transparent backgrounds; the system silently downgrades to auto
moderation
string
default:"auto"
Moderation strength
  • auto - Default moderation strength
  • low - More lenient moderation
output_format
string
default:"png"
Output format
  • png - Default
  • jpeg - Smaller files
  • webp - Optimal for modern browsers
output_compression
integer
Output compression level, range 0-100
  • Only effective for jpeg / webp
n
integer
default:"1"
Number of images to generateRange: 1 ~ 4
Must be a pure number (e.g., 1), do not wrap in quotes
image_urls
array
Reference image URL array
mask_url
string
Mask image URL, used for inpainting
  • Must be used together with image_urls
  1. Ensure the mask image has an Alpha channel before uploading.
  2. The mask image dimensions must match the first reference image.

Size × Resolution Mapping

size × resolution → OpenAI actual pixels (15 ratios × 3 tiers):
Note: Some dimensions are approximated based on multiples of 16 and pixel limits, such as 3:2 / 2:3 @ 2K being 2048×1360 and 21:9 @ 4K being 3840×1648. Use the actual pixels in the table as the source of truth.

Usage Examples

Text-to-image (minimal request)
2K high-definition poster
4K wallpaper
Image-to-image (multi-reference fusion)
Inpainting (mask)
Multiple images (n > 1)
Direct pixel string (advanced)

Response

code
integer
Response status code
data
array
Response data array

Querying Task Results

After successful submission, a task_id is returned. Poll the task status via GET /v1/tasks/{task_id}, see Task Query API for details.

Success Response Example

The usage field reports the billable token usage for this request: For image generation the output is mostly image tokens, so output_tokens_details.image_tokens usually equals output_tokens. In the example above, total_tokens = 22 + 196 = 218. Task status flow: submittedin_progresscompleted / failed. Image access: data.result.images[0].url[0].