将 Starfish 与 Comfy Router 配合使用
通过 Comfy Router 调用 heygen/starfish:端点、请求形状以及 Router 返回的响应。
将 Starfish 与 Comfy Router 配合使用
通过 Comfy Router 调用 heygen/starfish:端点、请求形状以及 Router 返回的响应。
heygen/starfish 的 API 参考,由 Comfy Router 提供,模型来自 HeyGen。
输入: 文本 · 输出: 音频
快速开始
在你的 Comfy 工作区中创建一个密钥,并将其导出为 COMFY_API_KEY。Python 和 TypeScript 代码片段使用 Comfy SDK(pip install comfy-sdk 和 npm install @comfyorg/sdk);cURL 代码片段是通过原始 HTTP 发起的相同调用。
模型 ID: heygen/starfish
端点: POST https://api.comfy.org/v2/models/heygen/starfish
[tab] 等待结果 ``python Python theme={null} from comfy_sdk import Comfy # 从环境变量中读取 COMFY_API_KEY。 # SDK 会自动创建幂等键,并在自动重试时复用它。 with Comfy() as client: result = client.models.run( "heygen/starfish", { "text": "Hello from Comfy. This voice is generated with the HeyGen Starfish engine.", "voice_id": "d2f4f24783d04e22ab49ee8fdc3715e0", }, ) print(result)``typescript TypeScript theme={null} import { comfy } from "@comfyorg/sdk"; // 从环境变量中读取 COMFY_API_KEY。 // SDK 会自动创建幂等键,并在自动重试时复用它。 const { data } = await comfy.models.run("heygen/starfish", { text: "Hello from Comfy. This voice is generated with the HeyGen Starfish engine.", voice_id: "d2f4f24783d04e22ab49ee8fdc3715e0", }); console.log(data);``bash cURL theme={null} curl https://api.comfy.org/v2/models/heygen/starfish \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"text\": \"Hello from Comfy. This voice is generated with the HeyGen Starfish engine.\", \"voice_id\": \"d2f4f24783d04e22ab49ee8fdc3715e0\"}"``
[tab] 入队并稍后收集 同一个请求体,发送到POST https://api.comfy.org/v2/models/heygen/starfish/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( "heygen/starfish", { "text": "Hello from Comfy. This voice is generated with the HeyGen Starfish engine.", "voice_id": "d2f4f24783d04e22ab49ee8fdc3715e0", }, ) 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("heygen/starfish", { text: "Hello from Comfy. This voice is generated with the HeyGen Starfish engine.", voice_id: "d2f4f24783d04e22ab49ee8fdc3715e0", }); 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(); 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/heygen/starfish/requests \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"text\": \"Hello from Comfy. This voice is generated with the HeyGen Starfish engine.\", \"voice_id\": \"d2f4f24783d04e22ab49ee8fdc3715e0\"}" # 2. 轮询直到状态为 COMPLETED,每次响应都会给出需等待的 Retry-After 秒数。 REQUEST_ID="<request_id from the 201 body>" curl -i https://api.comfy.org/v2/models/heygen/starfish/requests/$REQUEST_ID/status \ -H "X-API-Key: $COMFY_API_KEY" # 3. 收集。返回 200 及模型的原生输出;若仍在运行,则返回 202 及状态响应体。 curl https://api.comfy.org/v2/models/heygen/starfish/requests/$REQUEST_ID \ -H "X-API-Key: $COMFY_API_KEY"``
Schema
输入
input\_type string
输入的类型:纯文本使用 'text',SSML 标记使用 'ssml'。默认为 'text'
language string
基础语言代码(例如 'en')。省略时会从文本中自动检测
locale string
BCP-47 区域设置标签(例如 'en-US')。设置后,语言将根据区域设置推断
speed number
速度倍数(0.5-2.0)
范围:0.5 到 2
格式:double
text string required
要合成的文本(1-5000 个字符)
voice\_id string required
要使用的语音 ID。该语音必须支持 starfish 引擎
本内容根据 Router 在 GET /v2/models/heygen/starfish/openapi.json 提供的 schema 生成,该文档也是请求到达提供商之前 Router 用来校验调用的同一份文档。
输出
data object required
成功的 HeyGen 文本转语音响应的载荷
data.audio\_url string required
已生成音频文件的 URL
data.duration number
音频的时长,单位为秒
格式:double
data.request\_id string
此生成请求的唯一标识符
data.word\_timestamps object[]
词级时间数据
data.word\_timestamps\[].end number
结束时间,单位为秒
格式:double
data.word\_timestamps\[].start number
开始时间,单位为秒
格式:double
data.word\_timestamps\[].word string
该单词
示例
输入
{
"text": "Hello from Comfy. This voice is generated with the HeyGen Starfish engine.",
"voice_id": "d2f4f24783d04e22ab49ee8fdc3715e0"
}
输出
{
"data": {
"audio_url": "https://example.invalid/heygen/starfish/speech.mp3",
"duration": 12.5,
"request_id": "018f2c7a-4b1e-7c3d-9a05-6e2f8b41d0c9"
}
}
发布前须知
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 目前不支持的功能,以及替代方案。