Image / GPT Image

GPT Image 2 Official Image Generation API

asOpenAI localized example text:Path, Request Bodyand OpenAIimages/generations, images/edits, can OpenAI SDK.in use v2 endpoint (POST /api/v2/open/aigc/gpt-image-2-official, camelCase Request Body)localized example textGPT Image v2 endpoint.task and, can.

Overview

gpt-image-2-official OpenAIgpt-image-2, in Request Bodymodel fieldin.

Capabilitylocalized example textRequestFormat
Text-to-Image / Image-to-ImagePOST /v1/images/generationsapplication/json
Image Editing (upload a file)POST /v1/images/editsmultipart/form-data
Query Tasklocalized example textGET /v1/images/generations/{taskId}—
  • supported Text-to-Image, Image-to-Image and Mask repainting
  • supported up to 16 images Reference image, 1–4 images image
  • supported 15 and 1K / 2K / 4K Resolution
  • supported PNG / JPEG; PNG can
  • token, query resultsreturnusage
  • query resultslocalized example textoutput after; image Base64 will as URL
  • default:task booking after Usually 1 seconds returntaskId, query image;async=false can as, Request OpenAI imageBase URL:https://mm-internal-cn.leonecloud.com

localized example text```http Authorization: Bearer YOUR_API_KEY


## Create Task

**POST** `/v1/images/generations`

`Content-Type: application/json`.defaultlocalized example text——task bookingafter Usually 1 seconds return`taskId`, etc. image.Requestimage when`async=false`, see below[localized example text](#-async-false).

### Text-to-Imagelocalized example text```bash
curl -X POST "https://mm-internal-cn.leonecloud.com/v1/images/generations" \
 -H "Authorization: Bearer YOUR_API_KEY" \
 -H "Content-Type: application/json" \
 -d '{
 "model": "gpt-image-2-official",
 "prompt": ",, and,",
 "size": "16:9",
 "resolution": "2k",
 "quality": "high",
 "n": 1,
 "output_format": "jpeg",
 "output_compression": 90,
 "callback_url": "https://example.com/webhooks/image",
 "task_nickname": "autumn-fox"
 }'

Image-to-Imagelocalized example textimage Image-to-Image, no Generation type.

{
 "model": "gpt-image-2-official",
 "prompt": "subject, will as, and output PNG",
 "image": ["https://example.com/product.png"],
 "size": "1:1",
 "resolution": "1k",
 "background": "transparent",
 "output_format": "png"
}

Maskrepainting

Mask as Alpha PNG, dimensions and images Reference image, must andimage use.

{
 "model": "gpt-image-2-official",
 "prompt": "onlyMask as",
 "image": ["https://example.com/room.png"],
 "mask": "https://example.com/mask.png",
 "size": "1:1",
 "resolution": "1k",
 "output_format": "png"
}

localized example text+ PNG output```json { "model": "gpt-image-2-official", "prompt": "A minimal logo of a paper crane, centered, clean edges", "size": "1:1", "background": "transparent", "output_format": "png" }


### Image Editinglocalized example text**POST** `/v1/images/edits`

`Content-Type: multipart/form-data`.and,**fieldand Meaningexactly identical** (localized example text`background` / `moderation` / `output_format` / `output_compression` / `provider`), in image and Mask file, no URL or Base64.task bookingand query Methodexactly identical.

```bash

curl -X POST "https://mm-internal-cn.leonecloud.com/v1/images/edits" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-2-official" \
-F "prompt=, subject" \
-F "size=1:1" \
-F "resolution=2k" \
-F "background=transparent" \
-F "output_format=png" \
-F "image=@/path/to/product.png"


