Tài liệu tham khảo đầy đủ về API cho các mô hình tạo video Magi 2 của Sand AI.
Các biến thể của mô hình
API này hỗ trợ ba biến thể của mô hình:
Magi 2 Text to Video
Điểm cuối
POST /api/v1/video/task
Tham số yêu cầu
Bắt buộc
Không bắt buộc
Ví dụ về yêu cầu
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
Tham số yêu cầu
Bắt buộc
Không bắt buộc
Ví dụ về yêu cầu
{
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
Tham số yêu cầu
Bắt buộc
Ảnh, video và âm thanh tham chiếu
Tất cả nội dung tham chiếu đều không bắt buộc và có thể kết hợp trong cùng một yêu cầu. Nếu bỏ qua cả ba mảng, mô hình sẽ tạo video chỉ dựa trên câu lệnh.
Ký hiệu tham chiếu @ (AT)
Tính năng tham chiếu @ (AT) dùng các ký hiệu <<<...>>> có đánh số trong câu lệnh. Với mỗi loại nội dung, số thứ tự bắt đầu từ 1 và tuân theo thứ tự trong mảng tương ứng.
Không bắt buộc
Ví dụ về yêu cầu
{
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']
}
Ví dụ về yêu cầu tạo video từ nội dung tham chiếu bằng @ (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']
}
Định dạng phản hồi
Phản hồi ban đầu
Tất cả các mô hình đều trả về task_id để truy vấn trạng thái định kỳ:
{
"code": 0,
"message": "success",
"data": {
"task_id": "{task_id}",
"response_url": "https://api.flaq.ai/api/v1/video/{task_id}",
"task_status": "submitted"
}
}
Phản hồi khi truy vấn trạng thái
Gọi định kỳ GET /api/v1/video/{taskId} để kiểm tra trạng thái:
{
"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"
}
]
}
}
}
Các giá trị trạng thái
submitted: Tác vụ đã được tiếp nhận và đang chờ xử lý
processing: Đang tạo video
succeed: Đã tạo xong video
failed: Tạo video thất bại
Khuyến nghị sử dụng
- Câu lệnh: Mô tả cảnh, hành động, cách quay và âm thanh bạn muốn nghe
- Ảnh khung hình: Luôn cung cấp
image_url khi tạo video từ ảnh, kể cả khi đã cung cấp image_end_url
- Thứ tự tham chiếu: Sắp xếp
images, videos và audios theo thứ tự bạn muốn tham chiếu đến các mục trong prompt
- Âm thanh: Đặt
sound thành false nếu bạn muốn tạo video không có âm thanh