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

# GPT Image

Parameters and usage are aligned with the official implementation. For detailed parameters, refer directly to the official documentation.

## Endpoint

* `https://{api_domain}/openai/v1/images/generations`
* `https://{api_domain}/openai/v1/images/edits`

BaseURL:

* `https://{api_domain}/openai/v1`

## Supported Models

* `gpt-image-2`
* `gpt-image-2-oai`
* `gpt-image-2.5-sunburst-oai`
* `gpt-image-2.5-flare-oai`

## Description

This endpoint is compatible with the OpenAI Image API and currently supports image generation and image editing. For detailed parameters, refer to the official OpenAI documentation:

* [OpenAI Official Image Generation Guide](https://developers.openai.com/api/docs/guides/image-generation)

* [Images generate](https://developers.openai.com/api/reference/resources/images/methods/generate)

* [Images edit](https://developers.openai.com/api/reference/resources/images/methods/edit)

* Image generation requests use `application/json`.

* Image editing supports `multipart/form-data` file uploads as well as `application/json`, with image references passed via the `images` array; a JSON example is provided below.

* It is recommended to explicitly set `size` and `quality` to control image quality and cost. Fees are calculated based on actual Token usage and model pricing; usage can be viewed in the `usage` field of the response.

## Models and Parameters

* Use `gpt-image-2.5-sunburst-oai` for fine-grained image editing, or `gpt-image-2.5-flare-oai` for fast image generation. Use the full names listed above in the `model` field of your requests.
* For 2.5, `quality` accepts `low` / `medium` / `high` / `xhigh` / `max` / `auto`, with a default of `auto`; GPT Image 2 does not support the newly added `xhigh` / `max`.
* To generate images with a transparent background, set `background="transparent"` and use `output_format="png"` or `"webp"`.
* Set the image size via `size`, for example `1024x1024`, `1536x1024`, or `1024x1536`. For constraints on custom sizes and the full parameter description, refer to the [official documentation](https://developers.openai.com/api/docs/guides/image-generation).

## REST API

### 1. Image Generation

```bash theme={null}
curl -X POST 'https://{api_domain}/openai/v1/images/generations' \
  -H 'Authorization: Bearer apikey' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gpt-image-2.5-flare-oai",
    "prompt": "A product photo of a white ceramic mug on a wooden table",
    "size": "1024x1024",
    "quality": "high",
    "output_format": "png",
    "n": 1
  }' | jq -r '.data[0].b64_json' | base64 --decode > output.png
```

### 2. Image Editing

```bash theme={null}
curl -X POST 'https://{api_domain}/openai/v1/images/edits' \
  -H 'Authorization: Bearer apikey' \
  -F 'model=gpt-image-2' \
  -F 'image[]=@input.png' \
  -F 'mask=@mask.png' \
  -F 'prompt=Replace the background with a clean studio backdrop' \
  -F 'size=1024x1024' \
  -F 'quality=high' \
  -F 'output_format=png' \
  | jq -r '.data[0].b64_json' | base64 --decode > edited.png
```

For multi-image reference editing, you can pass `image[]` multiple times:

```bash theme={null}
curl -X POST 'https://{api_domain}/openai/v1/images/edits' \
  -H 'Authorization: Bearer apikey' \
  -F 'model=gpt-image-2' \
  -F 'image[]=@body-lotion.png' \
  -F 'image[]=@bath-bomb.png' \
  -F 'image[]=@soap.png' \
  -F 'prompt=Create a photorealistic gift basket using the reference products' \
  -F 'size=1024x1024' \
  -F 'quality=high'
```

### 3. Image Editing (JSON)

Replace `{base64_image}` with the Base64 encoding of the input PNG image.

```bash theme={null}
curl -X POST 'https://{api_domain}/openai/v1/images/edits' \
  -H 'Authorization: Bearer {your-api-key}' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gpt-image-2.5-sunburst-oai",
    "images": [
      {"image_url": "data:image/png;base64,{base64_image}"}
    ],
    "prompt": "Change the shape to green. Preserve the simple composition.",
    "size": "1024x1024",
    "quality": "xhigh",
    "moderation": "low",
    "output_format": "png"
  }'
```

## OpenAI SDK

### Python

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

api_key = "{your-api-key}"

client = OpenAI(
    api_key=api_key,
    base_url="https://{api_domain}/openai/v1",
)

result = client.images.generate(
    model="gpt-image-2.5-flare-oai",
    prompt="A product photo of a white ceramic mug on a wooden table",
    size="1024x1024",
    quality="high",
)

image_base64 = result.data[0].b64_json
with open("output.png", "wb") as f:
    f.write(base64.b64decode(image_base64))
```

Image editing:

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

api_key = "{your-api-key}"

client = OpenAI(
    api_key=api_key,
    base_url="https://{api_domain}/openai/v1",
)

result = client.images.edit(
    model="gpt-image-2",
    image=open("input.png", "rb"),
    mask=open("mask.png", "rb"),
    prompt="Replace the background with a clean studio backdrop",
    size="1024x1024",
    quality="high",
)

image_base64 = result.data[0].b64_json
with open("edited.png", "wb") as f:
    f.write(base64.b64decode(image_base64))
```

### Node.js

```javascript theme={null}
import OpenAI from "openai";
import fs from "fs";

const client = new OpenAI({
  apiKey: "{your-api-key}",
  baseURL: "https://{api_domain}/openai/v1",
});

const result = await client.images.generate({
  model: "gpt-image-2.5-flare-oai",
  prompt: "A product photo of a white ceramic mug on a wooden table",
  size: "1024x1024",
  quality: "high",
});

const imageBase64 = result.data[0].b64_json;
fs.writeFileSync("output.png", Buffer.from(imageBase64, "base64"));
```

Image editing:

```javascript theme={null}
import OpenAI, { toFile } from "openai";
import fs from "fs";

const client = new OpenAI({
  apiKey: "{your-api-key}",
  baseURL: "https://{api_domain}/openai/v1",
});

const result = await client.images.edit({
  model: "gpt-image-2",
  image: await toFile(fs.createReadStream("input.png"), null, {
    type: "image/png",
  }),
  mask: await toFile(fs.createReadStream("mask.png"), null, {
    type: "image/png",
  }),
  prompt: "Replace the background with a clean studio backdrop",
  size: "1024x1024",
  quality: "high",
});

const imageBase64 = result.data[0].b64_json;
fs.writeFileSync("edited.png", Buffer.from(imageBase64, "base64"));
```

## Best Practices

### moderation Parameter

* `moderation="auto"` is the default standard filtering; `moderation="low"` indicates more lenient filtering.
* `moderation` can be used in both image generation and image editing requests.
