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

# Comfy Router で FLUX 2 Max を使う

> Comfy Router 経由で bfl/flux-2-max を呼び出します: エンドポイント、リクエストの形状、Router が返すレスポンスについて説明します。

`bfl/flux-2-max` のAPIリファレンス。Black Forest Labs から Comfy Router 経由で提供されています。

## クイックスタート

[Comfy ワークスペース](https://platform.comfy.org/profile/api-keys)でキーを作成し、`COMFY_API_KEY` としてエクスポートします。Python と TypeScript のスニペットは Comfy SDK（`pip install comfy-sdk`、`npm install @comfyorg/sdk`）を使用しており、cURL のスニペットは同じ呼び出しを生の HTTP で実行するものです。

**モデル ID:** `bfl/flux-2-max`

**エンドポイント:** `POST https://api.comfy.org/v2/models/bfl/flux-2-max`

<Tabs>
  <Tab title="Wait for the result">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # The SDK automatically creates an idempotency key and reuses it for automatic retries.
      with Comfy() as client:
          result = client.models.run(
              "bfl/flux-2-max",
              {
                  "prompt": "A single red maple leaf on a plain white background.",
              },
          )

      print(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // Reads COMFY_API_KEY from the environment.
      // The SDK automatically creates an idempotency key and reuses it for automatic retries.
      const { data } = await comfy.models.run("bfl/flux-2-max", {
        prompt: "A single red maple leaf on a plain white background.",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/bfl/flux-2-max \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"prompt\": \"A single red maple leaf on a plain white background.\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Queue and collect later">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      with Comfy() as client:
          handle = client.models.submit(
              "bfl/flux-2-max",
              {
                  "prompt": "A single red maple leaf on a plain white background.",
              },
          )
          print("request_id:", handle.request_id)  # with the model ID, all another process needs

          # Poll until the request completes, waiting the Retry-After the server names.
          for update in handle.iter_events():
              print(update.status, update.queue_position)

          # The provider's own payload, the same value models.run() returns.
          # A request that failed or was cancelled raises the typed Router error here.
          result = handle.get()

      print(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // Reads COMFY_API_KEY from the environment.
      // Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      const handle = await comfy.models.submit("bfl/flux-2-max", {
        prompt: "A single red maple leaf on a plain white background.",
      });
      console.log("requestId:", handle.requestId); // with the model ID, all another process needs

      // Poll until the request completes, waiting the Retry-After the server names.
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // The same result models.run() returns. A request that failed or was cancelled rejects here.
      const result = await handle.get();

      console.log(result.data);
      ```

      ```bash cURL theme={null}
      # 1. Submit. Router answers 201 with request_id, status_url, response_url and cancel_url.
      curl https://api.comfy.org/v2/models/bfl/flux-2-max/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"prompt\": \"A single red maple leaf on a plain white background.\"}"

      # 2. Poll until status is COMPLETED, waiting the Retry-After seconds each response names.
      REQUEST_ID="<request_id from the 201 body>"
      curl -i https://api.comfy.org/v2/models/bfl/flux-2-max/requests/$REQUEST_ID/status \
        -H "X-API-Key: $COMFY_API_KEY"

      # 3. Collect. 200 with the model's native output, 202 with the status body while it is still running.
      curl https://api.comfy.org/v2/models/bfl/flux-2-max/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## スキーマ

### 入力

<ParamField body="height" type="integer" default="1024">
  画像の高さ。

  範囲: `256` から `2048`
</ParamField>

<ParamField body="input_image" type="string">
  画像から画像への生成に使用する Base64 エンコードされた画像。
</ParamField>

<ParamField body="input_image_2" type="string">
  画像から画像への生成に使用する Base64 エンコードされた画像。
</ParamField>

<ParamField body="input_image_3" type="string">
  画像から画像への生成に使用する Base64 エンコードされた画像。
</ParamField>

<ParamField body="input_image_4" type="string">
  画像から画像への生成に使用する Base64 エンコードされた画像。
</ParamField>

<ParamField body="input_image_5" type="string">
  画像から画像への生成に使用する Base64 エンコードされた画像。
</ParamField>

<ParamField body="input_image_6" type="string">
  画像から画像への生成に使用する Base64 エンコードされた画像。
</ParamField>

<ParamField body="input_image_7" type="string">
  画像から画像への生成に使用する Base64 エンコードされた画像。
</ParamField>

<ParamField body="input_image_8" type="string">
  画像から画像への生成に使用する Base64 エンコードされた画像。
</ParamField>

<ParamField body="input_image_9" type="string">
  画像から画像への生成に使用する Base64 エンコードされた画像。
</ParamField>

<ParamField body="output_format" type="string" default="&#x22;jpeg&#x22;">
  生成される画像の出力形式。

  指定可能な値: `jpeg`、`png`
</ParamField>

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

<ParamField body="prompt_upsampling" type="boolean" default="true">
  生成のためにプロンプトを自動的に変更します。
</ParamField>

<ParamField body="safety_tolerance" type="integer" default="2">
  モデレーションの許容値レベル (Flux 2 Max のみ)。

  範囲: `0` から `5`
</ParamField>

<ParamField body="seed" type="integer">
  再現性のためのシード。
</ParamField>

<ParamField body="width" type="integer" default="1024">
  画像の幅。

  範囲: `256` から `2048`
</ParamField>

Router が `GET /v2/models/bfl/flux-2-max/openapi.json` で提供しているスキーマから生成されています。これは、リクエストがプロバイダーに到達する前に Router が呼び出しの検証に使用するドキュメントと同じものです。

### 出力

<ResponseField name="cost" type="number">
  プロバイダーが報告するクレジット単位のコスト。タスクが Ready になると設定されます。

  形式: `float`
</ResponseField>

<ResponseField name="id" type="string" required>
  BFL のタスク識別子。
</ResponseField>

<ResponseField name="progress" type="number">
  BFL が報告する省略可能な生成の進捗。

  範囲: `0` から `1`

  形式: `float`
</ResponseField>

<ResponseField name="result" type="object" required>
  完了した生成結果。ここでは null 許容ではありません。このコンポーネントの `required` エントリは、`200` が結果を伴うことを約束するものであり、`result` を null 許容にすると、単なるキーの存在チェックにまで後退してしまいます。
</ResponseField>

<ResponseField name="result.cost" type="number">
  プロバイダーが報告する生成のコスト。これは BFL の数値であり、Comfy の請求額ではありません。

  形式: `double`
</ResponseField>

<ResponseField name="result.duration" type="number">
  プロバイダーが報告する生成時間 (秒単位)。

  形式: `double`
</ResponseField>

<ResponseField name="result.end_time" type="number">
  プロバイダーが報告する生成の完了時刻。Unix エポックからの秒数で表されます。`start_time` と同じ理由で `double` です。

  形式: `double`
</ResponseField>

<ResponseField name="result.prompt" type="string">
  プロンプトのアップサンプリング後、実際に生成で使用されたプロンプト。
</ResponseField>

<ResponseField name="result.sample" type="string (uri)">
  生成されたアセットの署名付き URL。Router はアセットを Comfy のストレージに再ホストしてこのフィールドを書き換えるため、通常は最大 24 時間有効な Comfy ホストの URL になります。発行時に 24 時間の署名が付与され、23 時間のメモから再生されるため、後でのポーリングでは残り 1 時間しかない URL が返されることがあります。再ホストを実行できなかったリーフは、代わりに BFL 自身の短命な配信用 URL を保持します。ビデオでは約 2 時間、画像では約 10 分です。いずれにしてもリンクは失効するため、URL を保存するのではなくアセットをダウンロードしてください。

  形式: `uri`
</ResponseField>

<ResponseField name="result.seed" type="integer">
  生成で使用されたシード。指定されたものでもプロバイダーが選択したものでもかまいません。BFL は 2^31 を超えるシード (例: 2784347701) を返すため `int64` として宣言されています。フォーマットされていない `integer` は、多くの SDK ジェネレーターで 32 ビットフィールドとして生成されてしまいます。

  形式: `int64`
</ResponseField>

<ResponseField name="result.start_time" type="number">
  プロバイダーが報告する生成の開始時刻。Unix エポックからの秒数で表されます。`float` ではなく `double` です。現在のエポック値付近では float32 の間隔が約 128 秒になるため、生成全体の期間が単一のデコード値に潰れてしまいます。

  形式: `double`
</ResponseField>

<ResponseField name="status" type="string" required>
  タスクのステータス: Pending、Reasoning、Generating、Ready、Request Moderated、Content Moderated、Error、または Task not found。
</ResponseField>

## 例

### 入力

```json theme={null}
{
  "prompt": "A single red maple leaf on a plain white background."
}
```

### 出力

```json theme={null}
{
  "cost": null,
  "id": "b2e0c1a4-0f2f-4a55-9f2e-2f9a1c0d4e77",
  "progress": null,
  "result": {
    "cost": null,
    "duration": 3.4,
    "end_time": 1767225603.4,
    "prompt": "A watercolor painting of a lighthouse at dawn, soft light on the water",
    "sample": "https://example.invalid/bfl/flux-pro-1.1/sample.png",
    "seed": 2784347701,
    "start_time": 1767225600
  },
  "status": "Ready"
}
```

## 出荷前の確認

SDK は `Idempotency-Key` を生成し、自動リトライで再利用します。手動リトライでは元のキーを再利用してください。Router は最大 10 分間接続を保持できます。

リクエストが失敗すると、Router は理由を示す `X-Comfy-Error-Type` レスポンスヘッダーを送信します。`422` は、プロバイダーを呼び出す前に Router が入力を拒否したことを意味します。生成されたアセットは [結果 URL の有効期限](/ja/development/comfy-router/reference#結果アセット) があるため、早めにダウンロードしてください。

<CardGroup cols={3}>
  <Card title="ヘッダー" icon="list" href="/ja/development/comfy-router/quickstart">
    認証、冪等性、リクエスト ID、エラー分類、リトライ間隔、支出上限。
  </Card>

  <Card title="Router API の利用" icon="code" href="/ja/development/comfy-router/quickstart">
    モデルの検出、バリデーションエラー、リトライ、課金。
  </Card>

  <Card title="制限事項" icon="triangle-exclamation" href="/ja/development/comfy-router/limitations">
    Router が現在対応していないことと、代替手段。
  </Card>
</CardGroup>
