> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-chore-sync-comfy-api-v2-spec.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 Flux 1.1 Pro Ultra Image 与 Comfy Router

> 通过 Comfy Router 以 HTTP 调用 FLUX 1.1 [pro] Ultra 和 FLUX 1.1 [pro] 的 Python、TypeScript 与 cURL 代码片段，以及请求字段和结果形状

Flux 1.1 Pro Ultra Image 的 API 参考。FLUX 1.1 \[pro] 是 Black Forest Labs 推出的文生图模型。Ultra 模式可生成最高 4MP 分辨率的图像。

## 快速开始

在[你的 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 发起同样的调用。

选择你要调用的模型。以下所有内容，从代码片段到 schema 和示例，都会随你的选择而变化。

<Tabs>
  <Tab title="FLUX 1.1 [pro] Ultra">
    **模型 ID：** `bfl/flux-pro-1.1-ultra`

    **端点：** `POST https://api.comfy.org/v2/models/bfl/flux-pro-1.1-ultra`

    <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-pro-1.1-ultra",
                  {
                      "prompt": "a single red maple leaf on a plain white background, studio lighting",
                      "aspect_ratio": "16:9",
                      "raw": False,
                  },
              )

          print("image:", result["result"]["sample"])
          ```

          ```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.
          type Result = { result: { sample: string } };
          const { data } = await comfy.models.run<Result>("bfl/flux-pro-1.1-ultra", {
            prompt: "a single red maple leaf on a plain white background, studio lighting",
            aspect_ratio: "16:9",
            raw: false,
          });

          console.log("image:", data.result.sample);
          ```

          ```bash cURL theme={null}
          curl https://api.comfy.org/v2/models/bfl/flux-pro-1.1-ultra \
            -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, studio lighting\", \"aspect_ratio\": \"16:9\", \"raw\": false}"
          ```
        </CodeGroup>
      </Tab>

      <Tab title="Queue and collect later">
        将相同的请求体发送到 `POST https://api.comfy.org/v2/models/bfl/flux-pro-1.1-ultra/requests`。运行被受理后，Router 会立即返回 `201` 和 `request_id`；结果就绪后，可以从本进程或其他进程收集。状态、取消与收集的细节见 [Queued delivery](/zh/development/comfy-router/queue)。

        <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-pro-1.1-ultra",
                  {
                      "prompt": "a single red maple leaf on a plain white background, studio lighting",
                      "aspect_ratio": "16:9",
                      "raw": False,
                  },
              )
              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("image:", result["result"]["sample"])
          ```

          ```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.
          type Result = { result: { sample: string } };
          const handle = await comfy.models.submit<Result>("bfl/flux-pro-1.1-ultra", {
            prompt: "a single red maple leaf on a plain white background, studio lighting",
            aspect_ratio: "16:9",
            raw: false,
          });
          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();
          if (result.kind !== "json") throw new Error("expected a JSON result");

          console.log("image:", result.data.result.sample);
          ```

          ```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-pro-1.1-ultra/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, studio lighting\", \"aspect_ratio\": \"16:9\", \"raw\": false}"

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

    <h2>Schema</h2>

    <h3>输入</h3>

    <ParamField body="aspect_ratio" type="string" default="&#x22;16:9&#x22;">
      图像的比例，介于 21:9 和 9:21 之间，例如 16:9。
    </ParamField>

    <ParamField body="image_prompt" type="string">
      可选的 base64 编码图像，用于混合生成。
    </ParamField>

    <ParamField body="image_prompt_strength" type="number" default="0.1">
      提示词与图像提示词之间的混合程度，从 0（仅使用提示词）到 1（仅使用图像提示词）。

      范围：`0` 到 `1`
    </ParamField>

    <ParamField body="output_format" type="string" default="&#x22;jpeg&#x22;">
      输出图像格式。

      可选值：`jpeg`、`png`、`webp`
    </ParamField>

    <ParamField body="prompt" type="string" required>
      用于图像生成的文本提示词。
    </ParamField>

    <ParamField body="prompt_upsampling" type="boolean" default="false">
      是否对提示词进行上采样。启用后，提示词会被自动修改，以进行更具创造性的生成。
    </ParamField>

    <ParamField body="raw" type="boolean" default="false">
      生成处理更少、看起来更自然的图像。
    </ParamField>

    <ParamField body="safety_tolerance" type="integer" default="2">
      输入和输出审核的阈值，介于 0（最严格）和 6（最宽松）之间。

      范围：`0` 到 `6`
    </ParamField>

    <ParamField body="seed" type="integer">
      可选种子，用于保证可复现性。省略时使用随机种子。
    </ParamField>

    <ParamField body="webhook_secret" type="string">
      可选密钥，用于 Webhook 签名验证。
    </ParamField>

    <ParamField body="webhook_url" type="string (uri)">
      接收 Webhook 通知的 URL。

      格式：`uri`
    </ParamField>

    根据 Router 在 `GET /v2/models/bfl/flux-pro-1.1-ultra/openapi.json` 提供的 schema 生成，Router 在请求到达提供商之前会依据同一份文档校验调用。

    <h3>输出</h3>

    <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>
      已完成的生成结果。此处不可为空：该组件的 `required` 条目意味着 `200` 响应一定携带结果，而可空的 `result` 会将其降级为仅检查键是否存在。
    </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 存储并改写此字段，因此它通常是有效的 Comfy 托管 URL，有效期最长 24 小时。签发时签名为 24 小时，并从 23 小时的备忘中重放，因此稍后轮询可能返回仅剩一小时有效期的链接；如果某个叶子节点无法完成重新托管，则保留 BFL 自己的短期交付 URL，视频大约两小时，图像大约十分钟。无论哪种情况，链接都会过期，因此请下载资源，而不是保存 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 纪元起的秒数。使用 `double` 而非 `float`：在当前纪元数值附近，float32 的间隔约为 128 秒，这会把整次生成的时间跨度压缩为单个解码值。

      格式：`double`
    </ResponseField>

    <ResponseField name="status" type="string" required>
      任务状态：Pending、Reasoning、Generating、Ready、Request Moderated、Content Moderated、Error 或 Task not found。
    </ResponseField>

    <h2>示例</h2>

    <h3>输入</h3>

    ```json theme={null}
    {
      "prompt": "a single red maple leaf on a plain white background, studio lighting",
      "aspect_ratio": "16:9",
      "raw": false
    }
    ```

    <h3>输出</h3>

    ```json theme={null}
    {
      "id": "0a1b2c3d-...",
      "status": "Ready",
      "result": {
        "sample": "https://.../out.jpeg",
        "prompt": "a single red maple leaf on a plain white background, studio lighting",
        "seed": 1234567890
      }
    }
    ```

    该 URL 是临时的。如果你需要保留图像，请及时下载。
  </Tab>

  <Tab title="FLUX 1.1 [pro]">
    **模型 ID：** `bfl/flux-pro-1.1`

    **端点：** `POST https://api.comfy.org/v2/models/bfl/flux-pro-1.1`

    <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-pro-1.1",
                  {
                      "prompt": "a single red maple leaf on a plain white background, studio lighting",
                      "width": 1024,
                      "height": 768,
                  },
              )

          print("image:", result["result"]["sample"])
          ```

          ```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.
          type Result = { result: { sample: string } };
          const { data } = await comfy.models.run<Result>("bfl/flux-pro-1.1", {
            prompt: "a single red maple leaf on a plain white background, studio lighting",
            width: 1024,
            height: 768,
          });

          console.log("image:", data.result.sample);
          ```

          ```bash cURL theme={null}
          curl https://api.comfy.org/v2/models/bfl/flux-pro-1.1 \
            -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, studio lighting\", \"width\": 1024, \"height\": 768}"
          ```
        </CodeGroup>
      </Tab>

      <Tab title="Queue and collect later">
        将相同的请求体发送到 `POST https://api.comfy.org/v2/models/bfl/flux-pro-1.1/requests`。运行被受理后，Router 会立即返回 `201` 和 `request_id`；结果就绪后，可以从本进程或其他进程收集。状态、取消与收集的细节见 [Queued delivery](/zh/development/comfy-router/queue)。

        <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-pro-1.1",
                  {
                      "prompt": "a single red maple leaf on a plain white background, studio lighting",
                      "width": 1024,
                      "height": 768,
                  },
              )
              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("image:", result["result"]["sample"])
          ```

          ```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.
          type Result = { result: { sample: string } };
          const handle = await comfy.models.submit<Result>("bfl/flux-pro-1.1", {
            prompt: "a single red maple leaf on a plain white background, studio lighting",
            width: 1024,
            height: 768,
          });
          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();
          if (result.kind !== "json") throw new Error("expected a JSON result");

          console.log("image:", result.data.result.sample);
          ```

          ```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-pro-1.1/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, studio lighting\", \"width\": 1024, \"height\": 768}"

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

    <h2>Schema</h2>

    <h3>输入</h3>

    <ParamField body="height" type="integer" default="768">
      已生成图像的高度，单位为像素。必须是 32 的倍数。

      范围：`256` 到 `1440`
    </ParamField>

    <ParamField body="image_prompt" type="string">
      可选的 base64 编码图像，用于配合 FLUX Redux 使用。
    </ParamField>

    <ParamField body="output_format" type="string" default="&#x22;jpeg&#x22;">
      输出图像格式。

      可选值：`jpeg`、`png`、`webp`
    </ParamField>

    <ParamField body="prompt" type="string" required>
      用于图像生成的文本提示词。
    </ParamField>

    <ParamField body="prompt_upsampling" type="boolean" default="false">
      是否对提示词进行上采样。启用后，提示词会被自动修改，以进行更具创造性的生成。
    </ParamField>

    <ParamField body="safety_tolerance" type="integer" default="2">
      输入和输出审核的阈值，介于 0（最严格）和 6（最宽松）之间。

      范围：`0` 到 `6`
    </ParamField>

    <ParamField body="seed" type="integer">
      可选种子，用于保证可复现性。省略时使用随机种子。
    </ParamField>

    <ParamField body="webhook_secret" type="string">
      可选密钥，用于 Webhook 签名验证。
    </ParamField>

    <ParamField body="webhook_url" type="string (uri)">
      接收 Webhook 通知的 URL。

      格式：`uri`
    </ParamField>

    <ParamField body="width" type="integer" default="1024">
      已生成图像的宽度，单位为像素。必须是 32 的倍数。

      范围：`256` 到 `1440`
    </ParamField>

    根据 Router 在 `GET /v2/models/bfl/flux-pro-1.1/openapi.json` 提供的 schema 生成，Router 在请求到达提供商之前会依据同一份文档校验调用。

    <h3>输出</h3>

    <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>
      已完成的生成结果。此处不可为空：该组件的 `required` 条目意味着 `200` 响应一定携带结果，而可空的 `result` 会将其降级为仅检查键是否存在。
    </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 存储并改写此字段，因此它通常是有效的 Comfy 托管 URL，有效期最长 24 小时。签发时签名为 24 小时，并从 23 小时的备忘中重放，因此稍后轮询可能返回仅剩一小时有效期的链接；如果某个叶子节点无法完成重新托管，则保留 BFL 自己的短期交付 URL，视频大约两小时，图像大约十分钟。无论哪种情况，链接都会过期，因此请下载资源，而不是保存 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 纪元起的秒数。使用 `double` 而非 `float`：在当前纪元数值附近，float32 的间隔约为 128 秒，这会把整次生成的时间跨度压缩为单个解码值。

      格式：`double`
    </ResponseField>

    <ResponseField name="status" type="string" required>
      任务状态：Pending、Reasoning、Generating、Ready、Request Moderated、Content Moderated、Error 或 Task not found。
    </ResponseField>

    <h2>示例</h2>

    <h3>输入</h3>

    ```json theme={null}
    {
      "prompt": "a single red maple leaf on a plain white background, studio lighting",
      "width": 1024,
      "height": 768
    }
    ```

    <h3>输出</h3>

    ```json theme={null}
    {
      "id": "0a1b2c3d-...",
      "status": "Ready",
      "result": {
        "sample": "https://.../out.jpeg",
        "prompt": "a single red maple leaf on a plain white background, studio lighting",
        "seed": 1234567890
      }
    }
    ```

    该 URL 是临时的。如果你需要保留图像，请及时下载。
  </Tab>
</Tabs>

## 发布前须知

SDK 会生成 `Idempotency-Key` 并在自动重试中复用它。手动重试时，请复用原始 key。Router 最长可保持连接 10 分钟。

请求失败时，Router 会发送 `X-Comfy-Error-Type` 响应头说明原因。`422` 表示 Router 在调用提供商之前就拒绝了输入。生成的资源请及时下载，因为[结果链接会过期](/zh/development/comfy-router/reference#结果资产)。

<CardGroup cols={3}>
  <Card title="请求头" icon="list" href="/zh/development/comfy-router/quickstart">
    身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。
  </Card>

  <Card title="使用 Router API" icon="code" href="/zh/development/comfy-router/quickstart">
    模型发现、校验错误、重试与计费。
  </Card>

  <Card title="限制" icon="triangle-exclamation" href="/zh/development/comfy-router/limitations">
    Router 目前不支持的功能，以及替代方案。
  </Card>
</CardGroup>
