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