> ## 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

Parameter und Nutzung sind mit dem offiziellen Angebot abgestimmt; detaillierte Parameter können direkt der offiziellen Dokumentation entnommen werden.

## Aufruf

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

BaseURL:

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

## Unterstützte Modelle

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

## Hinweise

Diese Schnittstelle ist mit der OpenAI Image API kompatibel und unterstützt derzeit die Bilderzeugung und Bildbearbeitung. Detaillierte Parameter richten sich nach der offiziellen OpenAI-Dokumentation:

* [Offizieller OpenAI-Leitfaden zur Bilderzeugung](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)

* Anforderungen zur Bilderzeugung verwenden `application/json`.

* Die Bildbearbeitung unterstützt Datei-Uploads per `multipart/form-data` sowie `application/json`, wobei Bildreferenzen über das `images`-Array übergeben werden; unten finden Sie ein JSON-Beispiel.

* Es wird empfohlen, `size` und `quality` explizit zu setzen, um Bildqualität und Kosten besser steuern zu können. Die Kosten werden nach dem tatsächlichen Token-Verbrauch und den Modellpreisen berechnet; der Verbrauch kann über das Feld `usage` in der Antwort eingesehen werden.

## Modelle und Parameter

* Verwenden Sie `gpt-image-2.5-sunburst-oai` für präzise Bildbearbeitung oder `gpt-image-2.5-flare-oai` für schnelle Bilderzeugung. Verwenden Sie im `model`-Parameter der Anfrage den oben aufgeführten vollständigen Namen.
* `quality` bei 2.5: `low` / `medium` / `high` / `xhigh` / `max` / `auto`, Standard ist `auto`; GPT Image 2 unterstützt die neuen Werte `xhigh` / `max` nicht.
* Setzen Sie für Bilder mit transparentem Hintergrund `background="transparent"` und verwenden Sie `output_format="png"` oder `"webp"`.
* Legen Sie die Bildgröße über `size` fest, z. B. `1024x1024`, `1536x1024` oder `1024x1536`. Einschränkungen für benutzerdefinierte Größen sowie vollständige Parameterbeschreibungen finden Sie in der [offiziellen Dokumentation](https://developers.openai.com/api/docs/guides/image-generation).

## REST API

### 1. Bilderzeugung

```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. Bildbearbeitung

```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
```

Bei der Bearbeitung mit mehreren Referenzbildern kann `image[]` mehrfach übergeben werden:

```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. Bildbearbeitung (JSON)

Ersetzen Sie `{base64_image}` durch die Base64-Kodierung des Eingabe-PNG-Bildes.

```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))
```

Bildbearbeitung:

```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"));
```

Bildbearbeitung:

```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

### Parameter `moderation`

* `moderation="auto"` ist die standardmäßige, normale Filterung; `moderation="low"` steht für eine lockere Filterung.
* `moderation` kann in Anforderungen zur Bilderzeugung und Bildbearbeitung verwendet werden.
