비디오 조회
플랫폼 Video Generations API로 비디오 작업을 조회합니다.
생성 API가 반환한 작업 ID로 상태, 비디오 결과 및 메타데이터를 조회합니다. 작업이 succeeded 또는 failed 상태가 되면 폴링을 중지해야 합니다.
GET
/v1/video/generations/{task_id}생성 API가 반환한 Task ID로 비디오 작업의 현재 상태와 결과를 조회합니다. 작업이 succeeded 또는 failed 상태가 되면 폴링을 중지해야 합니다.
이 API는 플랫폼 Video Generations의 작업 경로와 상태 구조를 사용하며 OpenAI Videos의 Video ID 조회 API와 동일하지 않습니다.
작업 상태 폴링
비디오 생성은 비동기 과정입니다. 작업 제출 후 다음 간격으로 조회하여 결과 확인의 적시성과 요청 빈도를 조절할 수 있습니다:
- 작업 제출 후 먼저 2~3초 기다립니다.
- 처음 30초 동안은 5초마다 조회합니다.
- 30초부터 2분까지는 10초마다 조회합니다.
- 2분 이후에는 30초마다 조회합니다.
- 전체 시간 제한을 5~10분으로 설정하고 작업이
succeeded또는failed상태가 되면 즉시 중지합니다.
JavaScript 폴링 예시
async function pollVideoStatus(taskId, maxAttempts = 30) {
const apiOrigin = 'https://api.agtcloud.cn';
const headers = {
Authorization: 'Bearer your-api-key',
};
await new Promise((resolve) => setTimeout(resolve, 3000));
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
const response = await fetch(
`${apiOrigin}/v1/video/generations/${encodeURIComponent(taskId)}`,
{ headers },
);
if (!response.ok) {
throw new Error(`HTTP ${response.status} 조회 실패`);
}
const result = await response.json();
if (result.status === 'succeeded') {
return result;
}
if (result.status === 'failed') {
throw new Error(result.error?.message ?? '비디오 생성 실패');
}
const delay = attempt < 6 ? 5000 : attempt < 12 ? 10000 : 30000;
await new Promise((resolve) => setTimeout(resolve, delay));
}
throw new Error('비디오 작업 폴링 시간 초과');
}
pollVideoStatus('TASK_ID').then(console.log).catch(console.error);