> ## 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.

# 使用 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)中创建密钥，并将其导出为 `COMFY_API_KEY`。Python 和 TypeScript 片段使用 Comfy SDK（`pip install comfy-sdk`、`npm install @comfyorg/sdk`）；cURL 片段是通过原始 HTTP 发起的同一调用。

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

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

<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-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";

      // 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-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("video:", data.result.sample);
      ```

      ```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="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-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)  # 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("video:", 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-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); // 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("video:", 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-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. 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-3-video/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-3-video/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### Input

<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。具体尺寸会随宽高比变化。

  Possible values: `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 用于校验调用的同一份文档。

### Output

<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 在调用提供商之前就拒绝了输入。生成的资源请及时下载，因为[结果链接会过期](/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>
