通过 Comfy Router 使用 FLUX Video Upscale
使用 Python、TypeScript 和 cURL 代码片段,通过 Comfy Router 以 HTTP 方式调用 FLUX Video Upscale 对视频进行放大,并说明请求字段与结果结构
通过 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 工作区中创建一个密钥,并将其导出为 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
[tab] 等待结果 ``python Python theme={null} import asyncio from comfy_sdk import AsyncComfy # 从环境变量中读取 COMFY_API_KEY。 # SDK 会自动创建幂等键,并在自动重试时复用它。 async def main(): async with AsyncComfy() as client: result = await 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"]) asyncio.run(main())``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/video-upscale-v1", { input_video: "https://your-host.example/clip.mp4", upscale_factor: 2, creativity: 1, }); if (result.kind !== "json") throw new Error("expected a JSON result"); console.log("video:", result.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}"``
[tab] 排队并稍后收集 相同的请求体,发送到POST https://api.comfy.org/v2/models/bfl/video-upscale-v1/requests。运行一旦被受理,Router 就会立即返回201以及一个request_id,结果就绪后即可收集,无论是从当前进程还是另一个进程。队列投递介绍了状态查询、取消和结果收集的完整流程。 ``python Python theme={null} import asyncio from comfy_sdk import AsyncComfy # 从环境变量中读取 COMFY_API_KEY。 # 每次 submit() 调用都会生成自己的 Idempotency-Key,并在自动重试时复用它。 async def main(): async with AsyncComfy() as client: handle = await 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) # 配合模型 ID,就是另一个进程所需的全部信息 # 轮询直到请求完成,等待服务器指定的 Retry-After 时间。 async for update in handle.iter_events(): print(update.status, update.queue_position) # 提供商自身的载荷,与 models.run() 返回的值相同。 # 失败或已取消的请求会在此抛出类型化的 Router 错误。 result = await handle.get() print("video:", result["result"]["sample"]) asyncio.run(main())``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/video-upscale-v1", { input_video: "https://your-host.example/clip.mp4", upscale_factor: 2, creativity: 1, }); 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);``bash cURL theme={null} # 1. 提交。Router 返回 201,以及 request_id、status_url、response_url 和 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. 轮询直到状态为 COMPLETED,每个响应都会指明需要等待的 Retry-After 秒数。 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. 收集。返回 200 时携带模型的原始输出;仍在运行时则返回 202 及状态响应体。 curl https://api.comfy.org/v2/models/bfl/video-upscale-v1/requests/$REQUEST_ID \ -H "X-API-Key: $COMFY_API_KEY"``
Schema
输入
creativity integer (default: 1)
0 会精确保留来源内容并对其进行锐化;1 则允许创意性的细节增强,此时不会严格保留人脸或产品。
范围:0 到 1
input\_video string required
要放大的视频,可以是 HTTP(S) URL 或 base64 编码的 MP4。来源素材最长 20 秒、不超过 50MB,且每帧不超过 2560x1440(3.7 兆像素);来源更大时,请先缩小再提交。
prompt string
可选的片段内容描述,用于引导增强后的细节。留空则进行中性的放大处理。
safety\_tolerance integer (default: 2)
提示词和输出帧内容审核的阈值等级,0 为最严格。
范围:0 到 4
upscale\_factor number (default: 2)
输出相对于来源分辨率的缩放倍数。输出会保留来源的宽高比,并限制在每帧约 14.4 兆像素以内,因此非常大的来源素材放大倍数会小于请求的值。没有分辨率选项;若要以 2K(2560x1440)或 4K(3840x2160)为目标,请用目标高度除以来源高度。720p 的来源在 2 时达到 2K,在 3 时达到 4K;1080p 的来源在 2 时达到 4K,但无法达到 2K,需要 1.33。
范围:1.5 到 3
格式:float
webhook\_secret string
用于 webhook 签名验证的可选密钥。
webhook\_url string (uri)
用于接收 webhook 通知的 URL。
格式:uri
本文档由 Router 在 GET /v2/models/bfl/video-upscale-v1/openapi.json 提供的 schema 生成,Router 在请求到达提供商之前,正是依据同一份文档来校验调用。
输出
cost number
提供商报告的费用,以积分计,任务进入 Ready 状态后填充。
格式:float
id string required
BFL 任务标识符。
progress number
BFL 报告的生成进度(可选)。
范围:0 到 1
格式:float
result object required
已完成的生成结果。此处不可为空:该组件的 required 条目承诺 200 响应必定携带结果,而可空的 result 会把它降格为仅检查键是否存在。
result.cost number
提供商报告的本次生成费用。这是 BFL 的数字,不是 Comfy 的计费。
格式:double
result.duration number
提供商报告的生成时长,单位为秒。
格式:double
result.end\_time number
提供商报告的生成完成时间,为自 Unix 纪元起的秒数。与 start_time 同样使用 double。
格式:double
result.prompt string
生成实际采用的提示词,即经过提示词上采样之后的结果。
result.sample string (uri)
生成资源的签名 URL。Router 会把该资源重新托管到 Comfy 存储并重写此字段,因此它通常是 Comfy 托管的 URL,有效期最长 24 小时:签发时按 24 小时签名,并从 23 小时的缓存中重放,所以稍后轮询拿到的链接可能只剩一小时有效期;若某个叶子节点无法执行重新托管,则保留 BFL 自己的短时效分发 URL,视频约为两小时,图像约为十分钟。无论哪种情况链接都会过期,因此请下载资源,而不要保存 URL。
格式:uri
result.seed integer
本次生成使用的种子,无论是传入的还是提供商选定的。声明为 int64 是因为 BFL 会返回大于 2^31 的种子(例如 2784347701),而在许多 SDK 生成器中,未指定格式的 integer 会生成 32 位字段。
格式:int64
result.start\_time number
提供商报告的生成开始时间,为自 Unix 纪元起的秒数。使用 double 而非 float:在当前纪元值附近,float32 的间隔约为 128 秒,会把整次生成的时间跨度压缩成一个解码值。
格式:double
status string required
任务状态:Pending、Reasoning、Generating、Ready、Request Moderated、Content Moderated、Error 或 Task not found。
示例
输入
{
"input_video": "https://your-host.example/clip.mp4",
"upscale_factor": 2,
"creativity": 1
}
输出
{
"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 在调用提供商之前就拒绝了输入,413 表示请求体超出了 Router 可接受的大小。已生成的资源请及时下载,因为结果 URL 会过期。
上文任何字段描述中提到的尺寸限制,都是提供商对该字段自身的限定,引自提供商的规范。Router 会对整个请求体另行设置上限,base64 编码的媒体内容也计入其中:参见请求体大小。
本页记录的是通过 Comfy Router 调用的某一个合作伙伴模型。同一个 comfy-sdk / @comfyorg/sdk 包还提供第二个客户端,用于在 Comfy Cloud 上运行完整的 ComfyUI 工作流图:Comfy(api_key=...) / new Comfy({ apiKey }),并带有 client.workflows、client.assets 和 client.jobs。请参阅 Comfy SDKs。
[card] 请求头 身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。
[card] 使用 Router API 模型发现、验证错误、重试与计费。
[card] 限制 Router 目前不支持的功能,以及替代方案。