## Request Parameters

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `model` | string | Yes | — | `gpt-image-2-official` |
| `prompt` | string | Yes | — | image, maximum 32,000 characters|
| `n` | integer | No | `1` | image, range 1–4, mustType|
| `size` | string | No | `auto` |, dimensions, dimensions or`auto` (Text-to-Imageas`1:1`, Image-to-ImageReference image); see below|
| `resolution` | string | No | `1k` | `1k`, `2k` or`4k`; and`size` use|
| `quality` | string | No | `auto` | `auto`, `low`, `medium`, `high` |
| `image` | string[] | No | — | input imagelist (URL or Base64 data URI),**Image-to-Image**, up to 16 images|
| `mask` | string | No | — | Mask PNG (URL or Base64 data URI), must and`image` use, dimensions and images Reference image Alpha|
| `background` | string | No | `auto` | `auto`, `opaque` or`transparent`; supported PNG|
| `moderation` | string | No | `auto` |,`auto` or`low`; and`nsfw_check=true` when as`auto` |
| `nsfw_check` | boolean | No | `false` | Safety moderation toggle; as`true` when use`moderation=auto` |
| `output_format` | string | No | `png` | `png` or`jpeg`; first supported WebP|
| `output_compression` | integer | No | — | JPEG output quality, range 0–100; PNG supported, field|
| `provider` | string | No | localized example text|,`oai` / `az`; If omittedas,.see below「localized example text」 |
| `async` | boolean | No | `true` |;`false` image and return OpenAI image|
| `response_format` | string | No | `url` | **only `async=false` when**:`url` or`b64_json` |
| `extra_body` | object | No | — | Modelwith Parameter,`{"nsfw_checker": true}` |
| `callback_url` | string | No | — | Callback notification URL after the task is complete |
| `task_nickname` | string | No | — | Task label, localized example text|
| `user` | string | No | — | (OpenAI field)|

`/v1/images/edits` field and Meaning and exactly identical, in`image` and`mask` as file (multiple images when`image` field); can use`image_urls` URL Reference image,`mask_url` URL provide Mask, and upload a file can.localized example text`extra_body` JSON characters,`provider` localized example text`-F provider=az` can.

### Model in with, default can use and.with when can use`provider`:| `provider` | Meaning |
| --- | --- |
| If omitted (default) |,|
| `az` | onlyuse Azure|
| `oai` | onlyuse OpenAI|

> - **after**:localized example text`provider` in, when can use when taskFailure and, will.image Success, no when field.
> - image Parameter, and return exactly identical,`provider` localized example text.
> - localized example text`oai` / `az` returned when applicable `code=10002`.

### dimensions and Resolution`size × resolution` will in as dimensions:| `size` | `1k` | `2k` | `4k` |
| --- | --- | --- | --- |
| `1:1` | 1024×1024 | 2048×2048 | 2880×2880 |
| `3:2` | 1536×1024 | 2048×1360 | 3520×2336 |
| `2:3` | 1024×1536 | 1360×2048 | 2336×3520 |
| `4:3` | 1024×768 | 2048×1536 | 3312×2480 |
| `3:4` | 768×1024 | 1536×2048 | 2480×3312 |
| `5:4` | 1280×1024 | 2560×2048 | 3216×2576 |
| `4:5` | 1024×1280 | 2048×2560 | 2576×3216 |
| `16:9` | 1536×864 | 2048×1152 | 3840×2160 |
| `9:16` | 864×1536 | 1152×2048 | 2160×3840 |
| `2:1` | 2048×1024 | 2688×1344 | 3840×1920 |
| `1:2` | 1024×2048 | 1344×2688 | 1920×3840 |
| `3:1` | 1536×512 | 3072×1024 | 3840×1280 |
| `1:3` | 512×1536 | 1024×3072 | 1280×3840 |
| `21:9` | 2016×864 | 2688×1152 | 3840×1648 |
| `9:21` | 864×2016 | 1152×2688 | 1648×3840 |

can in the dimensions as`size`, not in when`size supported`.

`size` or`auto` when:Text-to-Image`1:1`; Image-to-Image (Mask) images Reference image Aspect ratio, in,`resolution` localized example text.Reference imagedimensions Failure when as`1:1`.

supported**dimensions** (localized example text`"size": "1088x1920"`), when Condition, returned when applicableParameterError:

- width, height as 16; 
- exceeds 3840; 
- Aspect ratioin 1:3 3:1; 
- in 655,360 8,294,400.

dimensions`resolution` and; supported and`provider=az` localized example text.

Resolutionas`resolution` > `size` localized example text> `quality`.localized example text`{"size":"16:9","resolution":"4k"}` 16:9 4K image;`{"size":"2K"}` default 2K image; If omitted when default 1K.

## task booking(default)task:```json
{
 "code": 0,
 "msg": "success",
 "data": {
 "taskId": "task_xxx",
 "status": "processing",
 "createdAt": "2026-08-25 18:00:00"
 }
}

