> ## 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 Pro を使用する

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

`bfl/flux-2-pro` の 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-pro`

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

<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-pro",
              {
                  "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-pro", {
        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-pro \
        -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-pro",
              {
                  "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-pro", {
        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-pro/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-pro/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-pro/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### Input

<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-pro/openapi.json` で提供するスキーマから生成されています。これは、リクエストがプロバイダーに到達する前に Router が呼び出しを検証する対象となるドキュメントと同じものです。

### Output

<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 エポックからの秒数です。`double` である理由は `start_time` と同じです。

  形式: `double`
</ResponseField>

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

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

  形式: `uri`
</ResponseField>

<ResponseField name="result.seed" type="integer">
  生成で使用されたシード（指定されたものか、プロバイダーが選択したものかを問いません）。`int64` として宣言されています。BFL は 2^31 を超えるシード（例: 2784347701）を返すことがあり、フォーマットされていない `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>
