> ## Documentation Index
> Fetch the complete documentation index at: https://comfyuiwiki.com/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?onboarding=router)でキーを作成し、`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 defaultTabIndex={1}>
  <Tab title="結果を待つ">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # 環境変数から COMFY_API_KEY を読み取ります。
      # SDK は自動的に冪等キーを作成し、自動リトライのために再利用します。
      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";

      // 環境変数から COMFY_API_KEY を読み取ります。
      // SDK は自動的に冪等キーを作成し、自動リトライのために再利用します。
      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="キューに送信して後で取得する">
    同じボディを `POST https://api.comfy.org/v2/models/bfl/flux-2-max/requests` に送信します。Router は実行が受け付けられ次第 `201` と `request_id` を返し、結果は準備が整った時点で、このプロセスからでも別のプロセスからでも取得できます。ステータス、キャンセル、結果の取得の詳細は[キュー配信](/ja/development/comfy-router/queue)を参照してください。

    <CodeGroup>
      ```python Python theme={null}
      import asyncio
      from comfy_sdk import AsyncComfy

      # 環境変数から COMFY_API_KEY を読み取ります。
      # 各 submit() 呼び出しは独自の Idempotency-Key を発行し、自動リトライのために再利用します。
      async def main():
          async with AsyncComfy() as client:
              handle = await client.models.submit(
                  "bfl/flux-2-max",
                  {
                      "prompt": "A single red maple leaf on a plain white background.",
                  },
              )
              print("request_id:", handle.request_id)  # モデル ID と合わせて、別のプロセスに必要な情報はこれだけです

              # リクエストが完了するまでポーリングし、サーバーが指定する Retry-After を待機します。
              async for update in handle.iter_events():
                  print(update.status, update.queue_position)

              # プロバイダー自身のペイロードで、models.run() が返す値と同じです。
              # 失敗またはキャンセルされたリクエストは、ここで型付きの Router エラーを発生させます。
              result = await handle.get()

          print(result)

      asyncio.run(main())
      ```

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

      // 環境変数から COMFY_API_KEY を読み取ります。
      // 各 submit() 呼び出しは独自の Idempotency-Key を発行し、自動リトライのために再利用します。
      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); // モデル ID と合わせて、別のプロセスに必要な情報はこれだけです

      // リクエストが完了するまでポーリングし、サーバーが指定する Retry-After を待機します。
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // models.run() が返すのと同じ結果です。失敗またはキャンセルされたリクエストはここで reject されます。
      const result = await handle.get();

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

      ```bash cURL theme={null}
      # 1. 送信。Router は request_id、status_url、response_url、cancel_url とともに 201 を返します。
      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. status が COMPLETED になるまでポーリングし、各レスポンスが指定する Retry-After 秒を待機します。
      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. 取得。200 はモデルのネイティブ出力、まだ実行中は 202 とステータスボディを返します。
      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 が入力を拒否したことを意味し、`413` はリクエスト本文が Router の受け入れ可能なサイズを超えていたことを意味します。生成されたアセットは [結果 URL の有効期限](/ja/development/comfy-router/reference#結果アセット) があるため、早めにダウンロードしてください。

上記のフィールド説明に記載されているサイズ制限は、プロバイダーの仕様から引用した、そのフィールドに対するプロバイダー自身の上限です。Router はリクエスト本文全体に対して別の上限を適用し、base64 エンコードされたメディアもこれにカウントされます。[リクエスト本文のサイズ](/ja/development/comfy-router/limitations) を参照してください。

このページは、Comfy Router 経由で呼び出す 1 つのパートナーモデルについて説明しています。同じ `comfy-sdk` / `@comfyorg/sdk` パッケージには、Comfy Cloud 上で ComfyUI のワークフローグラフ全体を実行するための 2 つ目のクライアントも含まれています: `Comfy(api_key=...)` / `new Comfy({ apiKey })`、および `client.workflows`、`client.assets`、`client.jobs`。[Comfy SDKs](/ja/development/api-development/sdks) を参照してください。

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

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

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