> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crazyrouter.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GPT Image

> Generate and edit images with gpt-image-2 through the OpenAI-compatible Images API

> Last updated: 2026-06-06

# GPT Image

`gpt-image-2` uses the OpenAI-compatible Images API:

```text theme={null}
POST /v1/images/generations
POST /v1/images/edits
```

<Warning>
  Use the primary image route `https://api.crazyrouter.com/v1` for `gpt-image-2`. The full generation endpoint is `https://api.crazyrouter.com/v1/images/generations`. Account login, billing, and the console remain on `https://crazyrouter.com`.
</Warning>

## Generate Image

### Request Parameters

| Parameter            | Type    | Required | Description                                                                                                                                                                                                                          |
| -------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `model`              | string  | Yes      | Fixed as `gpt-image-2`                                                                                                                                                                                                               |
| `prompt`             | string  | Yes      | Image description prompt                                                                                                                                                                                                             |
| `n`                  | integer | No       | Number of images, default `1`, range `1-10`                                                                                                                                                                                          |
| `size`               | string  | No       | `auto` or `WxH`. Dimensions must be multiples of 16, each side must be at most 3840, total pixels must be 655360 to 8294400, and the long:short side ratio must not exceed 3:1. Common values: `1024x1024`, `1536x1024`, `1024x1536` |
| `quality`            | string  | No       | `auto`, `low`, `medium`, `high`. `hd` is accepted for compatibility and normalized to `high`; `standard` is accepted for compatibility and normalized to `auto`                                                                      |
| `background`         | string  | No       | `auto` or `opaque`. `transparent` is not supported for `gpt-image-2`                                                                                                                                                                 |
| `output_format`      | string  | No       | `png`, `jpeg`, `webp`                                                                                                                                                                                                                |
| `output_compression` | integer | No       | `0-100`, only with `output_format=jpeg` or `output_format=webp`                                                                                                                                                                      |
| `moderation`         | string  | No       | `auto` or `low`                                                                                                                                                                                                                      |
| `stream`             | boolean | No       | Return an SSE stream                                                                                                                                                                                                                 |
| `partial_images`     | integer | No       | `0-3`, only when `stream=true`                                                                                                                                                                                                       |
| `user`               | string  | No       | End-user identifier                                                                                                                                                                                                                  |

For compatibility with older DALL-E / OpenAI Images clients, `gpt-image-2` accepts `response_format=url`, `response_format=b64_json`, `quality=standard`, and `style=vivid/natural`. `response_format` and `style` are not forwarded upstream; `quality=standard` is normalized to `auto`.

<Warning>
  `response_format` is only a Crazyrouter compatibility field for legacy clients, not a `gpt-image-2` upstream parameter. For new integrations, use `output_format="png"`, `"jpeg"`, or `"webp"` to choose the image file format, and read `data[0].url` by default. If a legacy client sends `response_format="b64_json"`, the service tries to preserve base64 response semantics.
</Warning>

These combinations are still rejected: `input_fidelity`, `background=transparent`, and `output_format=png` with `output_compression`.

### Request Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.crazyrouter.com/v1/images/generations \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -d '{
      "model": "gpt-image-2",
      "prompt": "A cat wearing a spacesuit walking on the moon with Earth in the background",
      "n": 1,
      "size": "1024x1024",
      "quality": "low",
      "output_format": "png"
    }'
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="YOUR_API_KEY",
      base_url="https://api.crazyrouter.com/v1",
  )

  response = client.images.generate(
      model="gpt-image-2",
      prompt="A cat wearing a spacesuit walking on the moon with Earth in the background",
      n=1,
      size="1024x1024",
      quality="low",
      output_format="png",
  )

  print(response.data[0].url)
  ```
</CodeGroup>

### Streaming

`gpt-image-2` supports `stream=true`. If you send `partial_images`, you must also set `stream=true`, and the value must be `0-3`.

```bash cURL theme={null}
curl -N -X POST https://api.crazyrouter.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A simple blue verification icon on a white background",
    "size": "1024x1024",
    "quality": "high",
    "stream": true,
    "partial_images": 2
  }'
