المرجع الكامل لواجهة برمجة التطبيقات الخاصة بنماذج Magi 2 لتوليد الفيديو من Sand AI.
إصدارات النموذج
تدعم هذه الواجهة ثلاثة إصدارات من النموذج:
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
- ترتيب المراجع: رتّب عناصر
images وvideos وaudios بحسب الترتيب الذي تريد الإشارة إليها به في prompt
- الصوت: اضبط
sound على false إذا أردت فيديو صامتًا