curl --request POST \
--url https://api.apiyi.com/hailuo/v2/video_generation \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "MiniMax-H3",
"content": [
{
"type": "text",
"text": "黄昏海边的灯塔,镜头缓慢推进,海浪拍打礁石,电影级光影"
}
],
"resolution": "768P",
"duration": 5,
"ratio": "16:9"
}
'{
"task_id": "task_Clo9iKPCM46sRwRsMFcmJG6pGNSL1ygx"
}MiniMax H3 影片生成(開源自部署)
MiniMax-H3 影片生成 API 參考
MiniMax-H3 影片生成 API 參考與線上除錯:一個端點覆蓋文生、首尾幀、參考圖/影片/音訊生影片,非同步提交 + 按 task_id 查詢,768P、4–15 秒、按秒計費。
POST
/
hailuo
/
v2
/
video_generation
curl --request POST \
--url https://api.apiyi.com/hailuo/v2/video_generation \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "MiniMax-H3",
"content": [
{
"type": "text",
"text": "黄昏海边的灯塔,镜头缓慢推进,海浪拍打礁石,电影级光影"
}
],
"resolution": "768P",
"duration": 5,
"ratio": "16:9"
}
'{
"task_id": "task_Clo9iKPCM46sRwRsMFcmJG6pGNSL1ygx"
}右側的互動式 Playground 支援線上除錯。在 Authorization 填入你的 API Key(格式
Bearer sk-xxx),在 content 裡放一個文本項(需要時再加圖片 / 影片 / 音訊項),選好 duration 與 ratio 即可傳送。傳送後拿到的是 task_id,影片要用下文的查詢介面取回。一個端點,四種玩法:只放文本 = 文生影片;加
first_frame / last_frame 圖片 = 首尾幀生影片;加 reference_image / reference_video / reference_audio = 參考素材生影片。系統按 content[] 自動識別,不用切換端點。能力總覽見 MiniMax-H3 概覽。⚠️ 最容易踩的四個坑
- 路徑帶
/hailuo字首:建立是POST /hailuo/v2/video_generation,查詢是GET /hailuo/v2/query/video_generation/{task_id}。不帶字首的/v2/...會返回網頁而不是 JSON duration必須是整數,範圍 4–15:傳字串"5"或小數5.5會被拒resolution只能寫大寫768P:768p、2K都會被拒- 純文本和純音訊請求不能用
ratio: "adaptive",必須選固定比例;adaptive只在帶圖片或影片時可用
程式碼示例
Python(requests · 提交 + 輪詢 + 下載)
import time
import requests
API_KEY = "sk-your-api-key"
BASE = "https://api.apiyi.com/hailuo/v2"
HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
# 第 1 步:提交任務
payload = {
"model": "MiniMax-H3",
"content": [
{"type": "text", "text": "黃昏海邊的燈塔,鏡頭緩慢推進,海浪拍打礁石,電影級光影"}
],
"resolution": "768P", # 只支援大寫 768P
"duration": 5, # 整數 4–15,按秒計費
"ratio": "16:9", # 純文本請求必須用固定比例
}
for attempt in range(3):
# 提交本身要幾秒;高峰期偶發 500,不扣費,退避後重試
r = requests.post(f"{BASE}/video_generation", headers=HEADERS, json=payload, timeout=60)
if r.status_code != 500:
break
time.sleep(5 * (attempt + 1))
r.raise_for_status()
task_id = r.json()["task_id"]
print("task_id:", task_id)
# 第 2 步:輪詢(通常 2–4 分鐘出片,最長等 15 分鐘)
deadline = time.time() + 900
while time.time() < deadline:
task = requests.get(f"{BASE}/query/video_generation/{task_id}",
headers=HEADERS, timeout=30).json()["task"]
print(task["status"])
if task["status"] == "succeeded":
video_url = task["content"]["url"]
break
if task["status"] == "failed":
# 失敗任務自動退款,error 裡有原因
raise RuntimeError(task["error"])
time.sleep(10)
else:
raise TimeoutError(task_id)
# 第 3 步:下載(地址不需要鑑權;用 GET,不要用 HEAD 探活)
with requests.get(video_url, stream=True, timeout=300) as v, open("output.mp4", "wb") as f:
v.raise_for_status()
for chunk in v.iter_content(1 << 16):
f.write(chunk)
print("Saved: output.mp4")
Python(首幀生影片 · 請求體片段)
payload = {
"model": "MiniMax-H3",
"content": [
{"type": "text", "text": "人物緩緩轉頭微笑,微風吹動髮絲,鏡頭輕推"},
{"type": "image_url",
"image_url": {"url": "https://your-cdn.example.com/first.png"},
"role": "first_frame"},
],
"resolution": "768P",
"duration": 5,
"ratio": "adaptive", # 跟隨首幀圖片比例
}
Python(多參考素材 · 請求體片段)
payload = {
"model": "MiniMax-H3",
"content": [
# 按同類素材的出現順序編號:第 1 張圖 = <Picture 1>,第 1 段影片 = <Video 1>
{"type": "text", "text": "<Picture 1> 按照 <Video 1> 的動作起舞,節奏跟隨 <Audio 1>"},
{"type": "image_url", "image_url": {"url": "https://your-cdn.example.com/character.png"},
"role": "reference_image"},
{"type": "video_url", "video_url": {"url": "https://your-cdn.example.com/motion.mp4"},
"role": "reference_video"},
{"type": "audio_url", "audio_url": {"url": "https://your-cdn.example.com/music.mp3"},
"role": "reference_audio"},
],
"resolution": "768P",
"duration": 10,
"ratio": "adaptive",
}
cURL
curl -X POST "https://api.apiyi.com/hailuo/v2/video_generation" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
--max-time 60 \
-d '{
"model": "MiniMax-H3",
"content": [
{"type": "text", "text": "黃昏海邊的燈塔,鏡頭緩慢推進,海浪拍打礁石,電影級光影"}
],
"resolution": "768P",
"duration": 5,
"ratio": "16:9"
}'
Node.js(原生 fetch)
const API_KEY = 'sk-your-api-key';
const BASE = 'https://api.apiyi.com/hailuo/v2';
const headers = { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' };
const submit = await fetch(`${BASE}/video_generation`, {
method: 'POST',
headers,
body: JSON.stringify({
model: 'MiniMax-H3',
content: [{ type: 'text', text: '雪山上空緩緩流動的極光,延時攝影質感' }],
resolution: '768P',
duration: 8,
ratio: '21:9',
}),
});
if (!submit.ok) throw new Error(`submit ${submit.status}: ${await submit.text()}`);
const { task_id } = await submit.json();
let task;
for (;;) {
await new Promise(r => setTimeout(r, 10000));
task = (await (await fetch(`${BASE}/query/video_generation/${task_id}`, { headers })).json()).task;
if (task.status === 'succeeded' || task.status === 'failed') break;
}
if (task.status === 'failed') throw new Error(JSON.stringify(task.error));
console.log('video:', task.content.url);
瀏覽器 JavaScript
{/* 僅作演示,生產請走後端代理避免 Key 洩露 */}
const resp = await fetch('https://api.apiyi.com/hailuo/v2/video_generation', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer sk-your-api-key' },
body: JSON.stringify({
model: 'MiniMax-H3',
content: [{ type: 'text', text: '水彩風格的小船漂過平靜的河面' }],
resolution: '768P',
duration: 4,
ratio: '9:16',
}),
});
const { task_id } = await resp.json();
console.log('task_id:', task_id);
{/* 輪詢交給後端,拿到 content.url 後直接用 video 標籤播放 */}
已有 task_id?一條 cURL 查結果
curl "https://api.apiyi.com/hailuo/v2/query/video_generation/task_xxxxxxxxxxxxxxxx" \
-H "Authorization: Bearer sk-your-api-key"
status 為 succeeded 時,task.content.url 就是 MP4 地址,可直接下載:
curl -L -o output.mp4 "<task.content.url 的值>"
引數說明速查
| 引數 | 型別 | 必填 | 預設 | 說明 |
|---|---|---|---|---|
model | string | 是 | — | 固定 MiniMax-H3,大小寫敏感 |
content | array | 是 | — | 恰好 1 個文本項 + 0–12 個媒體項(參考圖 ≤ 9、參考影片 ≤ 3、參考音訊 ≤ 3) |
content[].text | string | 是 | — | 1–7000 字元;引用素材寫 <Picture 1> / <Video 1> / <Audio 1> |
content[].role | string | 視情況 | — | 圖片:first_frame / last_frame / reference_image;影片:reference_video;音訊:reference_audio。只有一張圖時可省略(按首幀處理) |
resolution | string | 是 | — | 僅 768P |
duration | integer | 是 | — | 4–15 秒,按秒計費 |
ratio | string | 是 | — | 21:9 / 16:9 / 4:3 / 1:1 / 3:4 / 9:16 / adaptive |
比例與輸出尺寸(實測)
ratio | 輸出尺寸 |
|---|---|
21:9 | 1536×672 |
16:9 | 1344×768 |
4:3 | 1024×768 |
1:1 | 768×768 |
3:4 | 768×1024 |
9:16 | 768×1344 |
adaptive | 跟隨輸入圖片比例(如方圖出 768×768) |
素材要求
| 型別 | 格式 | 大小 | 時長 / 尺寸 |
|---|---|---|---|
| 圖片 | JPG / PNG / WebP / HEIC / HEIF(靜態) | ≤ 30MB | 單邊 256–5760 畫素,寬高比 0.4–2.5;首尾幀比例差不超過 2% |
| 影片 | MP4 / MOV(H.264 / H.265) | ≤ 50MB | 每段 ≥ 2 秒;超 15 秒只取片頭;多段累計不超過 15 秒 |
| 音訊 | WAV / MP3 / M4A / AAC | ≤ 15MB | 每段 ≥ 2 秒;超 15 秒只取片頭 |
所有素材都必須是公網可直接下載的 HTTPS 連結。Base64、data URI、
http:// 連結、內網地址都不支援;帶防盜鏈或需要登入的連結會讓任務在下載素材時失敗。響應格式
建立任務
{"task_id": "task_Clo9iKPCM46sRwRsMFcmJG6pGNSL1ygx"}
查詢任務(生成中)
{
"task": {
"id": "task_Clo9iKPCM46sRwRsMFcmJG6pGNSL1ygx",
"status": "running",
"progress": 0,
"content": null,
"error": null
}
}
查詢任務(成功)
{
"task": {
"id": "task_R3SNqSywqnYPTAbqg1Z4iXEItPoln59I",
"status": "succeeded",
"progress": 1,
"model": "MiniMax-H3",
"modality": "video",
"task_type": "generation",
"ratio": "21:9",
"resolution": "768P",
"duration": 5,
"usage": {
"input_image_count": 0,
"input_seconds": 0,
"output_seconds": 5,
"total_seconds": 5
},
"content": {
"url": "https://your-video-host.example.com/outputs/4a441cc0....mp4"
},
"created_at": 1790641245,
"updated_at": 1790641411
}
}
查詢任務(失敗)
{
"task": {
"id": "task_w6ASrlpw5rfIVeeMSMnC5sHryP2Xv4th",
"status": "failed",
"error": {"code": "input_download_failed", "message": "media server returned 404"}
}
}
⚠️ 響應欄位要點
- 查詢結果包在
task物件裡,不在頂層 - 成功時穩定存在的只有
id、status、progress、content.url;usage、model、ratio等欄位不保證每次都返回,解析時請做好預設處理 - 狀態依次為
queued→running→succeeded/failed;高峰期可能直接從running開始 progress只在 0 和 1 之間跳,不適合做百分比進度條- 影片地址在
task.content.url,下載不需要鑑權頭。該地址對HEAD請求返回 403,但GET正常——檢查可用性請用GET - 建議拿到地址後儘快下載轉存到自己的儲存
計費:任務受理時按
duration × \$0.03 預扣,參考素材不額外收費;任務失敗會自動全額退款。提交階段返回 4xx / 5xx 的請求不扣費,查詢與下載不收費。價格詳見 概覽頁定價。授權
在 API易控制台获取的 API Key
主體
application/json
固定为 MiniMax-H3(大小写敏感)
可用選項:
MiniMax-H3 恰好一个文本项 + 0–12 个媒体项。媒体项类型:
image_url:角色first_frame/last_frame/reference_image,参考图最多 9 张;只有一张图且省略role时按首帧处理video_url:角色reference_video,最多 3 段,MP4/MOV,≤ 50MB,每段 ≥ 2 秒,累计不超过 15 秒audio_url:角色reference_audio,最多 3 段,WAV/MP3/M4A/AAC,≤ 15MB,每段 ≥ 2 秒
Required array length:
1 - 13 elements- Option 1
- Option 2
- Option 3
- Option 4
Show child attributes
Show child attributes
分辨率,本通道仅支持 768P(必须大写,768p / 2K 会被拒)
可用選項:
768P 输出时长(秒),整数 4–15。按秒计费;实际成片通常比名义值长 0.1–0.5 秒
必填範圍:
4 <= x <= 15画面比例与输出尺寸:21:9=1536×672、16:9=1344×768、4:3=1024×768、1:1=768×768、3:4=768×1024、9:16=768×1344。
adaptive 跟随输入图片比例,只能用于带图片 / 视频的请求;纯文本和纯音频请求必须用固定比例。
可用選項:
16:9, 9:16, 21:9, 4:3, 1:1, 3:4, adaptive 回應
任务已受理,返回 task_id
任务 ID,用于 GET /hailuo/v2/query/video_generation/{task_id} 查询
範例:
"task_Clo9iKPCM46sRwRsMFcmJG6pGNSL1ygx"
這個頁面有幫助嗎?