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

# GPT-Image-2 Bildgenerierung (offizieller Kanal)

>  - OpenAI-offizielles Modell `gpt-image-2`, basierend auf dem mit `/v1/images/generations` kompatiblen Protokoll
- Asynchrone Verarbeitung, gibt `task_id` für nachfolgende Abfragen zurück
- Text-zu-Bild / Bild-zu-Bild / Inpainting (Maske) — alles in einem
- Unterstützt transparente Hintergründe in PNG / WebP (Alphakanal)
- Neues Feld `resolution` für die Stufe — Auswahl 1K / 2K / 4K
- 15 Seitenverhältnisse in den Stufen 1K / 2K / 4K verfügbar
- Bis zu 4 Bilder pro Anfrage, bis zu 16 Referenzbilder
- 95 % Parameter-Übereinstimmung mit `gpt-image-1.5-official` — für die Migration genügt eine Änderung des Modellnamens 

```bash cURL theme={null}
curl --request POST \
  --url https://gccai.heqingsong.uk/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-image-2-official",
    "prompt": "An ancient castle beneath a starry sky",
    "size": "16:9",
    "resolution": "2k",
    "quality": "high",
    "n": 1
  }'
```

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

url = "https://gccai.heqingsong.uk/v1/images/generations"

payload = {
    "model": "gpt-image-2-official",
    "prompt": "An ancient castle beneath a starry sky",
    "size": "16:9",
    "resolution": "2k",
    "quality": "high",
    "n": 1
}

headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript JavaScript theme={null}
const url = "https://gccai.heqingsong.uk/v1/images/generations";

const payload = {
  model: "gpt-image-2-official",
  prompt: "An ancient castle beneath a starry sky",
  size: "16:9",
  resolution: "2k",
  quality: "high",
  n: 1,
};

const headers = {
  Authorization: "Bearer <token>",
  "Content-Type": "application/json",
};

fetch(url, {
  method: "POST",
  headers: headers,
  body: JSON.stringify(payload),
})
  .then((response) => response.json())
  .then((data) => console.log(data))
  .catch((error) => console.error("Error:", error));
```

```go Go theme={null}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io/ioutil"
    "net/http"
)

func main() {
    url := "https://gccai.heqingsong.uk/v1/images/generations"

    payload := map[string]interface{}{
        "model":      "gpt-image-2-official",
        "prompt":     "An ancient castle beneath a starry sky",
        "size":       "16:9",
        "resolution": "2k",
        "quality":    "high",
        "n":          1,
    }

    jsonData, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Authorization", "Bearer <token>")
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
}
```

```java Java theme={null}
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;

public class Main {
    public static void main(String[] args) throws Exception {
        String url = "https://gccai.heqingsong.uk/v1/images/generations";

        String payload = """
        {
          "model": "gpt-image-2-official",
          "prompt": "An ancient castle beneath a starry sky",
          "size": "16:9",
          "resolution": "2k",
          "quality": "high",
          "n": 1
        }
        """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(url))
            .header("Authorization", "Bearer <token>")
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(payload))
            .build();

        HttpResponse<String> response = client.send(request,
            HttpResponse.BodyHandlers.ofString());

        System.out.println(response.body());
    }
}
```

```php PHP theme={null}
<?php

$url = "https://gccai.heqingsong.uk/v1/images/generations";

$payload = [
    "model" => "gpt-image-2-official",
    "prompt" => "An ancient castle beneath a starry sky",
    "size" => "16:9",
    "resolution" => "2k",
    "quality" => "high",
    "n" => 1
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>
```

```ruby Ruby theme={null}
require 'net/http'
require 'json'
require 'uri'

url = URI("https://gccai.heqingsong.uk/v1/images/generations")

payload = {
  model: "gpt-image-2-official",
  prompt: "An ancient castle beneath a starry sky",
  size: "16:9",
  resolution: "2k",
  quality: "high",
  n: 1
}

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <token>"
request["Content-Type"] = "application/json"
request.body = payload.to_json

response = http.request(request)
puts response.body
```

```swift Swift theme={null}
import Foundation

let url = URL(string: "https://gccai.heqingsong.uk/v1/images/generations")!

let payload: [String: Any] = [
    "model": "gpt-image-2-official",
    "prompt": "An ancient castle beneath a starry sky",
    "size": "16:9",
    "resolution": "2k",
    "quality": "high",
    "n": 1
]

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let error = error {
        print("Error: \(error)")
        return
    }

    if let data = data, let responseString = String(data: data, encoding: .utf8) {
        print(responseString)
    }
}

