配合 Comfy Router 使用 MiniMax H3
通过 Comfy Router 调用 minimax/minimax-h3:端点、请求结构,以及 Router 返回的带原生立体声音频的 MP4。
配合 Comfy Router 使用 MiniMax H3
通过 Comfy Router 调用 minimax/minimax-h3:端点、请求结构,以及 Router 返回的带原生立体声音频的 MP4。
minimax/minimax-h3 的 API 参考文档。MiniMax H3(Hailuo 03)是全模态视频模型,它会在同一次生成中同时输出画面与音轨,因此生成的片段本身就带有对白、音效和音乐。
输入: 文本, 图像 · 输出: 视频 + 音频
快速开始
在你的 Comfy 工作区中创建一个密钥,并将其导出为 COMFY_API_KEY。Python 和 TypeScript 代码片段使用 Comfy SDK(pip install comfy-sdk 和 npm install @comfyorg/sdk);cURL 代码片段是通过原始 HTTP 发出的同一调用。
模型 ID: minimax/minimax-h3
端点: POST https://api.comfy.org/v2/models/minimax/minimax-h3
[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( "minimax/minimax-h3", { "content": [ { "text": "A single red maple leaf resting on a plain white background.", "type": "text", }, ], "duration": 5, "ratio": "16:9", "resolution": "768P", }, ) print("video:", result["task"]["content"]["url"]) asyncio.run(main())``typescript TypeScript theme={null} import { comfy } from "@comfyorg/sdk"; // 从环境中读取 COMFY_API_KEY。 // SDK 会自动创建幂等键,并在自动重试时复用它。 type Result = { task: { content: { url: string } } }; const result = await comfy.models.run<Result>("minimax/minimax-h3", { content: [ { text: "A single red maple leaf resting on a plain white background.", type: "text", }, ], duration: 5, ratio: "16:9", resolution: "768P", }); if (result.kind !== "json") throw new Error("expected a JSON result"); console.log("video:", result.data.task.content.url);``bash cURL theme={null} curl https://api.comfy.org/v2/models/minimax/minimax-h3 \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"content\": [{\"text\":\"A single red maple leaf resting on a plain white background.\",\"type\":\"text\"}], \"duration\": 5, \"ratio\": \"16:9\", \"resolution\": \"768P\"}"``
[tab] 加入队列,稍后收集 将相同的请求体发送到POST https://api.comfy.org/v2/models/minimax/minimax-h3/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( "minimax/minimax-h3", { "content": [ { "text": "A single red maple leaf resting on a plain white background.", "type": "text", }, ], "duration": 5, "ratio": "16:9", "resolution": "768P", }, ) 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["task"]["content"]["url"]) asyncio.run(main())``typescript TypeScript theme={null} import { comfy } from "@comfyorg/sdk"; // 从环境中读取 COMFY_API_KEY。 // 每次 submit() 调用都会生成自己的 Idempotency-Key,并在自动重试时复用它。 type Result = { task: { content: { url: string } } }; const handle = await comfy.models.submit<Result>("minimax/minimax-h3", { content: [ { text: "A single red maple leaf resting on a plain white background.", type: "text", }, ], duration: 5, ratio: "16:9", resolution: "768P", }); 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(); if (result.kind !== "json") throw new Error("expected a JSON result"); console.log("video:", result.data.task.content.url);``bash cURL theme={null} # 1. 提交。Router 返回 201,并附带 request_id、status_url、response_url 和 cancel_url。 curl https://api.comfy.org/v2/models/minimax/minimax-h3/requests \ -H "X-API-Key: $COMFY_API_KEY" \ -H "Idempotency-Key: $(uuidgen)" \ -H "Content-Type: application/json" \ -d "{\"content\": [{\"text\":\"A single red maple leaf resting on a plain white background.\",\"type\":\"text\"}], \"duration\": 5, \"ratio\": \"16:9\", \"resolution\": \"768P\"}" # 2. 轮询直到状态为 COMPLETED,每次等待各响应中给出的 Retry-After 秒数。 REQUEST_ID="<request_id from the 201 body>" curl -i https://api.comfy.org/v2/models/minimax/minimax-h3/requests/$REQUEST_ID/status \ -H "X-API-Key: $COMFY_API_KEY" # 3. 收集。返回 200 时携带模型的原生输出;仍在运行时会以 202 返回状态正文。 curl https://api.comfy.org/v2/models/minimax/minimax-h3/requests/$REQUEST_ID \ -H "X-API-Key: $COMFY_API_KEY"``
Schema
输入
aigc\_watermark boolean
是否为输出添加 AIGC 水印。默认为 false。
callback\_url string
可选。用于在质询验证之后接收任务状态变更的 URL。
content object[] required
驱动生成的内容项。必须包含一个非空 text 项;可选添加 first\_frame/last\_frame 图像或 reference\_\* 媒体。
content\[].audio\_url object
音频来源。audio\_url 项必填。
content\[].audio\_url.url string
可公开访问的 URL、mm\_file://\{file\_id} 引用或 data URI。
content\[].image\_url object
图像来源。image\_url 项必填。
content\[].image\_url.url string
可公开访问的 URL、mm\_file://\{file\_id} 引用或 data URI。
content\[].role string
媒体项的角色。可选值:first\_frame、last\_frame、reference\_image、reference\_video、reference\_audio、base\_video。关键帧角色与 reference\_\* 角色在同一请求中互斥;base\_video 标记视频重生成请求的来源视频。
content\[].text string
提示词文本。每个请求必须且只能包含一个非空 text 项。
content\[].type string required
内容项类型。可选值:text、image\_url、video\_url、audio\_url。
content\[].video\_url object
视频来源。video\_url 项必填。
content\[].video\_url.url string
可公开访问的 URL、mm\_file://\{file\_id} 引用或 data URI。
duration integer required
视频时长,单位为秒。Comfy Router 接受 4 到 15,超出该范围的值会在调用提供商之前被拒绝。MiniMax 针对该模型的官方文档给出的是 5 到 15;ComfyUI MiniMax H3 节点提供 4 到 15,并且已观察到 4 秒的生成能够成功,因此这里接受 4。
范围:4 到 15
model string
模型 ID。可选值:MiniMax-H3。Router 调用方可以省略此字段或发送 null;Router 会在向提供商分发之前注入由请求路径所选择的模型。
ratio string
比例。可选值:adaptive(默认)、21:9、16:9、4:3、1:1、3:4、9:16。文生视频时必填且不能为 adaptive;首帧或尾帧生成时会忽略该字段(按 adaptive 处理)。
resolution string required
视频分辨率。可选值:2K、768P。该值在分发之前以不区分大小写的方式匹配并规范化,因此 2k 和 768p 会被接受,并以 2K 和 768P 发送。
可能的取值:2K、2k、768P、768p
seed integer
随机种子,取值范围 \[-1, 2^32 - 1];省略或为 -1 时表示随机。
格式:int64
根据 Router 在 GET /v2/models/minimax/minimax-h3/openapi.json 提供的 schema 生成,这与 Router 在请求到达提供商之前用于校验调用的文档是同一份。
输出
task object
一个 Minimax V2 视频生成任务。
task.content object
已生成的输出;当 status 为 succeeded 时存在。
task.content.prompt string
由成功的 h3\_context\_ir 任务产生的增强视频提示词。
task.content.url string
已生成 MP4 的限时 URL。可再次查询以获取刷新后的 URL。
task.duration number
已生成视频的时长,单位为秒。
task.error object
status 为 failed 时的错误详情;包含 code 和 message。
task.id string
任务 ID。
task.model string
该任务使用的模型。
task.ratio string
已生成视频的实际比例。
task.resolution string
已生成视频的分辨率。
task.status string
任务状态。可选值:queued、running、succeeded、failed、cancelled、expired。
task.task\_type string
任务的类型。
task.usage object
为该任务记录的使用量。
task.usage.completion\_tokens integer
task.usage.input\_image\_count integer
task.usage.input\_seconds number
task.usage.output\_seconds number
task.usage.prompt\_tokens integer
task.usage.total\_seconds number
task.usage.total\_tokens integer
示例
输入
{
"content": [
{
"text": "A single red maple leaf resting on a plain white background.",
"type": "text"
}
],
"duration": 5,
"ratio": "16:9",
"resolution": "768P"
}
输出
{
"task": {
"content": {
"url": "https://example.invalid/minimax/minimax-h3/generated.mp4"
},
"duration": 6,
"id": "3f7a1b28-5c0d-4e91-8a6f-1b2c3d4e5f60",
"model": "MiniMax-H3",
"ratio": "16:9",
"resolution": "768P",
"status": "succeeded",
"usage": {
"output_seconds": 6,
"total_seconds": 6
}
}
}
MP4 自带生成的音轨。 H3 是全模态模型:人声、音效和音乐与画面在同一次前向传播中一并合成,而非事后叠加,最终得到的是一个带原生立体声音频的 MP4。上文请求体中的任何内容都无法将其关闭:文档中记录的字段是提示词内容、duration、ratio、resolution、seed、aigc_watermark 和 callback_url,其中没有任何一个会选择静音渲染。因此,打算给片段叠加自己旁白的流水线必须先静音或剥离返回的音轨,否则就会在本就在说话的片段上再混入一层音轨。提示词才是引导音频的关键:在同一个提示词块中描述镜头以及对白、音效和音乐。关于如何组织提示词,请参阅 MiniMax H3 提示词指南;关于该模型在 ComfyUI 中能做什么,请参阅 MiniMax H3 概览。
视频 URL 会过期。Router 会重新托管该 MP4,并返回一个有效期为 12 小时的 Comfy 签名 URL;当重新托管失败时,则回退到 MiniMax 自己有效期更短的链接。上文响应 schema 中 task.content.url 的说明让你再次查询以获取刷新后的 URL:那是 MiniMax 针对自家 API 的措辞,原样沿用,而 Router 并不暴露 MiniMax 的任务查询路由。在请求完成后保留 24 小时期间,重新读取已排队请求的结果路由会返回存储的结果文档,但没有任何文档说明这次读取会签发一个新的签名 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 目前不支持的功能,以及替代方案。