> ## Documentation Index
> Fetch the complete documentation index at: https://comfyuiwiki.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 配合 Comfy Router 使用 MiniMax H3

> 通过 Comfy Router 调用 minimax/minimax-h3：端点、请求结构以及 Router 返回的响应。

`minimax/minimax-h3` 的 API 参考文档。MiniMax H3（Hailuo 03）是全模态视频模型，它会在同一次生成中同时输出画面与音轨，因此生成的片段本身就带有对白、音效和音乐。

## 快速开始

在[你的 Comfy 工作区](https://platform.comfy.org/profile/api-keys?onboarding=router)中创建一个密钥，并将其导出为 `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`

<Tabs defaultTabIndex={1}>
  <Tab title="等待结果">
    <CodeGroup>
      ```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\"}"
      ```
    </CodeGroup>
  </Tab>

  <Tab title="加入队列，稍后收集">
    将相同的请求体发送到 `POST https://api.comfy.org/v2/models/minimax/minimax-h3/requests`。运行被受理后，Router 会立即返回 `201` 和 `request_id`；结果就绪后，可以从本进程或其他进程收集。[队列投递](/zh/development/comfy-router/queue)介绍了状态、取消与收集。

    <CodeGroup>
      ```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"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Schema

### 输入

<ParamField body="aigc_watermark" type="boolean">
  是否为输出添加 AIGC 水印。默认为 false。
</ParamField>

<ParamField body="callback_url" type="string">
  可选。用于在质询验证之后接收任务状态变更的 URL。
</ParamField>

<ParamField body="content" type="object[]" required>
  驱动生成的内容项。必须包含一个非空 text 项；可选添加 first\_frame/last\_frame 图像或 reference\_\* 媒体。
</ParamField>

<ParamField body="content[].audio_url" type="object">
  音频来源。audio\_url 项必填。
</ParamField>

<ParamField body="content[].audio_url.url" type="string">
  可公开访问的 URL、mm\_file://\{file\_id} 引用或 data URI。
</ParamField>

<ParamField body="content[].image_url" type="object">
  图像来源。image\_url 项必填。
</ParamField>

<ParamField body="content[].image_url.url" type="string">
  可公开访问的 URL、mm\_file://\{file\_id} 引用或 data URI。
</ParamField>

<ParamField body="content[].role" type="string">
  媒体项的角色。可选值：first\_frame、last\_frame、reference\_image、reference\_video、reference\_audio、base\_video。关键帧角色与 reference\_\* 角色在同一请求中互斥；base\_video 标记视频重生成请求的来源视频。
</ParamField>

<ParamField body="content[].text" type="string">
  提示词文本。每个请求必须且只能包含一个非空 text 项。
</ParamField>

<ParamField body="content[].type" type="string" required>
  内容项类型。可选值：text、image\_url、video\_url、audio\_url。
</ParamField>

<ParamField body="content[].video_url" type="object">
  视频来源。video\_url 项必填。
</ParamField>

<ParamField body="content[].video_url.url" type="string">
  可公开访问的 URL、mm\_file://\{file\_id} 引用或 data URI。
</ParamField>

<ParamField body="duration" type="integer" required>
  视频时长，单位为秒，5 到 15。
</ParamField>

<ParamField body="model" type="string">
  模型 ID。可选值：MiniMax-H3。Router 调用方可以省略此字段或发送 null；Router 会在向提供商分发之前注入由请求路径所选择的模型。
</ParamField>

<ParamField body="ratio" type="string">
  比例。可选值：adaptive（默认）、21:9、16:9、4:3、1:1、3:4、9:16。文生视频时必填且不能为 adaptive；首帧或尾帧生成时会忽略该字段（按 adaptive 处理）。
</ParamField>

<ParamField body="resolution" type="string" required>
  视频分辨率。可选值：2K、768P。
</ParamField>

<ParamField body="seed" type="integer">
  随机种子，取值范围 \[-1, 2^32 - 1]；省略或为 -1 时表示随机。

  格式：`int64`
</ParamField>

根据 Router 在 `GET /v2/models/minimax/minimax-h3/openapi.json` 提供的 schema 生成，这与 Router 在请求到达提供商之前用于校验调用的文档是同一份。

### 输出

<ResponseField name="task" type="object">
  一个 Minimax V2 视频生成任务。
</ResponseField>

<ResponseField name="task.content" type="object">
  已生成的输出；当 status 为已成功时存在。
</ResponseField>

<ResponseField name="task.content.prompt" type="string">
  由成功的 h3\_context\_ir 任务产生的增强视频提示词。
</ResponseField>

<ResponseField name="task.content.url" type="string">
  已生成 MP4 的限时 URL。可再次查询以获取刷新后的 URL。
</ResponseField>

<ResponseField name="task.duration" type="number">
  已生成视频的时长，单位为秒。
</ResponseField>

<ResponseField name="task.error" type="object">
  status 为失败时的错误详情；包含 code 和 message。
</ResponseField>

<ResponseField name="task.id" type="string">
  任务 ID。
</ResponseField>

<ResponseField name="task.model" type="string">
  该任务使用的模型。
</ResponseField>

<ResponseField name="task.ratio" type="string">
  已生成视频的实际比例。
</ResponseField>

<ResponseField name="task.resolution" type="string">
  已生成视频的分辨率。
</ResponseField>

<ResponseField name="task.status" type="string">
  任务状态。可选值：已执行、运行中、已成功、失败、已取消、已过期。
</ResponseField>

<ResponseField name="task.task_type" type="string">
  任务的类型。
</ResponseField>

<ResponseField name="task.usage" type="object">
  为该任务记录的使用量。
</ResponseField>

<ResponseField name="task.usage.completion_tokens" type="integer" />

<ResponseField name="task.usage.input_image_count" type="integer" />

<ResponseField name="task.usage.input_seconds" type="number" />

<ResponseField name="task.usage.output_seconds" type="number" />

<ResponseField name="task.usage.prompt_tokens" type="integer" />

<ResponseField name="task.usage.total_seconds" type="number" />

<ResponseField name="task.usage.total_tokens" type="integer" />

## 示例

### 输入

```json theme={null}
{
  "content": [
    {
      "text": "A single red maple leaf resting on a plain white background.",
      "type": "text"
    }
  ],
  "duration": 5,
  "ratio": "16:9",
  "resolution": "768P"
}
```

### 输出

```json theme={null}
{
  "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 提示词指南](/zh/tutorials/video/minimax/minimax-h3-prompt-guide)；关于该模型在 ComfyUI 中能做什么，请参阅 [MiniMax H3 概览](/zh/tutorials/video/minimax/minimax-h3)。

视频 URL 会过期。Router 会重新托管该 MP4，并返回一个有效期为 12 小时的 Comfy 签名 URL；当重新托管失败时，则回退到 MiniMax 自己有效期更短的链接。上文响应 schema 中 `task.content.url` 的说明让你再次查询以获取刷新后的 URL：那是 MiniMax 针对自家 API 的措辞，原样沿用，而 Router 并不暴露 MiniMax 的任务查询路由。在请求[完成后保留 24 小时](/zh/development/comfy-router/queue#幂等性与计费)期间，重新读取已排队请求的结果路由会返回存储的结果文档，但没有任何文档说明这次读取会签发一个新的签名 URL。请及时下载 MP4，而不要只保存链接。

## 发布前须知

SDK 会生成 `Idempotency-Key` 并在自动重试中复用它。手动重试时，请复用原始 key。Router 最长可保持连接 10 分钟。

请求失败时，Router 会发送 `X-Comfy-Error-Type` 响应头说明原因。`422` 表示 Router 在调用提供商之前就拒绝了输入，`413` 表示请求体超出了 Router 可接受的大小。已生成的资源请及时下载，因为[结果 URL 会过期](/zh/development/comfy-router/reference#结果资产)。

上文任何字段描述中提到的尺寸限制，都是提供商对该字段自身的限定，引自提供商的规范。Router 会对整个请求体另行设置上限，base64 编码的媒体内容也计入其中：参见[请求体大小](/zh/development/comfy-router/limitations)。

本页记录的是通过 Comfy Router 调用的某一个合作伙伴模型。同一个 `comfy-sdk` / `@comfyorg/sdk` 包还提供第二个客户端，用于在 Comfy Cloud 上运行完整的 ComfyUI 工作流图：`Comfy(api_key=...)` / `new Comfy({ apiKey })`，并带有 `client.workflows`、`client.assets` 和 `client.jobs`。请参阅 [Comfy SDKs](/zh/development/api-development/sdks)。

<CardGroup cols={3}>
  <Card title="请求头" icon="list" href="/zh/development/comfy-router/headers">
    身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。
  </Card>

  <Card title="使用 Router API" icon="code" href="/zh/development/comfy-router/api">
    模型发现、验证错误、重试与计费。
  </Card>

  <Card title="限制" icon="triangle-exclamation" href="/zh/development/comfy-router/limitations">
    Router 目前不支持的功能，以及替代方案。
  </Card>
</CardGroup>