task.resume()
```

```csharp C# theme={null}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        var url = "https://gccai.heqingsong.uk/v1/images/generations";

        var payload = @"{
            ""model"": ""gpt-image-2-official"",
            ""prompt"": ""An ancient castle beneath a starry sky"",
            ""size"": ""16:9"",
            ""resolution"": ""2k"",
            ""quality"": ""high"",
            ""n"": 1
        }";

        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>");

        var content = new StringContent(payload, Encoding.UTF8, "application/json");
        var response = await client.PostAsync(url, content);
        var result = await response.Content.ReadAsStringAsync();

        Console.WriteLine(result);
    }
}
```

```dart Dart theme={null}
import 'dart:convert';
import 'package:http/http.dart' as http;

void main() async {
  final url = Uri.parse('https://gccai.heqingsong.uk/v1/images/generations');

  final payload = {
    'model': 'gpt-image-2-official',
    'prompt': 'An ancient castle beneath a starry sky',
    'size': '16:9',
    'resolution': '2k',
    'quality': 'high',
    'n': 1,
  };

  final response = await http.post(
    url,
    headers: {
      'Authorization': 'Bearer <token>',
      'Content-Type': 'application/json',
    },
    body: jsonEncode(payload),
  );

  print(response.body);
}
```

```r R theme={null}
library(httr)
library(jsonlite)

url <- "https://gccai.heqingsong.uk/v1/images/generations"

payload <- list(
  model = "gpt-image-2-official",
  prompt = "An ancient castle beneath a starry sky",
  size = "16:9",
  resolution = "2k",
  quality = "high",
  n = 1
)

response <- POST(
  url,
  add_headers(
    Authorization = "Bearer <token>",
    `Content-Type` = "application/json"
  ),
  body = toJSON(payload, auto_unbox = TRUE),
  encode = "raw"
)

