API 문서
Sora2 API를 통합하여 프로그래밍 방식으로 멋진 비디오를 생성하는 방법을 배우세요
💡 ChatGPT, Claude 또는 다른 AI 어시스턴트에 붙여넣어 구현하세요
2. 첫 번째 요청하기
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));Authorization 헤더에 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비디오 생성 작업을 시작하고 작업 ID를 반환합니다
매개변수
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비디오 생성 작업의 상태 및 진행 상황 확인
매개변수
taskIdrequiredgenerate-video 엔드포인트에서 반환된 작업 ID (문자열, 필수)
요청 예제
{
"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 키입니다. Authorization 헤더를 확인하세요.
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 시간
이 기간 내에 다운로드하세요