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

# Bild hochladen

> Laden Sie ein Bild hoch, um eine URL für die Verwendung mit Bild-/Video-Generierungs-APIs zu erhalten

<Note>
  **Der Doku-Playground unterstützt keinen Datei-Upload**: Verwenden Sie zum Testen die untenstehenden Codebeispiele für cURL, Python oder JavaScript.
</Note>

<Warning>
  **Wichtige Änderung:** Aus Gründen der Performance- und Kostenkontrolle unterstützen wir die direkte Übergabe von Base64-Bilddaten in den Generierungs-APIs nicht mehr. Bitte verwenden Sie diese API, um Bilder hochzuladen, die URL abzurufen und dann die Generierungs-API aufzurufen.
</Warning>

## Warum Bilder zuerst hochladen?

1. **Performance-Optimierung** – Base64-Kodierung vergrößert die Daten um 33 %; vorheriges Hochladen reduziert die Größe des Request-Bodys erheblich
2. **Bilder wiederverwenden** – Einmal hochladen, die URL beliebig oft wiederverwenden, ohne dass redundante Übertragungen nötig sind

## Workflow

```mermaid theme={null}
sequenceDiagram
    participant Client
    participant GccAi
    participant Storage

    Client->>GccAi: POST /v1/uploads/images (Upload image file)
    GccAi->>Storage: Save image
    Storage-->>GccAi: Return storage path
    GccAi-->>Client: Return image URL
    Client->>GccAi: POST /v1/images/generations (Use image URL)
```

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://gccai.heqingsong.uk/v1/uploads/images \
    --header 'Authorization: Bearer <token>' \
    --form 'file=@/path/to/your/image.jpg'
  ```

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

  # Upload image
  with open('image.jpg', 'rb') as f:
      response = requests.post(
          "https://gccai.heqingsong.uk/v1/uploads/images",
          headers={
              "Authorization": "Bearer <token>"
          },
          files={
              "file": f
          }
      )

  result = response.json()
  image_url = result['url']
  print(f"Image URL: {image_url}")

  # Use the uploaded image for generation
  response = requests.post(
      "https://gccai.heqingsong.uk/v1/images/generations",
      headers={
          "Authorization": "Bearer <token>",
          "Content-Type": "application/json"
      },
      json={
          "model": "gemini-3-pro-image-preview",
          "prompt": "Create a variation based on this image",
          "image_urls": [{"url": image_url}]
      }
  )
  ```

  ```javascript JavaScript theme={null}
  // Upload image
  const formData = new FormData();
  formData.append('file', fileInput.files[0]);

  const uploadResponse = await fetch('https://gccai.heqingsong.uk/v1/uploads/images', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer <token>'
    },
    body: formData
  });

  const uploadResult = await uploadResponse.json();
  const imageUrl = uploadResult.url;
  console.log(`Image URL: ${imageUrl}`);

  // Use the uploaded image for generation
  const genResponse = await fetch('https://gccai.heqingsong.uk/v1/images/generations', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer <token>',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      model: 'gemini-3-pro-image-preview',
      prompt: 'Create a variation based on this image',
      image_urls: [{url: imageUrl}]
    })
  });
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "url": "https://upload.gccai.ai/f/image/9990000123456-a1b2c3d4-photo.jpg",
    "filename": "photo.jpg",
    "content_type": "image/jpeg",
    "bytes": 235680,
    "created_at": 1743436800
  }
  ```

  ```json 400 - Missing File Field theme={null}
  {
    "error": {
      "message": "missing or invalid file field: http: no such file",
      "type": "invalid_request_error"
    }
  }
  ```

  ```json 400 - Unsupported Format theme={null}
  {
    "error": {
      "message": "unsupported image type: application/pdf, allowed: jpeg, png, gif, webp",
      "type": "invalid_request_error"
    }
  }
  ```

  ```json 413 - File Too Large theme={null}
  {
    "error": {
      "message": "file size 25165824 exceeds maximum 20971520 bytes",
      "type": "invalid_request_error"
    }
  }
  ```

  ```json 429 - Rate Limit Exceeded theme={null}
  {
    "error": {
      "code": 429,
      "message": "Rate limit exceeded. Please try again later",
      "type": "rate_limit_error"
    }
  }
  ```

  ```json 500 - Upload Failed theme={null}
  {
    "error": {
      "message": "failed to upload image",
      "type": "server_error"
    }
  }
  ```
</ResponseExample>

## Autorisierungen

<ParamField header="Authorization" type="string" required>
  Alle APIs erfordern eine Authentifizierung per Bearer Token

  API-Key abrufen:

  Besuchen Sie die [API-Key-Verwaltungsseite](https://gccai.heqingsong.uk/keys), um Ihren API-Key zu erhalten

  Fügen Sie ihn den Request-Headern hinzu:

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Body

<ParamField body="file" type="file" required>
  Bilddatei

  Unterstützte Formate: JPEG (.jpg, .jpeg), PNG (.png), WebP (.webp), GIF (.gif)

  Maximale Dateigröße: 20 MB
</ParamField>

## Antwort

<ResponseField name="url" type="string">
  Öffentliche Zugriffs-URL des Bildes; kann direkt in Generierungs-APIs verwendet werden (72 Stunden gültig)
</ResponseField>

<ResponseField name="filename" type="string">
  Ursprünglicher Dateiname
</ResponseField>

<ResponseField name="content_type" type="string">
  Erkannter MIME-Typ, z. B. `image/jpeg`
</ResponseField>

<ResponseField name="bytes" type="integer">
  Dateigröße in Bytes
</ResponseField>

<ResponseField name="created_at" type="integer">
  Upload-Zeitpunkt als Unix-Zeitstempel (Sekunden)
</ResponseField>

## Vollständiges Beispiel: Bild-zu-Bild-Workflow

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

API_KEY = "your-GccAi-key"
BASE_URL = "https://gccai.heqingsong.uk"

# Step 1: Upload reference image
def upload_image(file_path):
    with open(file_path, 'rb') as f:
        response = requests.post(
            f"{BASE_URL}/v1/uploads/images",
            headers={"Authorization": f"Bearer {API_KEY}"},
            files={"file": f}
        )
    return response.json()['url']

# Step 2: Create generation task
def create_generation(image_url, prompt):
    response = requests.post(
        f"{BASE_URL}/v1/images/generations",
        headers={
            "Authorization": f"Bearer {API_KEY}",
            "Content-Type": "application/json"
        },
        json={
            "model": "gemini-3-pro-image-preview",
            "prompt": prompt,
            "image_urls": [{"url": image_url}],
            "size": "16:9"
        }
    )
    return response.json()['id']

# Step 3: Poll task status
def wait_for_result(task_id):
    while True:
        response = requests.get(
            f"{BASE_URL}/v1/images/generations/{task_id}",
            headers={"Authorization": f"Bearer {API_KEY}"}
        )
        result = response.json()

        if result['status'] == 'completed':
            return result['url']
        elif result['status'] == 'failed':
            raise Exception(f"Generation failed: {result.get('fail_reason')}")

        time.sleep(2)

# Execute workflow
image_url = upload_image("reference.jpg")
print(f"Image uploaded: {image_url}")

task_id = create_generation(image_url, "Transform this photo into Ghibli anime style")
print(f"Task created: {task_id}")

result_url = wait_for_result(task_id)
print(f"Generation complete: {result_url}")
```
