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

# 使用 Comfy Router 调用 FLUX 3 Video

> 通过 Comfy Router 以 HTTP 方式调用 FLUX 3 生成带同步音频的视频，包含 Python、TypeScript 和 cURL 代码片段，以及请求字段和结果结构

FLUX 3 Video 的 API 参考。FLUX 3 Video 是 Black Forest Labs 的视频生成模型，可将文本提示词转换为带有同步音频的短片。

## 快速开始

在[你的 Comfy 工作区](https://platform.comfy.org/profile/api-keys?onboarding=router)中创建密钥，并将其导出为 `COMFY_API_KEY`。Python、TypeScript 和 Swift 片段使用 Comfy SDK（`pip install comfy-sdk`、`npm install @comfyorg/sdk`，以及 [`ComfySwiftSDK`](https://github.com/Comfy-Org/comfy-swift-sdk) Swift 包）；cURL 片段是通过原始 HTTP 发起的同一调用。

**模型 ID：** `bfl/flux-3-video`

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

<Tabs>
  <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-3-video",
              {
                  "mode": "t2v",
                  "prompt": "a single red maple leaf falling onto still water, slow motion",
                  "duration": 5,
                  "aspect_ratio": "16:9",
                  "generate_audio": True,
              },
          )

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

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

      // 从环境变量中读取 COMFY_API_KEY。
      // SDK 会自动创建幂等键，并在自动重试时复用它。
      type Result = { result: { sample: string } };
      const result = await comfy.models.run<Result>("bfl/flux-3-video", {
        mode: "t2v",
        prompt: "a single red maple leaf falling onto still water, slow motion",
        duration: 5,
        aspect_ratio: "16:9",
        generate_audio: true,
      });
      if (result.kind !== "json") throw new Error("expected a JSON result");

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

      ```swift Swift theme={null}
      import Foundation
      import ComfySwiftSDK

      // 从环境变量中读取 COMFY_API_KEY。
      // SDK 会为每次调用生成幂等键，并在自动重试时复用它。
      let client = ComfyCloudClient(apiKey: ProcessInfo.processInfo.environment["COMFY_API_KEY"]!)
      let result = try await client.models.run(
          "bfl/flux-3-video",
          input: [
              "mode": "t2v",
              "prompt": "a single red maple leaf falling onto still water, slow motion",
              "duration": 5,
              "aspect_ratio": "16:9",
              "generate_audio": true,
          ]
      )

      print("video:", result.output["result"]["sample"].stringValue ?? "")
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/bfl/flux-3-video \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"mode\": \"t2v\", \"prompt\": \"a single red maple leaf falling onto still water, slow motion\", \"duration\": 5, \"aspect_ratio\": \"16:9\", \"generate_audio\": true}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="排队并在稍后收集">
    相同的请求体，发送到 `POST https://api.comfy.org/v2/models/bfl/flux-3-video/requests`。只要该次运行被接纳，Router 就会返回 `201` 和 `request_id`，结果就绪后即可从当前进程或另一个进程收集。[队列投递](/zh/development/comfy-router/queue) 会介绍状态、取消和收集。

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

      # 从环境变量中读取 COMFY_API_KEY。
      # 每次调用 submit() 都会生成自己的 Idempotency-Key，并在自动重试时复用它。
      with Comfy() as client:
          handle = client.models.submit(
              "bfl/flux-3-video",
              {
                  "mode": "t2v",
                  "prompt": "a single red maple leaf falling onto still water, slow motion",
                  "duration": 5,
                  "aspect_ratio": "16:9",
                  "generate_audio": True,
              },
          )
          print("request_id:", handle.request_id)  # 配合模型 ID，这就是另一个进程所需的全部信息

          # 轮询直到请求完成，每次等待服务器指定的 Retry-After 时长。
          for update in handle.iter_events():
              print(update.status, update.queue_position)

          # 提供商自己的载荷，与 models.run() 返回的值相同。
          # 失败或已取消的请求会在这里抛出类型化的 Router 错误。
          result = handle.get()

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

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

      // 从环境变量中读取 COMFY_API_KEY。
      // 每次调用 submit() 都会生成自己的 Idempotency-Key，并在自动重试时复用它。
      type Result = { result: { sample: string } };
      const handle = await comfy.models.submit<Result>("bfl/flux-3-video", {
        mode: "t2v",
        prompt: "a single red maple leaf falling onto still water, slow motion",
        duration: 5,
        aspect_ratio: "16:9",
        generate_audio: true,
      });
      console.log("requestId:", handle.requestId); // 配合模型 ID，这就是另一个进程所需的全部信息

      // 轮询直到请求完成，每次等待服务器指定的 Retry-After 时长。
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // 与 models.run() 返回的结果相同。失败或已取消的请求会在这里被拒绝。
      const result = await handle.get();
      if (result.kind !== "json") throw new Error("expected a JSON result");

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

      ```swift Swift theme={null}
      import Foundation
      import ComfySwiftSDK

      // 从环境变量中读取 COMFY_API_KEY。
      // 每次调用 submit() 都会生成自己的 Idempotency-Key，并在自动重试时复用它。
      let client = ComfyCloudClient(apiKey: ProcessInfo.processInfo.environment["COMFY_API_KEY"]!)
      let handle = try await client.models.submit(
          "bfl/flux-3-video",
          input: [
              "mode": "t2v",
              "prompt": "a single red maple leaf falling onto still water, slow motion",
              "duration": 5,
              "aspect_ratio": "16:9",
              "generate_audio": true,
          ]
      )
      print("requestId:", handle.requestId)  // 配合模型 ID，这就是另一个进程所需的全部信息

      // 轮询直到请求完成，每次等待服务器指定的 Retry-After 时长。
      for try await update in handle.events() {
          print(update.state.rawValue, update.queuePosition.map(String.init) ?? "unknown")
      }

      // 提供商自己的载荷，与 models.run() 返回的值相同。
      // 失败或已取消的请求会在这里抛出类型化的 Router 错误。
      let result = try await handle.result()

      print("video:", result.output["result"]["sample"].stringValue ?? "")
      ```

      ```bash cURL theme={null}
      # 1. 提交。Router 返回 201，并带上 request_id、status_url、response_url 和 cancel_url。
      curl https://api.comfy.org/v2/models/bfl/flux-3-video/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"mode\": \"t2v\", \"prompt\": \"a single red maple leaf falling onto still water, slow motion\", \"duration\": 5, \"aspect_ratio\": \"16:9\", \"generate_audio\": true}"

      # 2. 轮询直到状态为 COMPLETED，每次等待响应中指定的 Retry-After 秒数。
      REQUEST_ID="<request_id from the 201 body>"
      curl -i https://api.comfy.org/v2/models/bfl/flux-3-video/requests/$REQUEST_ID/status \
        -H "X-API-Key: $COMFY_API_KEY"

      # 3. 收集。完成时返回 200 和模型的原生输出，仍在运行时返回 202 和状态响应体。
      curl https://api.comfy.org/v2/models/bfl/flux-3-video/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### 输入

<ParamField body="aspect_ratio" type="string" default="&#x22;auto&#x22;">
  输出宽高比：auto、21:9、2:1、16:9、4:3、1:1、3:4 或 9:16。auto 会让 BFL 根据提示词和任何参考素材自行选择。
</ParamField>

<ParamField body="draft" type="boolean" default="false">
  草稿模式：生成一份快速预览，其结果中包含一个 draft\_cache 下载 URL。将该包连同 mode draft\_enhance 一起发回，即可渲染同一次生成的完整质量版本。
</ParamField>

<ParamField body="draft_cache" type="string">
  仅 draft\_enhance 使用。来自先前草稿生成的加密草稿缓存包，形式为 base64 编码的已下载包，或仍然有效的 http(s) URL。原始输入已嵌入该包中。
</ParamField>

<ParamField body="duration" type="integer | string" default="&#x22;auto&#x22;">
  视频时长（秒），可为 5 到 20 之间的任意整数秒，或使用 auto 自动适配内容。

  Range: `5` to `20`
</ParamField>

<ParamField body="generate_audio" type="boolean" default="true">
  在生成视频的同时生成同步音频。
</ParamField>

<ParamField body="keyframes" type="string | number | string[] | string[] | number | string[][]">
  仅 i2v 使用。将成为视频帧的图像，每张为 http(s) URL 或 base64，总共一到十张。接受单张图像、图像列表（一张用于开始视频，两张分别作为起始和结束，更多则均匀分布且需要设定时长），或按时间顺序排列的带时间戳的 \[秒数, 图像] 对，例如 \[\[0, "..."], \[3.5, "..."]]。每个对是包含两个元素的数组：先是秒数，然后是图像。
</ParamField>

<ParamField body="mode" type="string" required>
  生成模式：t2v（文生视频）、i2v（图像续写）、v2v（视频续写）或 draft\_enhance（对先前草稿进行完整质量渲染）。也接受 text-to-video 这类完整拼写的别名。
</ParamField>

<ParamField body="prompt" type="string">
  描述视频的自由格式提示词。除 draft\_enhance 外的所有模式均必填。
</ParamField>

<ParamField body="resolution" type="string">
  视频分辨率级别：hd，或 fhd（由视频放大器完成更高分辨率的结果）。t2v、i2v 和 v2v 默认为 hd，draft\_enhance 默认为 fhd。具体尺寸会随宽高比变化。

  可选值： `hd`, `fhd`
</ParamField>

<ParamField body="safety_tolerance" type="integer" default="2">
  输入与输出有害内容审核的容差级别，0 为最严格。无论请求的容差级别如何，色情内容均限制为级别 3，仇恨内容均限制为级别 2；带条件媒体的请求限制为级别 2。

  Range: `0` to `4`
</ParamField>

<ParamField body="start_video" type="string">
  仅 v2v 使用。要续接的视频，为 http(s) URL 或 base64 MP4；生成的片段将从其最后几帧继续。
</ParamField>

<ParamField body="version" type="string" default="&#x22;latest&#x22;">
  端点版本。latest 提供当前发布版本；带日期的可固定发布标签会在发布时添加。
</ParamField>

本文件生成自 Router 在 `GET /v2/models/bfl/flux-3-video/openapi.json` 提供的 Schema，也就是在请求到达提供商之前 Router 用于校验调用的同一份文档。

### 输出

<ResponseField name="cost" type="number">
  提供商报告的以积分计的成本，在任务变为 Ready 后填充。

  Format: `float`
</ResponseField>

<ResponseField name="id" type="string" required>
  BFL 任务标识符。
</ResponseField>

<ResponseField name="progress" type="number">
  BFL 报告的可选生成进度。

  Range: `0` to `1`

  Format: `float`
</ResponseField>

<ResponseField name="result" type="object" required>
  已完成的生成结果。两个 URL 叶子字段中恰好会填充其中一个：默认模式下为 `sample`，`draft: true` 模式下为 `draft_cache`。
</ResponseField>

<ResponseField name="result.cost" type="number">
  提供商报告的任务成本。这是 BFL 的数值，而不是 Comfy 的收费。

  Format: `double`
</ResponseField>

<ResponseField name="result.draft_cache" type="string (uri)">
  由 `draft: true` 模式返回、用于替代 `sample` 的签名 URL，其重新托管到 Comfy 存储的方式与 `sample` 相同：通常是有效期最长 24 小时的 Comfy 托管 URL；若无法完成重新托管，则为 BFL 自身约两小时有效的交付 URL。

  Format: `uri`
</ResponseField>

<ResponseField name="result.sample" type="string (uri)">
  已生成 MP4 的签名 URL。Router 会把该资源重新托管到 Comfy 存储并重写此字段，因此它通常是有效期最长 24 小时的 Comfy 托管 URL（签发时签名 24 小时，之后从 23 小时的备忘录中重放，所以后续轮询可能返回仅剩一小时有效期的链接）；若某个叶子字段无法完成重新托管，则会保留 BFL 自身约两小时有效的交付 URL。在 `draft: true` 模式下不存在。

  Format: `uri`
</ResponseField>

<ResponseField name="status" type="string" required>
  任务状态：Pending、Reasoning、Generating、Ready、Request Moderated、Content Moderated、Error 或 Task not found。比较时不区分大小写；Router 会原样转发 BFL 的拼写。
</ResponseField>

## 示例

### 输入

```json theme={null}
{
  "mode": "t2v",
  "prompt": "a single red maple leaf falling onto still water, slow motion",
  "duration": 5,
  "aspect_ratio": "16:9",
  "generate_audio": true
}
```

### 输出

```json theme={null}
{
  "id": "0a1b2c3d-...",
  "status": "Ready",
  "result": {
    "sample": "https://.../out.mp4"
  }
}
```

`result.sample` 通常是一个由 Comfy 托管的签名 URL，自创建起最长 24 小时内有效。重放（replay）可能返回一个较早的 URL，而无法重新托管的素材会保留其有效期更短的提供商 URL。请及时下载 MP4，而不要只保存链接。当设置 `draft: true` 时，应读取 `result.draft_cache`，而不是期望获得 `result.sample`。

## 发布前须知

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

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

上文任何字段描述中提到的尺寸限制，都是提供商对该字段自身的限定，引自提供商的规范。Router 会对整个请求体另行设置上限，base64 编码的媒体内容也计入其中：参见[请求体大小](/zh/development/comfy-router/limitations)。

本页记录的是通过 Comfy Router 调用的某一个合作伙伴模型。同一个 `comfy-sdk` / `@comfyorg/sdk` 包还提供第二个客户端，用于在 Comfy Cloud 上运行完整的 ComfyUI 工作流图：`Comfy(api_key=...)` / `new Comfy({ apiKey })`，并带有 `client.workflows`、`client.assets` 和 `client.jobs`。请参阅 [Comfy SDKs](/zh/development/api-development/sdks)。

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

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

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