# GPT-Image-2 Image Generation

> Generate or edit images with gpt-image-2 through UniAll image APIs.

Canonical URL: https://docs.uniall.ai/models/image/gpt-image-2
Locale: en

Use `gpt-image-2` for text-to-image and image editing through the OpenAI-compatible image endpoints. This model uses `size` to control both dimensions and aspect ratio. It does not support `aspect_ratio`.

## Endpoint

```http
POST /v1/images/generations
POST /v1/images/edits
```

Use `/v1/images/generations` for text-to-image. Use `/v1/images/edits` when a reference image is included.

## Authentication

```http
Authorization: Bearer sk-***
Content-Type: application/json
```

## Request Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `model` | string | Yes | Use `gpt-image-2`. |
| `prompt` | string | Yes | Image generation or editing prompt. |
| `image` | string/object | Conditional | Reference image for editing. |
| `images` | array | Conditional | Multiple reference images when supported. |
| `size` | string | Yes | Output dimensions. Must be one of the supported size values. |
| `quality` | string | No | `low`, `medium`, or `high`. Default: `medium`. |
| `output_format` | string | No | `png`, `jpeg`, or `webp`. |
| `n` | integer | No | Output image count. Default: `1`; range: `1` to `8`. |
| `response_format` | string | No | Prefer `url`. |

## Supported Sizes

Common values:

| Size | Ratio | Tier |
| --- | --- | --- |
| `1024x768` | `4:3` | `1K` |
| `768x1024` | `3:4` | `1K` |
| `1024x1024` | `1:1` | `1K` |
| `1536x864` | `16:9` | `1K` |
| `864x1536` | `9:16` | `1K` |
| `1920x1080` | `16:9` | `2K` |
| `1080x1920` | `9:16` | `2K` |
| `1536x1536` | `1:1` | `2K` |
| `2048x2048` | `1:1` | `4K` |
| `3840x2160` | `16:9` | `4K` |
| `2160x3840` | `9:16` | `4K` |

Use the product model configuration as the source of truth for the complete enabled size matrix.

## Text-To-Image Example

```bash
curl -X POST "{BASE_URL}/v1/images/generations" \
  -H "Authorization: Bearer sk-***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A small blue glass sphere on a clean white desk, minimal product photo, soft daylight",
    "size": "1024x768",
    "quality": "low",
    "output_format": "webp",
    "n": 1,
    "response_format": "url"
  }'
```

## Image Editing Example

```bash
curl -X POST "{BASE_URL}/v1/images/edits" \
  -H "Authorization: Bearer sk-***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Keep the product shape, change the background to a bright studio scene",
    "image": "https://example.com/input.png",
    "size": "1024x1024",
    "quality": "medium",
    "output_format": "png",
    "n": 1,
    "response_format": "url"
  }'
```

## Response Example

```json
{
  "created": 1778688000,
  "data": [
    {
      "url": "https://example.com/generated.png"
    }
  ]
}
```

## Billing Notes

`gpt-image-2` uses a parameter matrix based on `size + quality`, multiplied by `n`. `output_format` controls file type and is not a separate billing dimension in the current source scope.

## Common Errors

- Missing `size`.
- Passing `aspect_ratio`; use `size` instead.
- Passing `quality` outside `low`, `medium`, or `high`.
- Requesting `n` outside `1` to `8`.
- Using an unsupported size for the current account.

## Related Pages

- [Image Generation Overview](/models/image/overview)
- [Async Image Generation](/models/image/async-image-generation)
- [Seedream Image Generation](/models/image/seedream)