localized example textdata.taskId after Polling query, orcallback_url complete.

Query Task

GET /v1/images/generations/{taskId}

/v1/images/generations and/v1/images/edits create task query.

curl "https://mm-internal-cn.leonecloud.com/v1/images/generations/task_xxx" \
 -H "Authorization: Bearer YOUR_API_KEY"

status can asprocessing, success orfailed.recommended2–5 secondsquery,.

Successwhen,result image URL list,output after.localized example textb64_json will and URL, field andusage localized example text.

{
 "code": 0,
 "msg": "success",
 "data": {
 "taskId": "task_xxx",
 "status": "success",
 "result": ["https://cdn.example.com/image.png"],
 "output": {
 "created": 1787661600,
 "data": [{"url": "https://cdn.example.com/image.png"}],
 "background": "opaque",
 "output_format": "png",
 "quality": "high",
 "size": "1024x1024",
 "usage": {
 "input_tokens": 10,
 "input_tokens_details": {
 "cached_tokens": 0,
 "text_tokens": 10,
 "image_tokens": 0
 },
 "output_tokens": 7033,
 "output_tokens_details": {
 "text_tokens": 0,
 "image_tokens": 7033
 },
 "total_tokens": 7043
 }
 }
 }
}

usage field

fieldDescription
input_tokensinput token
input_tokens_details.cached_tokensreturn input token
input_tokens_details.text_tokensPrompt token
input_tokens_details.image_tokensReference image token; Text-to-ImageUsuallyas 0
output_tokensoutput token
output_tokens_details.image_tokensimage token
output_tokens_details.text_tokensoutput token, Image GenerationUsually as 0
total_tokenstoken

localized example textdata.completionTokens token, etc.output.usage.total_tokens.

,, wheninput_tokens_details / output_tokens_details can as 0 or,input_tokens / output_tokens / total_tokens return, Optionalfield.

(async=false)

as OpenAI image, can OpenAI SDK:```json
{
"created": 1778394000,
"data": [
{ "url": "https://.../output_001.png" }
]
}


localized example text`response_format=b64_json` when,`data` as`{"b64_json":"..."}`.

> 4K image when: when width 10 minutes; Scenariorecommended use default, when.

## and`callback_url` after, task`success` or`failed` when, will HTTP POST.

Create Task when Parameter, Success after`output.usage` in the input, image input and image output token; Failuretask.

## Errorlocalized example text**(default)**Error, HTTP Status Code as 200,`code`:| `code` | Meaning | recommended|
| --- | --- | --- |
| `0` | Success | — |
| `10002` | Parametermissing or malformed / supported model| localized example text`msg` Parameter|
| `10005` | not, API Key invalid or missing| localized example text`Authorization: Bearer` localized example text|
| `30003` | Task not found | localized example text`taskId` |
| `40001` | Insufficient balance, no complete| after|
| `90003` | localized example text| after;|

taskSuccess after if Failure, query endpoint will return`status: "failed"` and in`msg` in Failure, first will.

**(`async=false`)**OpenAI Error, and use HTTP Status Code:`400` ParameterError, `401` Failure,`402` Insufficient balance, `500` taskexecute Failure,`504` etc. exceeds 10 minutes not image (**tasknot**, `error.code` localized example text`taskId`, can query ).

## v2 endpoint| localized example text| v2 endpoint| (OpenAI )|
| --- | --- | --- |
| create Path| `POST /api/v2/open/aigc/gpt-image-2-official` | `POST /v1/images/generations` |
| query Path| `GET /api/v2/open/aigc/{taskId}` | `GET /v1/images/generations/{taskId}` |
| fieldlocalized example text| camelCase (when snake_case )| OpenAI field|
| Reference image | `imageUrls` / `base64File` / `base64FileList` | `image` (URL or Base64 data URI)|
| Mask | `maskUrl` / `maskFile` | `mask` |
| Image Editing | Reference imageURL or Base64| `/v1/images/edits`, image upload a file|
| image| supported| supported (`async=false`) |
| OpenAI SDK localized example text| No | Yes |

v2 endpoint can use, task and.v2 fieldDescription[GPT Image v2 endpoint](/docs/gpt-image-v2).
Updated 2026-10-23