> ## 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 Video Upscale

> 使用 Python、TypeScript 和 cURL 代码片段，通过 Comfy Router 以 HTTP 方式调用 FLUX Video Upscale 对视频进行放大，并说明请求字段与结果结构

FLUX Video Upscale 的 API 参考。FLUX Video Upscale 是 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-upscale-v1`

**端点：** `POST https://api.comfy.org/v2/models/bfl/video-upscale-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-upscale-v1",
              {
                  "input_video": "https://your-host.example/clip.mp4",
                  "upscale_factor": 2,
                  "creativity": 1,
              },
          )

      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/video-upscale-v1", {
        input_video: "https://your-host.example/clip.mp4",
        upscale_factor: 2,
        creativity: 1,
      });

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

      ```bash cURL theme={null}
      curl https://api.comfy.org/v2/models/bfl/video-upscale-v1 \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input_video\": \"https://your-host.example/clip.mp4\", \"upscale_factor\": 2, \"creativity\": 1}"
      ```
    </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-upscale-v1",
              {
                  "input_video": "https://your-host.example/clip.mp4",
                  "upscale_factor": 2,
                  "creativity": 1,
              },
          )
          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/video-upscale-v1", {
        input_video: "https://your-host.example/clip.mp4",
        upscale_factor: 2,
        creativity: 1,
      });
      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/video-upscale-v1/requests \
        -H "X-API-Key: $COMFY_API_KEY" \
        -H "Idempotency-Key: $(uuidgen)" \
        -H "Content-Type: application/json" \
        -d "{\"input_video\": \"https://your-host.example/clip.mp4\", \"upscale_factor\": 2, \"creativity\": 1}"

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

<h2 id="schema">
  Schema
</h2>

### 输入

<ParamField body="creativity" type="integer" default="1">
  0 会精确保留来源内容并对其进行锐化；1 则允许创意性的细节增强，此时不会严格保留人脸或产品。

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

<ParamField body="input_video" type="string" required>
  要放大的视频，可以是 HTTP(S) URL 或 base64 编码的 MP4。来源素材最长 20 秒且不超过 50MB。
</ParamField>

<ParamField body="prompt" type="string">
  可选的片段内容描述，用于引导增强后的细节。留空则进行中性的放大处理。
</ParamField>

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

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

<ParamField body="upscale_factor" type="number" default="2">
  输出相对于来源分辨率的缩放倍数。输出会保留来源的宽高比，并限制在每帧约 14.4 兆像素以内，因此非常大的来源素材放大倍数会小于请求的值。

  范围：`1.5` 到 `3`

  格式：`float`
</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/video-upscale-v1/openapi.json` 提供的 schema 生成，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` 会把它降格为仅检查键是否存在。
</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），而在许多 SDK 生成器中，未指定格式的 `integer` 会生成 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}
{
  "input_video": "https://your-host.example/clip.mp4",
  "upscale_factor": 2,
  "creativity": 1
}
```

### 输出

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

`result.sample` 通常是 Comfy 托管的签名 URL，自创建时起最长 24 小时内有效。重放可能会返回较旧的 URL，而无法重新托管的资产会保留其有效期更短的提供商 URL。请及时下载 MP4，而不要只保存链接。

## 发布前须知

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>