cat(content(response, "text"))
```

```json 200 theme={null}
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01KPTXXXXXXXXXXXXXXX"
    }
  ]
}
```

```json 400 theme={null}
{
  "error": {
    "code": 400,
    "message": "Invalid parameters: size not allowed / resolution not supported / pixel violation, etc.",
    "type": "invalid_request_error"
  }
}
```

```json 401 theme={null}
{
  "error": {
    "code": 401,
    "message": "Authentication failed, please check your API key",
    "type": "authentication_error"
  }
}
```

```json 402 theme={null}
{
  "error": {
    "code": 402,
    "message": "Insufficient account balance, please top up and try again",
    "type": "payment_required"
  }
}
```

```json 403 theme={null}
{
  "error": {
    "code": 403,
    "message": "Access forbidden, you do not have permission to access this resource",
    "type": "permission_error"
  }
}
```

```json 429 theme={null}
{
  "error": {
    "code": 429,
    "message": "Too many requests, please try again later",
    "type": "rate_limit_error"
  }
}
```

```json 500 theme={null}
{
  "error": {
    "code": 500,
    "message": "Internal server error, please try again later",
    "type": "server_error"
  }
}
```

```json 502 theme={null}
{
  "error": {
    "code": 502,
    "message": "Bad gateway, the server is temporarily unavailable",
    "type": "bad_gateway"
  }
}
```

## Autorisierung

**Authorization** `string` *required*

Alle Endpunkte erfordern eine Authentifizierung per Bearer Token

API-Schlüssel erhalten:

Besuchen Sie die [Seite zur Verwaltung von API-Schlüsseln](https://gccai.heqingsong.uk/keys), um Ihren API-Schlüssel zu erhalten

Fügen Sie ihn in den Anfrage-Header ein:

```
Authorization: Bearer YOUR_API_KEY
```

## Body

**model** `string` *required* (default: gpt-image-2-official)

Name des Bildgenerierungsmodells

Fest auf `gpt-image-2-official` (offizielles OpenAI-Modell gpt-image-2) gesetzt

**nsfw\_check** `boolean` (default: false)

Legt fest, ob der Inhalt vor dem Absenden des Bildauftrags moderiert wird.

* `true`: Prompts und Eingabebilder mit `omni-moderation-latest` prüfen
* `false` oder nicht angegeben: keine Moderationsanfrage und damit keine zusätzlichen Moderationskosten oder Verzögerung (Standard)

**prompt** `string` *required*

Textbeschreibung für die Bildgenerierung

* Unterstützt Englisch und Chinesisch, detaillierte Beschreibungen werden empfohlen
* Inhaltsmoderation / Sicherheitsprüfung vor dem Einreichen — Verstöße werden sofort abgelehnt

**size** `string` (default: 1:1)

Seitenverhältnis des Bildes

Extern werden Verhältniswerte verwendet; intern werden sie gemäß `resolution` automatisch auf tatsächliche Pixel abgebildet.

Unterstützte Seitenverhältnisse, plus `auto`, damit der Server automatisch ein passendes Verhältnis auswählt:

* `auto` – Automatisch (Server wählt ein Verhältnis basierend auf Prompt / Referenzbildern)
* `1:1` – Quadrat (Standard, Social-Avatare / Logos)
* `3:2` – Querformat (gängiges DSLR-Verhältnis)
* `2:3` – Hochformat (vertikale Poster)
* `4:3` – Querformat (klassischer Monitor / Diashow)
* `3:4` – Hochformat
* `5:4` – Querformat
* `4:5` – Hochformat (Instagram-Hochformat-Post)
* `16:9` – Querformat (Breitbild-Video-Thumbnail)
* `9:16` – Hochformat (Telefon-Vollbild / Short-Video-Cover)
* `2:1` – Querformat (Web-Banner)
* `1:2` – Hochformat
* `3:1` – Querformat (ultrabreiter Banner)
* `1:3` – Hochformat (extra hohes Poster)
* `21:9` – Querformat (Kinoformat ultrabreit)
* `9:21` – Hochformat

Pixelabmessungen können auch direkt übergeben werden, z. B. `1881x836` / `887x1774`.

> [!WARNING]
>
> Wenn `size` auf `auto` gesetzt ist, beträgt das Standardverhältnis `1:1`.

**resolution** `string` (default: 1k)

Auflösungsstufe (**neues Feld**)

Steuert die tatsächliche Ausgabeschärfe.

* `1k` – Basis 1024, kosteneffizient für den täglichen Einsatz (Standard)
* `2k` – Basis 2048, geeignet für Poster / Anforderungen an hohe Auflösung
* `4k` – Basis 3840, unterstützt die 15 Verhältnisse in der Zuordnungstabelle unten

> [!WARNING]
>
> 4K unterstützt die 15 Verhältnisse in der Zuordnungstabelle unten; Sie können die Pixelabmessungen aus der Tabelle auch direkt über `size` übergeben.

**quality** `string` (default: auto)

Bildqualität

* `auto` – Automatisch (Standard, typischerweise gleichwertig mit `low`)
* `low` – Schnell und sparsam, ausreichend für grobe Umrisse
* `medium` – Ausgewogen
* `high` – Höchste Präzision (4K + high kann über 120 s dauern)

**moderation** `string` (default: auto)

Moderationsstärke

* `auto` – Standard-Moderationsstärke
* `low` – Mildere Moderation

**output\_format** `string` (default: png)

Ausgabeformat

* `png` – Standardformat, unterstützt transparente Hintergründe
* `jpeg` – Kleinere Dateien, unterstützt keinen Alphakanal
* `webp` – Unterstützt transparente Hintergründe, geeignet für moderne Browser

**output\_compression** `integer`

Ausgabe-Kompressionsstufe, Bereich `0–100`

* Nur für `jpeg` / `webp` wirksam

**n** `integer` (default: 1)

Anzahl der zu generierenden Bilder

Bereich: `1 ~ 4`

> [!WARNING]
>
> Muss eine reine Zahl sein (z. B. `1`), nicht in Anführungszeichen setzen

**image\_urls** `array`

Array mit Referenzbild-URLs

**Details**

* Max. 20 MB pro Bild, Gesamtobergrenze 256 MB
* Bis zu **16** Referenzbilder; mehr wird abgelehnt
* Müssen öffentlich zugängliche, stabile Bild-URLs sein

**mask\_url** `string`

Masken-Bild-URL, für Inpainting verwendet

* Muss zusammen mit `image_urls` verwendet werden

> [!WARNING]
>
> 1. Stellen Sie vor dem Hochladen sicher, dass das Maskenbild einen Alphakanal besitzt.
>
> 2. Die Abmessungen des Maskenbildes müssen **mit dem ersten Referenzbild übereinstimmen**.

## Size × Resolution Zuordnung

`size × resolution` → tatsächliche OpenAI-Pixel (15 Verhältnisse × 3 Stufen):

| size | `1k` | `2k` | `4k` |
| - | - | - | - |
| `1:1` | 1024×1024 | 2048×2048 | **2880×2880** |
| `3:2` | 1536×1024 | 2048×1360 | **3520×2336** |
| `2:3` | 1024×1536 | 1360×2048 | **2336×3520** |
| `4:3` | 1024×768 | 2048×1536 | **3312×2480** |
| `3:4` | 768×1024 | 1536×2048 | **2480×3312** |
| `5:4` | 1280×1024 | 2560×2048 | **3216×2576** |
| `4:5` | 1024×1280 | 2048×2560 | **2576×3216** |
| `16:9` | 1536×864 | 2048×1152 | **3840×2160** |
| `9:16` | 864×1536 | 1152×2048 | **2160×3840** |
| `2:1` | 2048×1024 | 2688×1344 | **3840×1920** |
| `1:2` | 1024×2048 | 1344×2688 | **1920×3840** |
| `3:1` | 1881×836 / 1536×512 | 3072×1024 | **3840×1280** |
| `1:3` | 887×1774 / 512×1536 | 1024×3072 | **1280×3840** |
| `21:9` | 2016×864 | 2688×1152 | **3840×1648** |
| `9:21` | 864×2016 | 1152×2688 | **1648×3840** |

> Hinweis: Einige Abmessungen sind auf Vielfache von 16 und Pixelgrenzen angenähert, z. B. `3:2` / `2:3` @ 2K mit 2048×1360 und `21:9` @ 4K mit 3840×1648. Als verbindliche Quelle gelten die tatsächlichen Pixel in der Tabelle.

## Anwendungsbeispiele

**Text-zu-Bild (minimale Anfrage)**

```json theme={null}
{
  "model": "gpt-image-2-official",
  "prompt": "An ancient castle beneath a starry sky"
}
```

**Text-zu-Bild (transparenter Sticker)**

```json theme={null}
{
  "model": "gpt-image-2-official",
  "prompt": "A cute cartoon orange cat sticker, full body, thick white outline, flat vector style, isolated on a fully transparent background",
  "size": "1:1",
  "resolution": "1k",
  "quality": "medium",
  "output_format": "png",
  "n": 1
}
```

**Bild-zu-Bild (Hintergrund entfernen)**

```json theme={null}
{
  "model": "gpt-image-2-official",
  "prompt": "Remove the background, keep only the product, isolated on a fully transparent background",
  "image_urls": ["https://your-cdn.com/product.jpg"],
  "size": "1:1",
  "resolution": "1k",
  "output_format": "png"
}
```

**2K-Hochauflösungsposter**

```json theme={null}
{
  "model": "gpt-image-2-official",
  "prompt": "Cyberpunk night scene",
  "size": "16:9",
  "resolution": "2k",
  "quality": "high",
  "output_format": "jpeg",
  "output_compression": 90
}
```

**4K-Hintergrundbild**

```json theme={null}
{
  "model": "gpt-image-2-official",
  "prompt": "Snow mountain sunrise panorama",
  "size": "16:9",
  "resolution": "4k",
  "quality": "high",
  "n": 1
}
```

**Bild-zu-Bild (Mehrfachreferenz-Fusion)**

```json theme={null}
{
  "model": "gpt-image-2-official",
  "prompt": "Fuse the two reference images into a single illustration poster, preserving the main silhouettes",
  "size": "1:1",
  "quality": "high",
  "image_urls": [
    "https://your-cdn.com/input-a.png",
    "https://your-cdn.com/input-b.png"
  ]
}
```

**Inpainting (Maske)**

```json theme={null}
{
  "model": "gpt-image-2-official",
  "prompt": "Replace the background with a desert sunset",
  "size": "1:1",
  "quality": "medium",
  "image_urls": ["https://your-cdn.com/photo.png"],
  "mask_url": "https://your-cdn.com/mask.png"
}
```

**Mehrere Bilder (n > 1)**

```json theme={null}
{
  "model": "gpt-image-2-official",
  "prompt": "Four minimalist poster variations of a red fox",
  "size": "1:1",
  "quality": "low",
  "n": 4
}
```

**Direkte Pixel-Zeichenkette (fortgeschritten)**

```json theme={null}
{
  "model": "gpt-image-2-official",
  "prompt": "wide cinematic shot",
  "size": "3840x2160",
  "quality": "high"
}
```

## Response

**code** `integer`

Statuscode der Antwort

**data** `array`

Array mit Antwortdaten

**Eigenschaften**

**status** `string`

Aufgabenstatus

* `submitted` – Eingereicht

**task\_id** `string`

Eindeutige Aufgabenkennung, wird für nachfolgende Ergebnisabfragen verwendet

## Abfrage der Aufgabenergebnisse

Nach erfolgreicher Einreichung wird eine `task_id` zurückgegeben. Pollen Sie den Aufgabenstatus über `GET /v1/tasks/{task_id}`, siehe [API zur Aufgabenabfrage](https://gccai.heqingsong.uk/de/api-reference/tasks/status.md) für Details.

### Beispiel einer erfolgreichen Antwort

```json theme={null}
{
  "code": 200,
  "data": {
    "actual_time": 14,
    "completed": 1784607890,
    "cost": 0.004792,
    "created": 1784607876,
    "credits_cost": 0.047920000000000004,
    "estimated_time": 60,
    "id": "task_01KPTXXXXXXXXXXXXXXX",
    "progress": 100,
    "result": {
      "images": [
        {
          "expires_at": 1784694290,
          "url": [
            "https://upload.gccai.ai/f/image/xxxxxxxx-gpt_image_2_official_task_xxx_0.png"
          ]
        }
      ]
    },
    "status": "completed",
    "usage": {
      "input_tokens": 22,
      "input_tokens_details": {
        "cached_tokens": 0,
        "image_tokens": 0,
        "text_tokens": 22
      },
      "output_tokens": 196,
      "output_tokens_details": {
        "image_tokens": 196,
        "text_tokens": 0
      },
      "total_tokens": 218
    }
  }
}
```

Das Feld `usage` gibt den abrechenbaren Token-Verbrauch dieser Anfrage an:

| Feld | Beschreibung |
| - | - |
| `input_tokens` | Insgesamt verbrauchte Eingabe-Tokens |
| `input_tokens_details.cached_tokens` | Aus dem Cache bediente Eingabe-Tokens |
| `input_tokens_details.image_tokens` | Von Eingabebildern verwendete Tokens |
| `input_tokens_details.text_tokens` | Von Eingabetext (Prompt) verwendete Tokens |
| `output_tokens` | Insgesamt verbrauchte Ausgabe-Tokens |
| `output_tokens_details.image_tokens` | Vom generierten Bild verwendete Tokens |
| `output_tokens_details.text_tokens` | Vom Ausgabetext verwendete Tokens |
| `total_tokens` | Gesamtanzahl der Tokens, entspricht `input_tokens` + `output_tokens` |

Bei der Bildgenerierung besteht die Ausgabe hauptsächlich aus Bild-Tokens, daher entspricht `output_tokens_details.image_tokens` in der Regel `output_tokens`. Im obigen Beispiel gilt `total_tokens` = 22 + 196 = 218.

Aufgabenstatusverlauf: `submitted` → `in_progress` → `completed` / `failed`.

Bildzugriff: `data.result.images[0].url[0]`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.