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

# MiniMax-Hailuo-02 視頻生成

> 使用 MiniMax Hailuo 02 模型生成視頻，支持文生視頻、圖生視頻和首尾幀生成

> [!NOTE]
>
> **中國大陸用戶請注意：** 中國大陸用戶請使用 `https://toapis.cn` 作為接口地址（Base URL）。文檔示例中的 `https://toapis.com` 請替換為 `https://toapis.cn`。

* 異步任務接口，提交後返回任務 ID
* 支持模型：`MiniMax-Hailuo-02`
* 支持三種生成模式：文生視頻、圖生視頻、首尾幀生成
* 支持 512P / 768P / 1080P 分辨率，6 秒和 10 秒時長

> [!WARNING]
>
> 請傳入公網可訪問的圖片 URL。不要在 `image_urls` 或 `metadata` 中直接傳 base64 圖片數據；本地圖片請先使用 [上傳圖片接口](https://docs.toapis.com/docs/zh-Hant/api-reference/uploads/images.md) 獲取 URL。

## 認證

**Authorization** `string` *required*

所有接口均需要使用 Bearer Token 認證。

```
Authorization: Bearer YOUR_API_KEY
```

## 請求參數

**model** `string` *required*

模型名稱，固定爲 `MiniMax-Hailuo-02`。

**prompt** `string`

視頻內容描述，最大 **2000 字符**。

* 文生視頻模式下爲**必填**
* 圖生視頻和首尾幀模式下爲可選（可用於描述期望的運動效果）

支持 15 種運鏡指令（如 `[推進]`、`[拉遠]`、`[左搖,上升]` 等），詳見下方運鏡指令表。

示例：`"一隻貓咪跑向鏡頭，微笑並眨眼"`

**duration** `integer` (default: 6)

視頻時長（秒）。

可選值：`6` 或 `10`

> [!WARNING]
>
> 使用 `1080P` 分辨率時，僅支持 `6` 秒時長。

**resolution** `string` (default: 768P)

視頻分辨率。

可選值：

* `512P` - 標清（圖生視頻可用）
* `768P` - 高清（默認）
* `1080P` - 全高清（僅支持 6 秒時長）

**image\_urls** `string[]`

首幀圖片 URL 數組。

* 不傳：文生視頻
* 傳 1 張：圖生視頻，圖片作爲視頻起始幀

圖片要求：

* 格式：JPG、JPEG、PNG、WebP
* 大小：小於 20MB
* 尺寸：短邊 > 300px，長寬比在 2:5 \~ 5:2 之間

示例：`["https://example.com/first-frame.jpg"]`

**metadata** `object`

擴展參數。

**顯示 metadata 字段**

**last\_frame\_image** `string`

尾幀圖片 URL，用於**首尾幀生成模式**。

傳入此參數後自動啓用首尾幀模式，系統會生成從首幀到尾幀的過渡視頻。

* 當同時傳入 `image_urls`（首幀）和 `last_frame_image`（尾幀）時，視頻尺寸以首幀爲準
* 首幀和尾幀尺寸不一致時，模型會參考首幀對尾幀進行裁剪
* 首尾幀模式**不支持 512P** 分辨率

圖片要求與 `image_urls` 相同。

示例：`"https://example.com/last-frame.jpg"`

**prompt\_optimizer** `boolean` (default: true)

是否自動優化 prompt。設爲 `false` 可進行更精確的控制。

**fast\_pretreatment** `boolean` (default: false)

是否縮短 prompt 優化耗時。啓用後可加快處理速度。

**aigc\_watermark** `boolean` (default: false)

是否在生成的視頻中添加水印。

**callback\_url** `string`

ToAPIs 最終任務 Webhook。需先設定 Token URL 與密鑰；詳見 [Webhook](https://docs.toapis.com/docs/zh-Hant/api-reference/webhooks/task-webhooks.md)。

## 三種生成模式

| 模式 | image\_urls | metadata.last\_frame\_image | 說明 |
| - | :-: | :-: | - |
| 文生視頻 | 不傳 | 不傳 | 純文本描述生成視頻 |
| 圖生視頻 | ✅ 傳 1 張 | 不傳 | 以圖片爲首幀生成視頻 |
| 首尾幀生成 | ✅ 傳 1 張（首幀） | ✅ 傳入（尾幀） | 生成從首幀到尾幀的過渡視頻 |

## 分辨率與時長組合

| 分辨率 | 支持的時長 | 文生視頻 | 圖生視頻 | 首尾幀 |
| - | - | :-: | :-: | :-: |
| 512P | 6 秒、10 秒 | ✅ | ✅ | ❌ |
| 768P | 6 秒、10 秒 | ✅ | ✅ | ✅ |
| 1080P | 6 秒 | ✅ | ✅ | ✅ |

## 運鏡指令

在 `prompt` 中使用 `[指令]` 語法控制運鏡效果：

| 類別 | 指令 |
| - | - |
| 平移 | `[左移]` `[右移]` |
| 左右搖 | `[左搖]` `[右搖]` |
| 推拉 | `[推進]` `[拉遠]` |
| 升降 | `[上升]` `[下降]` |
| 上下搖 | `[上搖]` `[下搖]` |
| 變焦 | `[變焦推近]` `[變焦拉遠]` |
| 其他 | `[晃動]` `[跟隨]` `[固定]` |

**使用規則**：

* 組合運鏡：同一 `[]` 內多個指令同時生效，如 `[左搖,上升]`，建議不超過 3 個
* 順序運鏡：prompt 中前後出現的指令依次生效，如 `"...[推進]，然後...[拉遠]"`

## 響應

**id** `string`

任務 ID，用於查詢任務狀態。

**object** `string`

對象類型，固定爲 `generation.task`。

**model** `string`

本次請求使用的模型名稱。

**status** `string`

任務狀態：`queued`、`in_progress`、`completed` 或 `failed`。

**created\_at** `integer`

任務創建時間戳。

## 示例

### 文生視頻

```json theme={null}
{
  "model": "MiniMax-Hailuo-02",
  "prompt": "城市夜景，霓虹燈閃爍，車流穿梭 [推進]",
  "duration": 6,
  "resolution": "1080P"
}
```

### 圖生視頻

```json theme={null}
{
  "model": "MiniMax-Hailuo-02",
  "prompt": "人物緩緩轉身，面帶微笑",
  "image_urls": ["https://example.com/portrait.jpg"],
  "duration": 6,
  "resolution": "768P"
}
```

### 首尾幀生成

```json theme={null}
{
  "model": "MiniMax-Hailuo-02",
  "prompt": "小女孩逐漸長大",
  "image_urls": ["https://example.com/child.jpg"],
  "duration": 6,
  "resolution": "1080P",
  "metadata": {
    "last_frame_image": "https://example.com/adult.jpg"
  }
}
```

### 運鏡控制

```json theme={null}
{
  "model": "MiniMax-Hailuo-02",
  "prompt": "一個人拿起一本書 [上升]，然後開始閱讀 [固定]",
  "duration": 6,
  "resolution": "768P"
}
```

### 10 秒長視頻 + 快速預處理

```json theme={null}
{
  "model": "MiniMax-Hailuo-02",
  "prompt": "海浪拍打沙灘，日落時分，金色光芒灑在海面上",
  "duration": 10,
  "resolution": "768P",
  "metadata": {
    "prompt_optimizer": true,
    "fast_pretreatment": true
  }
}
```

> [!NOTE]
>
> 視頻生成爲異步任務。提交後使用 [獲取視頻任務狀態](https://docs.toapis.com/docs/zh-Hant/api-reference/tasks/video-status.md) 查詢進度和結果。

```bash cURL theme={null}
curl --request POST \
  --url https://toapis.com/v1/videos/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "MiniMax-Hailuo-02",
    "prompt": "城市夜景，霓虹燈閃爍，車流穿梭",
    "duration": 6,
    "resolution": "1080P"
  }'
```

```python Python theme={null}
import requests

response = requests.post(
    "https://toapis.com/v1/videos/generations",
    headers={
        "Authorization": "Bearer your-ToAPIs-key",
        "Content-Type": "application/json",
    },
    json={
        "model": "MiniMax-Hailuo-02",
        "prompt": "城市夜景，霓虹燈閃爍，車流穿梭",
        "duration": 6,
        "resolution": "1080P",
    },
)

print(response.json())
```

```javascript JavaScript theme={null}
const response = await fetch("https://toapis.com/v1/videos/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer your-ToAPIs-key",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "MiniMax-Hailuo-02",
    prompt: "城市夜景，霓虹燈閃爍，車流穿梭",
    duration: 6,
    resolution: "1080P"
  })
});

console.log(await response.json());
```

```json 200 theme={null}
{
  "id": "vid_01K8SGYNNNVBQTXNR4MM964S7K",
  "object": "generation.task",
  "model": "MiniMax-Hailuo-02",
  "status": "queued",
  "progress": 0,
  "created_at": 1768380224,
  "metadata": {}
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.