# GPT Image 2 / 2.5 / 2.6 Generation & Editing

Generate or edit images asynchronously with the GPT Image model family. After submitting a task, save `task_id` and poll its status; once completed, read output URLs from `images[].url`.

Supported models: `gpt-image-2`, `gpt-image-2.5-flare`, `gpt-image-2.5-sunburst`, `gpt-image-2.6-flare`, and `gpt-image-2.6-sunburst`. All five models share identical endpoints, parameters, and task workflows; the only difference is that animated GIF output is supported exclusively on `gpt-image-2.6-flare` and `gpt-image-2.6-sunburst`.

## Quick Selection

Base URL: `https://vip.brioi.com`  
Authentication: `Authorization: Bearer YOUR_API_KEY`

**Image Generation**

- Create: `POST /v1/images/async/generations`
- Poll: `GET /v1/images/async/generations/{task_id}`
- Payload: JSON containing prompt and generation options.

**Image Editing via URL (Recommended)**

- Create: `POST /v1/images/async/edits`
- Poll: `GET /v1/images/async/edits/{task_id}`
- Payload: JSON passing public image URLs in `images`.

**Image Editing via Local Files**

- Create: `POST /v1/images/async/edits`
- Poll: `GET /v1/images/async/edits/{task_id}`
- Payload: `multipart/form-data` uploading files via `image[]`.

Compatibility note: `POST /v1/images/generations` and `POST /v1/images/edits` are retained only for legacy callers; use the async endpoints for all new integrations.

## Image Generation

### Generation Parameters

| Parameter | Required | Description |
|---|---:|---|
| `model` | Yes | string; one of the supported models. |
| `prompt` | Yes | string; image generation prompt. |
| `size` | No | string, default `auto`; see **Parameter Limits & Errors** for custom dimensions. |
| `quality` | No | string, default `auto`; supports `auto`, `high`, `medium`, `low`. |
| `n` | No | integer, default `1`; `1` is recommended (most configurations generate 1 image per call—send concurrent requests when you need multiple images). |
| `output_format` | No | string; supports `png`, `jpeg`, `webp`; `gpt-image-2.6-flare` and `gpt-image-2.6-sunburst` also support `gif` (see **Animated GIF Output**). |
| `background` | No | string, default `auto`; supports `auto`, `opaque` (transparent backgrounds are not supported). |
| `output_compression` | No | integer; JPEG or WebP compression quality (`0` to `100`). |

### Generation Request Example

```bash
curl -X POST "https://vip.brioi.com/v1/images/async/generations" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "An orange kitten sitting on a white windowsill, soft natural light, clean photography style",
    "size": "1024x1024",
    "quality": "auto",
    "n": 1
  }'
```

## Image Editing

### Edit Parameters

Provide either `image[]` or `images` (mutually exclusive): use `image[]` for local file uploads and `images` for public image URLs.

**Core Inputs**

| Parameter | Required | Description |
|---|---:|---|
| `model` | Yes | string; one of the supported models. |
| `prompt` | Yes | string; describe what to preserve and what to modify. |
| `image[]` | Conditional | file; used in `multipart/form-data` requests (upload at least 1 file; repeat the field for multiple files). |
| `images` | Conditional | array; used in JSON requests (each element may be a URL string or `{ "image_url": "..." }`). |

**Edit Controls**

| Parameter | Required | Description |
|---|---:|---|
| `mask` | No | file or string; PNG mask image. JSON requests accept a public URL; dimensions should match the first reference image. |
| `input_fidelity` | No | string; supports `low`, `high`. |
| `background` | No | string, default `auto`; supports `auto`, `opaque` (transparent backgrounds are not supported). |
| `size` | No | string, default `auto`; see **Parameter Limits & Errors** for custom dimensions. |
| `quality` | No | string, default `auto`; supports `auto`, `high`, `medium`, `low`. |
| `n` | No | integer, default `1`; `1` is recommended. |

**Output Controls**

| Parameter | Required | Description |
|---|---:|---|
| `output_format` | No | string; supports `png`, `jpeg`, `webp`; `gpt-image-2.6-flare` and `gpt-image-2.6-sunburst` also support `gif` (see **Animated GIF Output**). |
| `output_compression` | No | integer; JPEG or WebP compression quality (`0` to `100`). |

### URL Edit Example (Recommended)

```bash
curl -X POST "https://vip.brioi.com/v1/images/async/edits" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Keep the person and outfit unchanged, and change the background to a rainy street at night",
    "images": [
      "https://example.com/reference-1.png",
      "https://example.com/reference-2.jpg"
    ],
    "size": "1024x1024",
    "quality": "auto",
    "n": 1
  }'
```