```

<Note>
  Synchronous `quality=high` requests, including the compatibility value `quality=hd`, can take a long time. For image workloads, use `https://api.crazyrouter.com/v1`; for high-quality jobs, prefer `stream=true` or set your client timeout above 180 seconds.
</Note>

### Response Example

```json theme={null}
{
  "created": 1778990000,
  "data": [
    {
      "url": "https://media.crazyrouter.com/task-artifacts/2026/05/17/sync-image/request-id-1.png"
    }
  ],
  "output_format": "png",
  "quality": "low",
  "size": "1024x1024"
}
```

***

## Edit Image

```
POST /v1/images/edits
```

Edit an existing image with mask-based region editing support. You can also pass multiple reference images for blending, style transfer, or composition work.

### Request Parameters

| Parameter            | Type            | Required | Description                                                                                                      |
| -------------------- | --------------- | -------- | ---------------------------------------------------------------------------------------------------------------- |
| `model`              | string          | Yes      | Fixed as `gpt-image-2`                                                                                           |
| `image` / `image[]`  | file or file\[] | Yes      | Original image or reference image file(s), sent as multipart; `gpt-image-2` supports up to `16` reference images |
| `prompt`             | string          | Yes      | Edit description                                                                                                 |
| `mask`               | file            | No       | Mask image; transparent areas indicate regions to edit                                                           |
| `n`                  | integer         | No       | Number of images, default `1`, range `1-10`                                                                      |
| `size`               | string          | No       | Same rules as generation                                                                                         |
| `quality`            | string          | No       | `auto`, `low`, `medium`, `high`; `hd` is normalized to `high`                                                    |
| `background`         | string          | No       | `auto` or `opaque`                                                                                               |
| `output_format`      | string          | No       | `png`, `jpeg`, `webp`                                                                                            |
| `output_compression` | integer         | No       | `0-100`, only with `output_format=jpeg` or `output_format=webp`                                                  |
| `stream`             | boolean         | No       | Return an SSE stream                                                                                             |
| `partial_images`     | integer         | No       | `0-3`, only when `stream=true`                                                                                   |

### Single-Image Edit Example

```python Python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.crazyrouter.com/v1",
)

response = client.images.edit(
    model="gpt-image-2",
    image=open("original.png", "rb"),
    mask=open("mask.png", "rb"),
    prompt="Add a rainbow in the sky",
    n=1,
    size="1024x1024",
    quality="low",
)

print(response.data[0].url)
```

### Multi-Reference Edit Example

Multi-image editing requests must use `multipart/form-data`. Prefer multiple `image[]` fields for reference images; repeated `image` fields are also accepted.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.crazyrouter.com/v1/images/edits \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -F "model=gpt-image-2" \
    -F "prompt=Blend the person from the first image with the background from the second image into one natural campaign visual" \
    -F "size=1024x1024" \
    -F "quality=low" \
    -F "n=1" \
    -F "image[]=@person.png" \
    -F "image[]=@background.png"
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.crazyrouter.com/v1/images/edits",
      headers={"Authorization": "Bearer YOUR_API_KEY"},
      data={
          "model": "gpt-image-2",
          "prompt": "Blend the person from the first image with the background from the second image into one natural campaign visual",
          "size": "1024x1024",
          "quality": "low",
          "n": "1",
      },
      files=[
          ("image[]", ("person.png", open("person.png", "rb"), "image/png")),
          ("image[]", ("background.png", open("background.png", "rb"), "image/png")),
      ],
      timeout=240,
  )

  response.raise_for_status()
  print(response.json()["data"][0]["url"])
  ```
</CodeGroup>

<Note>
  `gpt-image-2` supports up to 16 reference images. Multi-image requests are routed to carriers that support multi-reference image editing.
</Note>
