وثائق API
تعلم كيفية دمج Sora2 API لتوليد مقاطع فيديو مذهلة برمجيًا
💡 انسخ والصق في ChatGPT أو Claude أو مساعدي AI الآخرين للتنفيذ
1. احصل على مفتاح API الخاص بك
أنشئ حسابًا وقم بإنشاء مفتاح API الخاص بك من لوحة التحكم
احصل على مفتاح API2. قم بإجراء طلبك الأول
استخدم مفتاح API الخاص بك للمصادقة وابدأ في توليد مقاطع الفيديو
// Make your first video generation request
async function generateVideo() {
const response = await fetch('https://sora2api.org/api/generate-video', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'A beautiful sunset over the ocean with gentle waves',
aspectRatio: '16:9',
duration: 10,
type: 'text2video'
})
});
const result = await response.json();
console.log('Task ID:', result.data.taskId);
console.log('Credits used:', result.data.creditsUsed);
return result.data.taskId; // Save this for status checking
}
generateVideo();3. استعلم عن النتائج
تحقق من حالة مهمة توليد الفيديو الخاصة بك واسترجع عنوان URL للفيديو
// Complete example: Generate and poll for video
async function generateAndWaitForVideo() {
// Step 1: Start video generation
const generateResponse = await fetch('https://sora2api.org/api/generate-video', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'A beautiful sunset over the ocean with gentle waves',
aspectRatio: '16:9',
duration: 10,
type: 'text2video'
})
});
const generateResult = await generateResponse.json();
const taskId = generateResult.data.taskId;
console.log('Video generation started, Task ID:', taskId);
// Step 2: Poll for completion
return new Promise((resolve, reject) => {
const checkStatus = async () => {
const statusResponse = await fetch('https://sora2api.org/api/check-video-status', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ taskId })
});
const statusResult = await statusResponse.json();
const { status, progress, videoUrl } = statusResult.data;
console.log(`Status: ${status}, Progress: ${progress}%`);
if (status === 'succeeded') {
console.log('Video ready! URL:', videoUrl);
resolve(videoUrl);
} else if (status === 'failed') {
reject(new Error('Video generation failed'));
} else {
// Still processing, check again in 5 seconds
setTimeout(checkStatus, 5000);
}
};
checkStatus();
});
}
// Usage
generateAndWaitForVideo()
.then(videoUrl => console.log('Final video URL:', videoUrl))
.catch(error => console.error('Error:', error));قم بتضمين مفتاح API الخاص بك في رأس التفويض:
Authorization: Bearer YOUR_API_KEYمثال على المصادقة
curl -X POST https://sora2api.org/api/generate-video \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "A cat playing", "aspectRatio": "16:9", "duration": 10, "type": "text2video"}'/api/generate-videoيبدأ مهمة توليد الفيديو ويعيد معرف المهمة
المعاملات
promptrequiredالوصف النصي أو موجه الإجراء للفيديو (سلسلة نصية، مطلوب)
aspectRatiorequiredنسبة العرض إلى الارتفاع للفيديو: "16:9" (أفقي) أو "9:16" (عمودي) (سلسلة نصية، مطلوب)
durationoptionalVideo duration in seconds: 10 or 15 (number, optional, default: 10). Cost depends on resolution: 480p 10s = 95 credits, 480p 15s = 143 credits, 720p 10s = 205 credits, 720p 15s = 308 credits
imageUrloptionalعنوان URL العام للصورة المحملة (سلسلة نصية، اختياري، مطلوب لصورة إلى فيديو)
مثال على الطلب
{
"prompt": "A beautiful sunset over the ocean",
"aspectRatio": "16:9",
"resolution": "480p",
"duration": 10, // optional, default 10, can be 10 or 15 seconds
"type": "text2video",
"imageUrl": "https://yourdomain.com/image.jpg" // optional, for image2video
}مثال على الاستجابة
{
"code": 0,
"data": {
"success": true,
"taskId": "xxxxxxxxxx-xxxx-xxxx-xxxxxxxxxx",
"creditsUsed": 95,
"message": "Video generation started"
}
}/api/check-video-statusتحقق من حالة وتقدم مهمة توليد الفيديو
المعاملات
taskIdrequiredمعرف المهمة المُرجع من نقطة نهاية توليد الفيديو (سلسلة نصية، مطلوب)
مثال على الطلب
{
"taskId": "xxxxxxxxxx-xxxx-xxxx-xxxxxxxxxx"
}مثال على الاستجابة
{
"code": 0,
"data": {
"status": "succeeded",
"progress": 100,
"videoUrl": "https://example.com/video.mp4",
"id": "xxxxxxxxxx-xxxx-xxxx-xxxxxxxxxx"
},
"msg": "success"
}رموز الحالة
توليد فيديو من وصف نصي فقط:
async function generateTextToVideo() {
// Step 1: Generate video
const generateResponse = await fetch('https://sora2api.org/api/generate-video', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'A serene mountain landscape at sunrise',
aspectRatio: '16:9',
resolution: '480p', // optional: 480p or 720p, default 480p
duration: 10, // optional: 10 or 15 seconds
type: 'text2video'
})
});
const { data } = await generateResponse.json();
const taskId = data.taskId;
// Step 2: Poll for status
const pollStatus = async () => {
const statusResponse = await fetch('https://sora2api.org/api/check-video-status', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ taskId })
});
const statusData = await statusResponse.json();
if (statusData.data.status === 'succeeded') {
console.log('Video URL:', statusData.data.videoUrl);
return statusData.data.videoUrl;
} else if (statusData.data.status === 'running') {
// Poll again after 3 seconds
setTimeout(pollStatus, 3000);
} else {
console.error('Generation failed');
}
};
pollStatus();
}رموز الأخطاء الشائعة
401 Unauthorizedمفتاح API غير صالح أو مفقود. تحقق من رأس التفويض الخاص بك.
402 Payment Requiredأرصدة غير كافية. يرجى شراء المزيد من الأرصدة للمتابعة.
400 Bad Requestمعاملات طلب غير صالحة. تحقق من نص طلبك.
التكلفة لكل فيديو
95-308 أرصدة
480p: 95 credits for 10s, 143 credits for 15s. 720p: 205 credits for 10s, 308 credits for 15s
مدة الفيديو
10s / 15s
اختر بين 10 ثوانٍ أو 15 ثانية
الحد الأقصى لحجم الصورة
5MB
لتوليد صورة إلى فيديو
صلاحية عنوان URL للفيديو
2 ساعات
قم بالتنزيل خلال هذه الفترة