### Local File Upload Example

```bash
curl -X POST "https://vip.brioi.com/v1/images/async/edits" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "model=gpt-image-2" \
  -F "prompt=Keep the product shape and material unchanged, and replace the background with a clean white studio backdrop" \
  -F "image[]=@/path/to/reference-1.png" \
  -F "image[]=@/path/to/reference-2.png" \
  -F "size=1024x1024" \
  -F "quality=auto"
```

## Animated GIF Output

Supported only on `gpt-image-2.6-flare` and `gpt-image-2.6-sunburst`. Available on both the generation and edit endpoints: pass `output_format: "gif"` and describe the subject, motion, and loop behavior in `prompt`; to animate a still reference image, pass it to the edit endpoint.

| Parameter | Required | Description |
|---|---:|---|
| `output_format` | Yes | string; set to `gif`. |
| `frame_count` | No | integer, default `9`; frame count (`2` to `16`). |
| `frame_duration_ms` | No | integer, default `200`; per-frame duration in milliseconds (`20` to `2000`, rounded to 10 ms increments). |
| `size` | No | string, default `auto`; dimensions of each individual frame. |

- Total pixels are counted across all frames combined—more frames or larger per-frame dimensions make it easier to exceed the pixel cap, which returns a parameter error. If this occurs, reduce `frame_count`, lower `size`, or set `size: "auto"` so the model selects frame dimensions automatically.
- `frame_count` and `frame_duration_ms` apply only to GIF output; GIF does not support `output_compression`.
- On completion, `images[].mime_type` is `image/gif`; download the full animation from `images[].url`.

```bash
curl -X POST "https://vip.brioi.com/v1/images/async/generations" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.6-flare",
    "prompt": "An orange kitten on a windowsill slowly blinking and gently swaying its tail, static camera, seamless loop",
    "size": "auto",
    "quality": "auto",
    "n": 1,
    "output_format": "gif",
    "frame_count": 6,
    "frame_duration_ms": 200
  }'
```

## Task Status & Results

**Creation Response**

```json
{"status":"SUBMITTED","task_id":"task_xxxxxxxxxxxxxxxxxxxxxxxx",
 "progress":"10%","images":[]}
```

Save `task_id`. A successful creation response indicates only that the task has entered processing—not that image generation has finished.

**Task Statuses**

Poll the corresponding `GET` endpoint every 3–5 seconds until a terminal status is reached:

| Status | Description |
|---|---|
| `SUBMITTED` | Submitted; continue polling. |
| `IN_PROGRESS` | Processing; continue polling. |
| `SUCCESS` | Completed; read result URLs from `images[].url`. |
| `FAILURE` | Failed; read the failure details from `fail_reason`. |

**Succeeded Result**

```json
{
  "task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxx",
  "status": "SUCCESS",
  "progress": "100%",
  "images": [
    {
      "index": 0,
      "url": "https://example.com/result.png",
      "mime_type": "image/png"
    }
  ]
}
```

Some storage backends return `application/octet-stream`. Result URLs expire—download or persist output images promptly. Polling responses may also include auxiliary fields such as `usage`; clients should not rely on them.

Failed response example:

```json
{
  "task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxx",
  "status": "FAILURE",
  "progress": "100%",
  "fail_reason": "{\"error\":{\"code\":\"invalid_input\",\"message\":\"Invalid parameters or inaccessible input media\"}}"
}
```

`fail_reason` contains raw diagnostic text that may embed JSON fragments; do not parse it against a fixed schema.

## Parameter Limits & Errors

- Image editing accepts at most 16 reference images per request.
- Reference images and masks in JSON requests must be publicly accessible direct `HTTPS` image URLs.
- `background: "transparent"` is not supported.
- Custom `size` values must satisfy all of the following simultaneously:
  - Both width and height are multiples of `16`;
  - Maximum edge does not exceed `3840` pixels;
  - Long-to-short edge ratio does not exceed `3:1`;
  - Total pixel count is at least `655,360` and at most `8,294,400`.
- Invalid `size`, `quality`, `output_format`, or input media formats return a parameter error.

| Status Code | Description |
|---:|---|
| `400` | Invalid request parameters. |
| `401` | Missing or invalid API key. |
| `403` | Insufficient balance or quota, or no permission for the requested model. |
| `404` | Queried task does not exist. |
| `429` | Rate limit exceeded. |
| `503` | Service temporarily unavailable. |
| `500`, `502` | Transient server or upstream error. |

