Video Task 视频任务查询

查询视频生成任务状态。视频生成采用异步任务模式,创建任务后通过此接口轮询查询,获取最终视频地址。

GET
/api/openai/videosTask?id=任务ID

接口地址

GET /api/openai/videosTask?id={task_id}

请求头

名称是否必须说明
AuthorizationBearer API_KEY
Content-Typeapplication/json

请求参数

参数类型必填说明
idint任务ID,由创建视频接口返回

请求示例

GET /api/openai/videosTask?id=123

Curl 示例

curl https://api.hejushuzi.com/api/openai/videosTask?id=123 \
-H "Authorization: Bearer sk-xxxxxxxx"

处理中返回

{
  "code": 200,
  "msg": "running",
  "data": {
    "task_id": 123,
    "status": "running"
  }
}

成功返回

{
  "code": 200,
  "msg": "success",
  "data": {
    "task_id": 123,
    "status": "success",
    "video_url": "https://example.com/video.mp4",
    "duration": 5,
    "resolution": "1280*720"
  }
}

失败返回

{
  "code": 500,
  "msg": "Video generation failed"
}

任务状态说明

状态说明
pending等待执行
running生成中
success生成成功,video_url 可用
failed生成失败

轮询建议

视频生成通常需要 30 秒到 5 分钟,建议:

  • 每 3 秒轮询一次
  • 最长等待 10 分钟
  • 状态为 success 时停止轮询
  • 状态为 failed 时处理错误

JavaScript 示例

async function pollVideo(taskId) {
  while (true) {
    const res = await fetch(
      `/api/openai/videosTask?id=${taskId}`,
      { headers: { 'Authorization': 'Bearer sk-xxx' } }
    );
    const data = await res.json();

    if (data.data.status === 'success') {
      return data.data.video_url;
    }
    if (data.data.status === 'failed') {
      throw new Error(data.msg);
    }

    await new Promise(r => setTimeout(r, 3000));
  }
}

pollVideo(123).then(url => {
  console.log("视频地址:", url);
}).catch(err => {
  console.error("生成失败:", err.message);
});
建议每 3 秒轮询一次,视频生成通常需要 30 秒到 5 分钟。状态为 success 时停止轮询获取视频地址,状态为 failed 时处理错误。最长等待建议不超过 10 分钟。

完整流程

POST /api/openai/videosGenerations
        ↓
    返回 task_id(如:123)
        ↓
GET /api/openai/videosTask?id=123
        ↓
    status: pending  ← 等待执行
        ↓
    status: running  ← 生成中
        ↓
    status: running  ← 生成中
        ↓
    status: success  ← 生成完成
        ↓
    获取 video_url 播放视频

错误码

code说明
400参数错误(缺少 id)
401API Key 无效
404任务不存在
500视频生成失败