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

# Flux 2.0 Pembuatan Gambar

>  - Mode pemrosesan asinkron, mengembalikan ID tugas untuk kueri berikutnya
- Mendukung text-to-image dan image-to-image
- Tautan gambar yang dihasilkan berlaku selama 24 jam; harap segera simpan 

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.apimart.ai/v1/images/generations \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "flux-2-flex",
      "prompt": "A blue cat on the grass",
      "resolution": "1K",
      "size": "16:9"
    }'
  ```

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

  url = "https://api.apimart.ai/v1/images/generations"

  payload = {
      "model": "flux-2-flex",
      "prompt": "A blue cat on the grass",
      "resolution": "1K",
      "size": "16:9"
  }

  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://api.apimart.ai/v1/images/generations";

  const payload = {
    model: "flux-2-flex",
    prompt: "A blue cat on the grass",
    resolution: "1K",
    size: "16:9"
  };

  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));
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "code": 200,
    "data": [
      {
        "status": "submitted",
        "task_id": "task_01KFG5BBFNK1YQDTJDZY0P0QT2"
      }
    ]
  }
  ```

  ```json 400 theme={null}
  {
    "error": {
      "code": 400,
      "message": "Invalid request parameters",
      "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 balance, please top up",
      "type": "payment_required"
    }
  }
  ```
</ResponseExample>

## Model yang Didukung

| Model         | Deskripsi                                                                      | Harga                        |
| ------------- | ------------------------------------------------------------------------------ | ---------------------------- |
| `flux-2-flex` | Model pembuatan gambar Flux 2.0 Flex (lebih cepat, cocok untuk iterasi cepat)  | Berdasarkan resolusi (1K/2K) |
| `flux-2-pro`  | Model pembuatan gambar Flux 2.0 Pro (kualitas lebih tinggi, detail lebih baik) | Berdasarkan resolusi (1K/2K) |

## Otorisasi

<ParamField header="Authorization" type="string" required>
  Semua endpoint memerlukan autentikasi Bearer Token

  Dapatkan API Key:

  Kunjungi [Manajemen API Key](https://apimart.ai/keys) untuk mendapatkan API Key Anda

  Tambahkan ke header permintaan:

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

## Body

<ParamField body="model" type="string" required>
  Nama model

  * `flux-2-flex` - Model Flux 2.0 Flex (lebih cepat, cocok untuk iterasi cepat)
  * `flux-2-pro` - Model Flux 2.0 Pro (kualitas lebih tinggi, detail lebih baik)
</ParamField>

<ParamField body="prompt" type="string" required>
  Deskripsi teks untuk pembuatan gambar
</ParamField>

<ParamField body="resolution" type="string" default="1K">
  Resolusi gambar

  Resolusi yang didukung:

  * `1K` - Default, level 1080p
  * `2K` - HD, maksimum 2048 piksel

  > Tidak peka huruf besar/kecil: `1k`, `1K`, `2k`, `2K` semuanya dapat digunakan
</ParamField>

<ParamField body="size" type="string" default="1:1">
  Rasio aspek gambar

  Rasio aspek yang didukung:

  * `1:1` - Persegi (default)
  * `4:3` - Lanskap
  * `3:4` - Potret
  * `16:9` - Layar lebar
  * `9:16` - Vertikal
  * `3:2` - Lanskap klasik
  * `2:3` - Potret klasik

  > Hanya 7 rasio ini yang didukung; rasio yang tidak didukung akan mengembalikan error
</ParamField>

<ParamField body="image_urls" type="array">
  Daftar URL gambar referensi

  **Batasan:**

  * Maksimum 8 images
  * Harus berupa URL yang dapat diakses publik
  * Format Base64 tidak didukung
</ParamField>

## Tabel Referensi Resolusi

| Rasio  | Nama            | 1K Ukuran | 2K Ukuran |
| ------ | --------------- | --------- | --------- |
| `1:1`  | Persegi         | 1440×1440 | 1536×1536 |
| `4:3`  | Lanskap         | 1664×1248 | 1824×1368 |
| `3:4`  | Potret          | 1248×1664 | 1368×1824 |
| `16:9` | Layar lebar     | 1920×1080 | 2048×1152 |
| `9:16` | Vertikal        | 1080×1920 | 1152×2048 |
| `3:2`  | Classic Lanskap | 1728×1152 | 1872×1248 |
| `2:3`  | Classic Potret  | 1152×1728 | 1248×1872 |

## Contoh Penggunaan

**Text-to-Image Dasar**

```json theme={null}
{
    "model": "flux-2-flex",
    "prompt": "A blue cat",
    "resolution": "1K",
    "size": "16:9"
}
```

**Pembuatan Resolusi Tinggi**

```json theme={null}
{
    "model": "flux-2-pro",
    "prompt": "Detailed landscape painting with mountains and rivers",
    "resolution": "2K",
    "size": "16:9"
}
```

**Image-to-Image (hingga 8 gambar referensi)**

```json theme={null}
{
    "model": "flux-2-flex",
    "prompt": "Convert image to watercolor style",
    "image_urls": [
        "https://example.com/input1.jpg",
        "https://example.com/input2.jpg"
    ],
    "resolution": "1K"
}
```

## Respons

<ResponseField name="code" type="integer">
  Kode status respons
</ResponseField>

<ResponseField name="data" type="array">
  Array data respons

  <Expandable title="Properti">
    <ResponseField name="status" type="string">
      Status tugas

      * `submitted` - Dikirim
    </ResponseField>

    <ResponseField name="task_id" type="string">
      Pengidentifikasi unik tugas
    </ResponseField>
  </Expandable>
</ResponseField>

## Catatan

1. **Persyaratan URL Gambar**: Gambar input harus berupa URL yang dapat diakses publik; base64 tidak didukung
2. **Penyimpanan Hasil**: Gambar yang dihasilkan disimpan otomatis; URL berlaku selama 24 jam
3. **Polling Tugas**: Tugas diproses secara asinkron; polling `/v1/tasks/{task_id}` untuk hasil
4. **Batas Gambar Input**: Hingga 8 gambar referensi didukung
