> ## Documentation Index
> Fetch the complete documentation index at: https://docs.comfy.org/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 参考文档，由 Comfy Router 提供服务，模型来自 MiniMax。

## 快速开始

在[你的 Comfy 工作区](https://platform.comfy.org/profile/api-keys)中创建一个密钥，并将其导出为 `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>
  <Tab title="Wait for the result">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # The SDK automatically creates an idempotency key and reuses it for automatic retries.
      with Comfy() as client:
          result = 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(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // Reads COMFY_API_KEY from the environment.
      // The SDK automatically creates an idempotency key and reuses it for automatic retries.
      const { data } = await comfy.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",
      });

      console.log(data);
      ```

      ```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="Queue and collect later">
    <CodeGroup>
      ```python Python theme={null}
      from comfy_sdk import Comfy

      # Reads COMFY_API_KEY from the environment.
      # Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      with Comfy() as client:
          handle = 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)  # with the model ID, all another process needs

          # Poll until the request completes, waiting the Retry-After the server names.
          for update in handle.iter_events():
              print(update.status, update.queue_position)

          # The provider's own payload, the same value models.run() returns.
          # A request that failed or was cancelled raises the typed Router error here.
          result = handle.get()

      print(result)
      ```

      ```typescript TypeScript theme={null}
      import { comfy } from "@comfyorg/sdk";

      // Reads COMFY_API_KEY from the environment.
      // Each submit() call mints its own Idempotency-Key and reuses it for automatic retries.
      const handle = await comfy.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",
      });
      console.log("requestId:", handle.requestId); // with the model ID, all another process needs

      // Poll until the request completes, waiting the Retry-After the server names.
      for await (const update of handle.events()) {
        console.log(update.status, update.queuePosition);
      }

      // The same result models.run() returns. A request that failed or was cancelled rejects here.
      const result = await handle.get();

      console.log(result.data);
      ```

      ```bash cURL theme={null}
      # 1. Submit. Router answers 201 with request_id, status_url, response_url and 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. Poll until status is COMPLETED, waiting the Retry-After seconds each response names.
      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. Collect. 200 with the model's native output, 202 with the status body while it is still running.
      curl https://api.comfy.org/v2/models/minimax/minimax-h3/requests/$REQUEST_ID \
        -H "X-API-Key: $COMFY_API_KEY"
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## 数据结构

### 输入

<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
    }
  }
}
```

## 发布前须知

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

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

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

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

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