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

# GPT Image 2

> GPT Image 2: image generation model. Request examples and parameters for MixRoute.

GPT Image 2 is an image generation model from OpenAI.

Call `gpt-image-2` through MixRoute using the endpoint shown below.

## Key capabilities

* Text-to-image - Generate images from natural-language prompts
* Image editing - Modify an uploaded image with a prompt
* Output controls - Configure size and quality
* Images API - Uses /v1/images/generations

## Output specifications

| Property         | Value                                                                   |
| ---------------- | ----------------------------------------------------------------------- |
| Endpoints        | `/v1/images/generations`, `/v1/images/edits`                            |
| Popular sizes    | 1024x1024, 1536x1024, 1024x1536, 2048x2048, up to 3840px                |
| Size constraints | Edges are multiples of 16; aspect ratio ≤ 3:1; 655,360-8,294,400 pixels |
| Quality          | low, medium, high, auto                                                 |
| Formats          | png, jpeg, webp                                                         |
| Background       | opaque, auto                                                            |

## Quick example

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl "https://api.mixroute.ai/v1/images/generations" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "model": "gpt-image-2",
      "prompt": "A minimal red circle centered on a white background",
      "size": "1024x1024",
      "n": 1,
      "quality": "low"
    }'
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests

    response = requests.post(
        "https://api.mixroute.ai/v1/images/generations",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={'model': 'gpt-image-2',
              'prompt': 'A minimal red circle centered on a white background',
              'size': '1024x1024',
              'n': 1,
              'quality': 'low'},
    )

    print(response.json())
    ```
  </Tab>
</Tabs>

## Parameters

| Parameter            | Type    | Required | Description                             |
| -------------------- | ------- | -------- | --------------------------------------- |
| `model`              | string  | Yes      | Must be `gpt-image-2`.                  |
| `prompt`             | string  | Yes      | Description of the image to generate.   |
| `n`                  | integer | No       | Number of images to generate.           |
| `size`               | string  | No       | Output image dimensions.                |
| `quality`            | string  | No       | Output quality when supported.          |
| `output_format`      | string  | No       | png, jpeg, or webp.                     |
| `output_compression` | integer | No       | JPEG or WebP compression from 0 to 100. |
| `background`         | string  | No       | opaque or auto.                         |

## Image editing

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl "https://api.mixroute.ai/v1/images/edits" \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -F "model=gpt-image-2" \
      -F "image=@source.png" \
      -F "prompt=Replace the white background with a pale blue background" \
      -F "size=1024x1024" \
      -F "quality=low"
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from openai import OpenAI

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

    result = client.images.edit(
        model="gpt-image-2",
        image=open("source.png", "rb"),
        prompt="Replace the white background with a pale blue background",
        size="1024x1024",
        quality="low",
    )

    print(result.data[0])
    ```
  </Tab>
</Tabs>

### Edit parameters

| Parameter            | Type    | Required | Description                                   |
| -------------------- | ------- | -------- | --------------------------------------------- |
| `image`              | file    | Yes      | Source image uploaded as multipart form data. |
| `model`              | string  | Yes      | Must be `gpt-image-2`.                        |
| `prompt`             | string  | Yes      | Edit instruction.                             |
| `size`               | string  | No       | Output image dimensions.                      |
| `quality`            | string  | No       | Output quality.                               |
| `output_format`      | string  | No       | png, jpeg, or webp.                           |
| `output_compression` | integer | No       | JPEG or WebP compression from 0 to 100.       |
