MAGI-2 影片生成
透過文字、首尾幀圖片或圖片/影片/音訊多模態參考生成 1080p 同步有聲 MP4 影片,時長 4-30 秒
中國大陸用戶請注意: 中國大陸用戶請使用 https://toapis.cn 作為 API 端點(Base URL),並將文件範例中的 https://toapis.com 替換為 https://toapis.cn。中國大陸站查詢與回調回傳的媒體檔案網址將自動使用中國大陸檔案網域。
- 平台模型名:
magi-2(全站統一模型名,透過頂層video_generation_mode區分三種模式) - 輸出規格:
1080pMP4 影片,預設同步生成對白、音效與環境聲,時長4-30秒任意整數秒 - 計費方式:按成功輸出影片秒數計費;三種模式計費規則一致,關閉音訊(
generate_audio: false)不改變計費口徑,參考素材不單獨計輸入費用,任務失敗不扣費 - 開放範圍:支援國際站(
https://toapis.com)與中國大陸站(https://toapis.cn) - 非同步任務介面:提交後回傳統一的
generation.task,透過GET /v1/videos/generations/{task_id}或GET /v1/tasks/{task_id}查詢狀態與結果
本模型採用嚴格的頂層扁平 JSON 參數白名單:所有模式(含圖生影片)prompt 均必填非空;不依素材自動推斷模式;不接受巢狀包裝物件(如 input、options、config、metadata)、舊參數別名、未知參數、Base64/Data URI 或 multipart 檔案上傳。
輸入模式
video_generation_mode |
模式說明 | 素材要求 | aspect_ratio |
|---|---|---|---|
text_to_video(預設) |
文生影片 | 不得傳入 image_urls、last_frame_url、video_urls、audio_urls |
可選,6 種比例,預設 16:9 |
first_frame_image_to_video |
首尾幀圖生影片 | image_urls 必填且恰好 1 張作為首幀;last_frame_url 可選;不得傳入 video_urls 或 audio_urls |
可選,6 種比例;省略時自動跟隨首幀 |
reference_to_video |
多模態參考生影片 | image_urls(1-10 張)、video_urls(1-5 段)、audio_urls(1-5 段)至少傳入一組且可混合;不得傳入 last_frame_url |
可選,6 種比例,預設 16:9 |
認證
所有介面均需使用 Bearer Token 認證。
Authorization: Bearer <token>請求參數
平台影片生成模型名稱,固定為 magi-2。三種模式統一使用同一模型名。
影片生成模式。預設為 text_to_video。
text_to_video:文生影片,不能攜帶任何媒體欄位first_frame_image_to_video:首幀(可選尾幀)圖生影片reference_to_video:圖片/影片/音訊多模態參考生影片
攜帶媒體輸入時必須明確指定對應模式,平台不會依 image_urls 自動推斷模式。
影片內容描述,去除首尾空白後 1-8000 個 Unicode 字元。所有模式(含圖生影片)均必填非空。 建議清楚描述主體、動作、鏡頭運動、對白(可用引號標註)、音效與環境聲。
輸出影片時長(秒),支援 4-30 之間的任意整數,預設 5。按成功輸出秒數計費。
輸出影片畫面比例,可選值:21:9、16:9、4:3、1:1、3:4、9:16。
text_to_video與reference_to_video:預設16:9first_frame_image_to_video:可選;省略時輸出畫面比例自動跟隨首幀圖片
輸出影片解析度。僅支援 1080p,傳入其他解析度值將被拒絕。
是否生成同步原生音訊(對白、音效、環境聲),預設 true。設為 false 可生成靜音影片,計費規則不變。
可選隨機種子,取值範圍 0-2147483647(含端點)。省略時使用隨機種子;明確傳入 0 會原樣保留;不接受負數。
公網可存取的 HTTP(S) 圖片 URL 陣列(支援 JPG / PNG / WEBP)。本機圖片請先透過 上傳圖片 取得 URL。
text_to_video:禁止傳入first_frame_image_to_video:必填且恰好1張,作為首幀圖片reference_to_video:可選,1-10張,作為主體/風格參考圖(不會解釋為首幀)
不使用時請省略此欄位,傳入空陣列 [] 或 null 將回傳 400 錯誤。
單張尾幀圖片公網 HTTP(S) URL(JPG / PNG / WEBP),用於指定影片結束畫面。
僅可在 first_frame_image_to_video 模式下與 image_urls 同時使用;text_to_video 與 reference_to_video 模式禁止傳入。
參考影片公網 HTTP(S) URL 陣列(支援 MP4 / MOV),1-5 段。本機影片請先透過 上傳影片 取得 URL。
- 僅適用於
reference_to_video,text_to_video與first_frame_image_to_video模式禁止傳入 - 每段參考影片建議
2-30秒且參考影片總時長<= 30秒(提交介面校驗 URL 與數量上限,媒體時長於生成階段校驗)
參考音訊公網 HTTP(S) URL 陣列(支援 MP3 / WAV),1-5 段。本機音訊請先透過 上傳音訊 取得 URL。
- 僅適用於
reference_to_video,text_to_video與first_frame_image_to_video模式禁止傳入 - 每段參考音訊建議
2-30秒且參考音訊總時長<= 30秒(提交介面校驗 URL 與數量上限,媒體時長於生成階段校驗)
可選的業務識別碼(例如訂單號或交易 ID),提交後可透過同一狀態查詢介面依該值查詢任務。
可選的 ToAPIs 任務完成回調網址(也相容 callback_url 欄位)。由平台託管並以 HMAC-SHA256 簽名投遞,詳見 任務 Webhook。
素材規則與校驗邊界
- 所有媒體輸入僅接受公網可存取的
http://或https://URL,拒絕內網/迴環位址、含內嵌憑證的 URL、Data URI、Base64 或 multipart 檔案上傳。 reference_to_video模式下image_urls、video_urls、audio_urls至少提供一組非空陣列,三類參考可自由組合,互不互斥。- 可選媒體陣列不使用時請直接省略,不得傳空陣列
[]或null。 - 以下參數或組合將回傳 HTTP
400明確拒絕:巢狀包裝物件(input、options、config、metadata)、舊別名(seconds、size、ratio、audio、audio_setting、image、images、reference_images)、stream、n、fps、watermark、return_last_frame、negative_prompt、非法seed/duration/resolution/aspect_ratio以及跨模式衝突欄位。
計費說明
| 計費項目 | 口徑說明 |
|---|---|
| 計費方式 | 按成功輸出影片秒數計費(per_second,4-30 整數秒) |
| 模式範圍 | text_to_video、first_frame_image_to_video、reference_to_video 三種模式採用相同計費規則 |
| 音軌與參考素材 | generate_audio: false(靜音)不改變計費口徑;參考圖片/影片/音訊不單獨計輸入費用 |
| 失敗與結算 | 任務失敗不扣費(退還預佔額度);最終結算以終態回應中的 billing(status: "settled" / "refunded")與 usage(charge_type: "per_second"、output_seconds)為準 |
提交回應僅回傳任務句柄,不含最終費用。實際可用性與帳戶計費細節以所在站點控制台及任務終態 billing / usage 為準。
請求範例
文生影片(含明確 seed: 0)
{
"model": "magi-2",
"video_generation_mode": "text_to_video",
"prompt": "A small boat crosses a quiet lake at sunrise, with gentle water sounds and distant birds.",
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": true,
"seed": 0
}首尾幀圖生影片(靜音,不傳 aspect_ratio)
{
"model": "magi-2",
"video_generation_mode": "first_frame_image_to_video",
"prompt": "The camera slowly pushes toward the subject and transitions smoothly into the ending composition.",
"image_urls": [
"https://example.com/first-frame.jpg"
],
"last_frame_url": "https://example.com/last-frame.jpg",
"duration": 5,
"resolution": "1080p",
"generate_audio": false
}多模態參考生影片(圖片 + 影片 + 音訊組合)
{
"model": "magi-2",
"video_generation_mode": "reference_to_video",
"prompt": "Keep the subject from the reference image, follow the camera movement from the reference video, and match the mood of the reference audio.",
"image_urls": [
"https://example.com/reference-subject.jpg"
],
"video_urls": [
"https://example.com/reference-motion.mp4"
],
"audio_urls": [
"https://example.com/reference-ambience.wav"
],
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": true
}回應
ToAPIs 平台任務 ID,用於後續查詢任務狀態。
物件類型,固定為 generation.task。
本次請求使用的平台模型名,固定為 magi-2。
任務狀態:queued、in_progress、completed 或 failed。
任務進度百分比,取值 0-100。
任務建立時間,Unix 秒級時間戳。
提交後請輪詢 查詢影片任務狀態(GET /v1/videos/generations/{task_id},相容 GET /v1/tasks/{task_id})或配置 任務 Webhook。任務完成後,生成的 MP4 影片位址位於 result.data[0].url。建議輪詢間隔至少 5-10 秒並加入隨機抖動,遇到 HTTP 429 時遵循 Retry-After。
請求示例
curl --request POST \
--url https://toapis.com/v1/videos/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "magi-2",
"video_generation_mode": "text_to_video",
"prompt": "A small boat crosses a quiet lake at sunrise, with gentle water sounds.",
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": true,
"seed": 0
}'curl --request POST \
--url https://toapis.com/v1/videos/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "magi-2",
"video_generation_mode": "first_frame_image_to_video",
"prompt": "The camera slowly pushes in and transitions smoothly to the ending frame.",
"image_urls": [
"https://example.com/first-frame.jpg"
],
"last_frame_url": "https://example.com/last-frame.jpg",
"duration": 5,
"resolution": "1080p",
"generate_audio": false
}'curl --request POST \
--url https://toapis.com/v1/videos/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "magi-2",
"video_generation_mode": "reference_to_video",
"prompt": "Keep the subject from the reference image, use the camera motion from the video, and match the ambience from the audio.",
"image_urls": [
"https://example.com/reference-subject.jpg"
],
"video_urls": [
"https://example.com/reference-motion.mp4"
],
"audio_urls": [
"https://example.com/reference-ambience.wav"
],
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": true
}'import requests
response = requests.post(
"https://toapis.com/v1/videos/generations",
headers={
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
},
json={
"model": "magi-2",
"video_generation_mode": "reference_to_video",
"prompt": "Keep the subject from the reference image and show it moving in a sunlit garden.",
"image_urls": ["https://example.com/reference-subject.jpg"],
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": True,
},
)
print(response.json())const response = await fetch("https://toapis.com/v1/videos/generations", {
method: "POST",
headers: {
Authorization: "Bearer <token>",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "magi-2",
video_generation_mode: "text_to_video",
prompt: "A small boat crosses a quiet lake at sunrise, with gentle water sounds.",
duration: 5,
aspect_ratio: "16:9",
resolution: "1080p",
generate_audio: true
})
});
console.log(await response.json());響應示例
{
"id": "tsk_vid_01M840FXWTM23BKN1JR68C5XEM",
"object": "generation.task",
"model": "magi-2",
"status": "queued",
"progress": 0,
"created_at": 1795575600
}