> ## 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 画像生成

>  - 非同期処理モード、後続のクエリ用にタスクIDを返します
- テキストから画像、画像から画像生成をサポート
- 生成された画像リンクの有効期限は24時間です、お早めに保存してください 

<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": "草原の上の青い猫",
      "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": "草原の上の青い猫",
      "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: "草原の上の青い猫",
    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": "リクエストパラメータが無効です",
      "type": "invalid_request_error"
    }
  }
  ```

  ```json 401 theme={null}
  {
    "error": {
      "code": 401,
      "message": "認証に失敗しました、APIキーを確認してください",
      "type": "authentication_error"
    }
  }
  ```

  ```json 402 theme={null}
  {
    "error": {
      "code": 402,
      "message": "残高不足です、チャージしてください",
      "type": "payment_required"
    }
  }
  ```
</ResponseExample>

## サポートされているモデル

| モデル名          | 説明                                     | 課金方式           |
| ------------- | -------------------------------------- | -------------- |
| `flux-2-flex` | Flux 2.0 Flex 画像生成モデル（高速、迅速な反復に適しています） | 解像度別課金 (1K/2K) |
| `flux-2-pro`  | Flux 2.0 Pro 画像生成モデル（より高品質、より詳細）       | 解像度別課金 (1K/2K) |

## 認証

<ParamField header="Authorization" type="string" required>
  すべてのエンドポイントはBearer Token認証が必要です

  API Keyの取得：

  [API Key管理ページ](https://apimart.ai/keys)でAPI Keyを取得してください

  リクエストヘッダーに追加：

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

## Body

<ParamField body="model" type="string" required>
  モデル名

  * `flux-2-flex` - Flux 2.0 Flexモデル（高速、迅速な反復に適しています）
  * `flux-2-pro` - Flux 2.0 Proモデル（より高品質、より詳細）
</ParamField>

<ParamField body="prompt" type="string" required>
  画像生成のテキスト説明
</ParamField>

<ParamField body="resolution" type="string" default="1K">
  画像解像度

  サポートされている解像度：

  * `1K` - デフォルト、1080pレベル
  * `2K` - HD、最大2048ピクセル

  > 大文字小文字を区別しません：`1k`、`1K`、`2k`、`2K` すべて使用可能
</ParamField>

<ParamField body="size" type="string" default="1:1">
  画像のアスペクト比

  サポートされているアスペクト比:

  * `1:1` - 正方形（デフォルト）
  * `4:3` - 横向き
  * `3:4` - 縦向き
  * `16:9` - ワイドスクリーン
  * `9:16` - 縦向き
  * `3:2` - クラシック横向き
  * `2:3` - クラシック縦向き

  > 上記7種類の比率のみサポート、サポートされていない比率はエラーを返します
</ParamField>

<ParamField body="image_urls" type="array">
  参照画像URLリスト

  **制限：**

  * 最大8枚
  * 公開アクセス可能なURLである必要があります
  * Base64形式はサポートされていません
</ParamField>

## 解像度参照表

| 比率     | 名前       | 1K サイズ    | 2K サイズ    |
| ------ | -------- | --------- | --------- |
| `1:1`  | 正方形      | 1440×1440 | 1536×1536 |
| `4:3`  | 横向き      | 1664×1248 | 1824×1368 |
| `3:4`  | 縦向き      | 1248×1664 | 1368×1824 |
| `16:9` | ワイドスクリーン | 1920×1080 | 2048×1152 |
| `9:16` | 縦向き      | 1080×1920 | 1152×2048 |
| `3:2`  | クラシック横向き | 1728×1152 | 1872×1248 |
| `2:3`  | クラシック縦向き | 1152×1728 | 1248×1872 |

## 使用例

**基本テキストから画像**

```json theme={null}
{
    "model": "flux-2-flex",
    "prompt": "青い猫",
    "resolution": "1K",
    "size": "16:9"
}
```

**高解像度生成**

```json theme={null}
{
    "model": "flux-2-pro",
    "prompt": "山と川の詳細な風景画",
    "resolution": "2K",
    "size": "16:9"
}
```

**画像から画像（最大8枚の参照画像）**

```json theme={null}
{
    "model": "flux-2-flex",
    "prompt": "画像を水彩画スタイルに変換",
    "image_urls": [
        "https://example.com/input1.jpg",
        "https://example.com/input2.jpg"
    ],
    "resolution": "1K"
}
```

## Response

<ResponseField name="code" type="integer">
  レスポンスステータスコード
</ResponseField>

<ResponseField name="data" type="array">
  レスポンスデータ配列

  <Expandable title="属性">
    <ResponseField name="status" type="string">
      タスクステータス

      * `submitted` - 送信済み
    </ResponseField>

    <ResponseField name="task_id" type="string">
      タスク一意識別子
    </ResponseField>
  </Expandable>
</ResponseField>

## 注意事項

1. **画像URL要件**：入力画像は公開アクセス可能なURLである必要があります、base64はサポートされていません
2. **結果保存**：生成された画像は自動的に保存され、URLは24時間有効です
3. **タスクポーリング**：タスクは非同期で処理されます、結果を取得するには `/v1/tasks/{task_id}` をポーリングしてください
4. **入力画像制限**：最大8枚までサポート
