Sand AI 的 Magi 2 影片生成模型完整 API 參考文件。
模型版本
此 API 支援以下三種模型版本:
Magi 2 Text to Video
端點
POST /api/v1/video/task
請求參數
必填參數
選填參數
請求範例
const response = await fetch('https://api.flaq.ai/api/v1/video/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'magi-2-text-to-video',
prompt: 'The camera glides toward a lighthouse at dusk as waves crash against the rocks',
duration: 8,
aspect_ratio: '16:9',
sound: true
})
});
const { data } = await response.json();
const taskId = data.task_id;
Magi 2 Image to Video
請求參數
必填參數
選填參數
請求範例
{
model_name: 'magi-2-image-to-video',
image_url: 'https://example.com/first-frame.jpg',
image_end_url: 'https://example.com/last-frame.jpg',
prompt: 'The camera slowly pulls back to reveal a waterfall and the forest around it',
duration: 8,
aspect_ratio: '16:9',
sound: false
}
Magi 2 Reference to Video
請求參數
必填參數
參考素材
各類參考素材皆為選填,可在同一個請求中搭配使用。若省略全部三個陣列,模型將僅依提示詞生成影片。
@ (AT) 引用預留位置
@ (AT) 引用功能會使用提示詞中帶編號的 <<<...>>> 預留位置來引用素材。各類素材皆從 1 開始編號,順序與對應陣列一致。
選填參數
請求範例
{
model_name: 'magi-2-reference-to-video',
prompt: 'Use the reference image for the subject, the reference video for the camera movement, and the reference audio for the ambience',
duration: 8,
aspect_ratio: '16:9',
sound: true,
images: ['https://example.com/subject-reference.jpg'],
videos: ['https://example.com/camera-movement-reference.mp4'],
audios: ['https://example.com/ambience-reference.mp3']
}
使用 @ (AT) 引用素材生成影片的請求範例
{
model_name: 'magi-2-reference-to-video',
prompt: 'Show the cyclist from <<<image_1>>> on the trail in <<<image_2>>>. Follow the camera movement in <<<video_1>>> and use <<<audio_1>>> as a reference for the forest ambience',
duration: 10,
aspect_ratio: '16:9',
sound: true,
images: [
'https://example.com/cyclist-reference.jpg',
'https://example.com/forest-trail-reference.png'
],
videos: ['https://example.com/camera-movement-reference.mp4'],
audios: ['https://example.com/forest-ambience-reference.mp3']
}
回應格式
初始回應
所有模型都會傳回 task_id,供輪詢使用:
{
"code": 0,
"message": "success",
"data": {
"task_id": "{task_id}",
"response_url": "https://api.flaq.ai/api/v1/video/{task_id}",
"task_status": "submitted"
}
}
輪詢回應
輪詢 GET /api/v1/video/{taskId} 以查看任務狀態:
{
"code": 0,
"message": "success",
"data": {
"task_id": "{task_id}",
"response_url": "https://api.flaq.ai/api/v1/video/{task_id}",
"task_status": "succeed",
"task_status_msg": null,
"task_result": {
"videos": [
{
"url": "https://example.com/generated-video.mp4"
}
]
}
}
}
狀態值
submitted:已受理任務,等待處理
processing:正在生成影片
succeed:影片生成完成
failed:影片生成失敗
最佳實務
- 提示詞:描述場景、動作、運鏡以及想聽到的聲音
- 首尾幀圖片:使用圖生影片時一律提供
image_url,即使已提供 image_end_url 也一樣
- 參考素材順序:依預計在
prompt 中引用素材的順序排列 images、videos 和 audios 內的項目
- 聲音:如需無聲影片,請將
sound 設為 false