AGTCloud API Docs
文件指南API Reference整合與資源更新與幫助
影片生成Platform Video Generations

查詢影片

透過 Platform 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。

授權

bearerAuth
授權Bearer <token>

在 Authorization Header 中使用 Bearer your-api-key。

傳遞位置: header

路徑參數

task_id*string

建立平台影片任務時回傳的 Task ID。

長度1 <= length

回應主體

application/json

application/json

application/json

application/json

application/json

application/json

輪詢任務狀態

影片生成是非同步程序。提交任務後,可以按照以下間隔查詢,以兼顧結果時效和請求頻率:

  1. 提交任務後先等待 2~3 秒。
  2. 前 30 秒每 5 秒查詢一次。
  3. 30 秒至 2 分鐘每 10 秒查詢一次。
  4. 2 分鐘後每 30 秒查詢一次。
  5. 設定 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(`Query failed with HTTP ${response.status}`);
    }

    const result = await response.json();

    if (result.status === 'succeeded') {
      return result;
    }

    if (result.status === 'failed') {
      throw new Error(result.error?.message ?? 'Video generation failed');
    }

    const delay = attempt < 6 ? 5000 : attempt < 12 ? 10000 : 30000;
    await new Promise((resolve) => setTimeout(resolve, delay));
  }

  throw new Error('Video task polling timed out');
}

pollVideoStatus('TASK_ID').then(console.log).catch(console.error);