将 SwitchX 与 Comfy Router 配合使用
通过 Comfy Router 调用 beeble/switchx:端点、请求结构以及 Router 返回的响应。
将 SwitchX 与 Comfy Router 配合使用
通过 Comfy Router 调用 beeble/switchx:端点、请求结构以及 Router 返回的响应。
beeble/switchx 的 API 参考,由 Comfy Router 提供,来自 Beeble。
输入: 图像, 视频, 文本 · 输出: 图像 + 视频
快速开始
在你的 Comfy 工作区中创建一个密钥,并将其导出为 COMFY_API_KEY。Python 和 TypeScript 代码片段使用 Comfy SDK(pip install comfy-sdk 和 npm install @comfyorg/sdk);cURL 代码片段是通过原始 HTTP 发出的同一调用。
模型 ID: beeble/switchx
端点: POST https://api.comfy.org/v2/models/beeble/switchx
[tab] 等待结果 ``python Python theme={null} from comfy_sdk import Comfy # 从环境变量中读取 COMFY_API_KEY。 # SDK 会自动创建幂等键,并在自动重试时复用它。 with Comfy() as client: result = client.models.run( "beeble/switchx", { "alpha_mode": "auto", "generation_type": "image", "max_resolution": 720, "prompt": "A cinematic product photo of a glass lamp on a marble table", "source_uri": "https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80", }, ) print(result)``typescript TypeScript theme={null} import { comfy } from "@comfyorg/sdk"; // 从环境变量中读取 COMFY_API_KEY。 // SDK 会自动创建幂等键,并在自动重试时复用它。 const { data } = await comfy.models.run("beeble/switchx", { alpha_mode: "auto", generation_type: "image", max_resolution: 720, prompt: "A cinematic product photo of a glass lamp on a marble table", source_uri: "https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80", }); console.log(data);``bash cURL theme={null} curl https://api.comfy.org/v2/models/beeble/switchx \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"alpha_mode\": \"auto\", \"generation_type\": \"image\", \"max_resolution\": 720, \"prompt\": \"A cinematic product photo of a glass lamp on a marble table\", \"source_uri\": \"https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80\"}"``
[tab] 队列并稍后收集 将相同的请求体发送到POST https://api.comfy.org/v2/models/beeble/switchx/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( "beeble/switchx", { "alpha_mode": "auto", "generation_type": "image", "max_resolution": 720, "prompt": "A cinematic product photo of a glass lamp on a marble table", "source_uri": "https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80", }, ) 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(result) asyncio.run(main())``typescript TypeScript theme={null} import { comfy } from "@comfyorg/sdk"; // 从环境变量中读取 COMFY_API_KEY。 // 每次 submit() 调用都会生成自己的 Idempotency-Key,并在自动重试时复用它。 const handle = await comfy.models.submit("beeble/switchx", { alpha_mode: "auto", generation_type: "image", max_resolution: 720, prompt: "A cinematic product photo of a glass lamp on a marble table", source_uri: "https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80", }); console.log("requestId:", handle.requestId); // 配合模型 ID,这就是另一个进程所需的全部信息 // 轮询直到请求完成,按服务器给出的 Retry-After 等待。 for await (const update of handle.events()) { console.log(update.status, update.queuePosition); } // 与 models.run() 返回的结果相同。失败或已取消的请求会在此处 reject。 const result = await handle.get(); console.log(result.data);``bash cURL theme={null} # 1. 提交。Router 返回 201,并附带 request_id、status_url、response_url 和 cancel_url。 curl https://api.comfy.org/v2/models/beeble/switchx/requests \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"alpha_mode\": \"auto\", \"generation_type\": \"image\", \"max_resolution\": 720, \"prompt\": \"A cinematic product photo of a glass lamp on a marble table\", \"source_uri\": \"https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80\"}" # 2. 轮询直到状态为 COMPLETED,按每个响应给出的 Retry-After 秒数等待。 REQUEST_ID="<request_id from the 201 body>" curl -i https://api.comfy.org/v2/models/beeble/switchx/requests/$REQUEST_ID/status \ -H "X-API-Key: $COMFY_API_KEY" # 3. 收集。返回 200 及模型的原生输出;仍在运行时返回 202 及状态响应体。 curl https://api.comfy.org/v2/models/beeble/switchx/requests/$REQUEST_ID \ -H "X-API-Key: $COMFY_API_KEY"``
Schema
输入
alpha\_mode string required
透明度模式:自动、填充、自定义或选择
可选值:auto、fill、custom、select
alpha\_uri string
自定义透明度蒙版的 URI。当 alpha\_mode 为 custom 或 select 时必填。在 auto 或 fill 模式下会被忽略。
callback\_url string
用于在任务完成或失败时接收 webhook 通知的 HTTPS URL。
generation\_type string required
输出类型:图像或视频
可选值:image、video
idempotency\_key string
用于安全重试的幂等键。如果你的账号下已存在使用相同键的任务,API 会返回现有任务的状态,而不会创建重复任务。
max\_resolution integer (default: 1080)
最大输出分辨率:720 或 1080(默认值:1080)。
prompt string
期望输出的文本描述(最多 2,000 个字符)。prompt 与 reference\_image\_uri 至少需要提供一个。
reference\_image\_uri string
用于风格迁移的参考图像 URI。接受的 URI 类型与 source\_uri 相同。
source\_uri string required
来源图像或视频的 URI。接受 beeble://uploads/\{id}/\{filename}、https URL 或 data:\{mime};base64 URI(最大 50 MB)。
本文档由 Router 在 GET /v2/models/beeble/switchx/openapi.json 提供的 schema 生成,Router 在请求到达提供商之前,正是用这份文档来校验调用。
输出
alpha\_mode string
自动、填充、自定义或选择
completed\_at string
任务完成或失败时的 ISO 8601 时间戳。
created\_at string
任务创建时的 ISO 8601 时间戳。
error string
报错信息(status 为 failed 时存在)。
generation\_type string
图像或视频
id string required
任务标识符(swx\_...)
modified\_at string
最后一次状态变更的 ISO 8601 时间戳。
output object
SwitchX 任务输出的签名 URL。
output.alpha string
透明度蒙版 URL。
output.render string
合成后的输出 URL。
output.source string
预处理后的来源 URL。
progress integer
进度百分比(0-100)。
status string required
当前任务状态。
可选值:in_queue、processing、completed、failed
webhook object
SwitchX 任务的 webhook 投递状态。
webhook.attempts integer
到目前为止的投递尝试次数。
webhook.last\_error string
最后一次失败投递尝试的报错信息。
webhook.status string
pending、delivered 或 failed
示例
输入
{
"alpha_mode": "auto",
"generation_type": "image",
"max_resolution": 720,
"prompt": "A cinematic product photo of a glass lamp on a marble table",
"source_uri": "https://img.freepik.com/free-photo/portrait-woman_395237-33.jpg?w=740&q=80"
}
输出
{
"alpha_mode": "auto",
"completed_at": "2027-01-01T00:01:04Z",
"created_at": "2027-01-01T00:00:00Z",
"generation_type": "image",
"id": "swx_1a2b3c4d5e6f7a8b",
"modified_at": "2027-01-01T00:01:04Z",
"output": {
"alpha": "https://example.invalid/beeble/switchx/alpha.png",
"render": "https://example.invalid/beeble/switchx/render.png",
"source": "https://example.invalid/beeble/switchx/source.png"
},
"progress": 100,
"status": "completed"
}
发布前须知
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 目前不支持的功能,以及替代方案。