AGTCloud API Docs
文档指南API Reference集成与资源更新与帮助
视频生成平台 Video Generations

查询视频

通过平台 Video Generations 接口查询视频任务。

使用创建接口返回的任务 ID 查询状态、视频结果和元数据;任务进入 succeeded 或 failed 后应停止轮询。

GET/v1/video/generations/{task_id}

使用创建接口返回的 Task ID 查询视频任务的当前状态和结果。任务进入 succeeded 或 failed 后应停止轮询。

本接口使用平台 Video Generations 的任务路径和状态结构,不等同于 OpenAI Videos 的 Video ID 查询接口。

Authorization

bearerAuth
AuthorizationBearer <token>

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

In: header

Path Parameters

task_id*string

创建平台视频任务时返回的 Task ID。

Length1 <= length

Response Body

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);