gpt-image-2 Image Generation API
Use `POST /v1/images/generations` to call the unified image generation entry for `gpt-image-2`.
https://zx1.deepwl.net/v1/images/generationscurl -X POST https://zx1.deepwl.net/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '
{
"model": "gpt-image-2",
"prompt": "A modern homepage illustration for an API platform, white background, teal-blue blocks, clean whitespace",
"n": 1,
"size": "1536x1024",
"response_format": "url"
}'{
"created": 1735689600,
"data": [
{
"url": "https://.../images/img-abc123.png",
"revised_prompt": "A modern homepage illustration for an API platform, white background, teal-blue blocks, clean whitespace"
}
]
}gpt-image-2 uses the unified image generation entry (POST /v1/images/generations), suitable for text-to-image requests based on standard ratios and size tiers.
- Select the target model by setting
model = "gpt-image-2". - Supports both
urlandb64_jsonresponse formats. - You can include
imagein JSON as a reference image; whether it takes effect depends on the actual image channel that is matched. - If
nis omitted or explicitly set to0, the unified layer falls back to1.
Request Headers
Authorizationstring必填Authentication header. Uses a Bearer token, e.g. Bearer YOUR_API_KEY.
Content-Typestring必填Request content type, must be application/json.
Request Body
modelstring必填Must be set to gpt-image-2.
promptstringGeneration prompt. For text-to-image semantics, this should be treated as required.
nintegerNumber of images to generate. If omitted or explicitly set to 0, the unified layer falls back to 1.
sizestringOutput size. The official gpt-image-2 accepts auto (default — the model picks a size from the prompt) and arbitrary WIDTHxHEIGHT custom sizes: both dimensions must be multiples of 16, aspect ratio between 1:3 and 3:1, longest edge up to 3840, and total pixels between 655360 and 8294400 (anything above 2560x1440 is experimental). Common base tiers are 1024x1024, 1536x1152, 1536x1024, 1024x1536, 1920x1080, 1080x1920.
imagestring | array<string> | objectOptional reference image input. Commonly written as a Base64 string or Base64 array, suitable for channels that require image style reference.
response_formatstringResponse format. Common values are url and b64_json.
qualitystringQuality field. Official values are low, medium, high, auto (default auto). low suits fast drafts; high gives maximum fidelity at significantly higher token cost. Whether it actually takes effect depends on the final matched channel.
stylestring | objectStyle field, passed through as-is to supported upstreams.
backgroundstring | objectBackground control field, passed through as-is to supported upstreams. Note: the official gpt-image-2 only supports opaque and auto (default auto) — transparent is not supported (unlike gpt-image-1).
output_formatstringOutput image format. Official values are png (default), jpeg, webp.
output_compressionintegerOutput compression level, integer 0–100. Only applies when output_format is jpeg or webp.
moderationstringContent moderation level. Official values are auto (default) and low (less restrictive filtering).
watermarkbooleanExplicit watermark switch. false and omission have different semantics.
Base Ratios and Size Tiers
| Preset | Actual Target Size |
|---|---|
1:1 | 1024x1024 |
4:3 | 1536x1152 |
3:2 | 1536x1024 |
2:3 | 1024x1536 |
16:9 | 1920x1080 |
9:16 | 1080x1920 |
If the actual channel does not natively accept the target size, the gateway or plugin will fall back to a closer official size and append the ratio intent to the prompt.
Request Examples
Response Examples
Response Fields
createdintegerGeneration timestamp.
dataarray<object>Array of generation results.
urlstringThe image URL returned when response_format = url.
b64_jsonstringThe Base64 image data returned when response_format = b64_json.
revised_promptstringSome upstreams rewrite the prompt and return it in this field.