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

# 将 Video Edit V1 与 Comfy Router 配合使用

> 通过 Comfy Router 调用 bfl/video-edit-v1：端点、请求结构以及 Router 返回的响应。

`bfl/video-edit-v1` 的 API 参考文档，由 Comfy Router 从 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/video-edit-v1`

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

<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/video-edit-v1",
              {
                  "prompt": "Remove the orange bucket.",
                  "video": "https://example.com/clip.mp4",
              },
          )

      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/video-edit-v1", {
        prompt: "Remove the orange bucket.",
        video: "https://example.com/clip.mp4",
      });

      console.log(data);
      ```

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/bfl/video-edit-v1 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"prompt\": \"Remove the orange bucket.\", \"video\": \"https://example.com/clip.mp4\"}"
      ```
    </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/video-edit-v1",
              {
                  "prompt": "Remove the orange bucket.",
                  "video": "https://example.com/clip.mp4",
              },
          )
          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/video-edit-v1", {
        prompt: "Remove the orange bucket.",
        video: "https://example.com/clip.mp4",
      });
      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/video-edit-v1/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"prompt\": \"Remove the orange bucket.\", \"video\": \"https://example.com/clip.mp4\"}"

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

## Schema

### 输入

<ParamField body="prompt" type="string" required>
  编辑指令。指明需要更改的对象、场景、风格、屏幕文字或对话；未指明的内容都会被保留。
</ParamField>

<ParamField body="safety_tolerance" type="integer" default="2">
  输入和输出审核的阈值等级，0 为最严格。

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

<ParamField body="video" type="string" required>
  要编辑的视频，可以是 HTTP(S) URL，也可以是 base64 编码的 MP4。来源素材最长 15 秒、最大 50 MiB，每一边至少 160 像素；高于 720p 的来源会被降采样到 720p。
</ParamField>

本 Schema 由 Router 在 `GET /v2/models/bfl/video-edit-v1/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>
  已完成的生成结果。此处不可为空：该组件的 `required` 条目承诺 `200` 响应必定携带 result，若 `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>

## 示例

### 输入

```json theme={null}
{
  "prompt": "Remove the orange bucket.",
  "video": "https://example.com/clip.mp4"
}
```

### 输出

```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` 并在自动重试中复用它。手动重试时，请复用原始 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>
