所有视频生成均为异步任务模式。创建任务后,通过轮询 GET /video/v1/tasks/:task_id 获取结果。

创建任务响应

{
  "task_id": "a1b2c3d4-e5f6-..."
}

task_id 用于后续查询和追溯。

查询任务状态

curl https://51kik.com/video/v1/tasks/a1b2c3d4-e5f6-... \
  -H 'Authorization: Bearer sk-xxxxxxxx'

pending / running 时

{
  "task_id": "a1b2c3d4-e5f6-...",
  "task_status": "running",
  "model": "wan2.1-t2v-turbo",
  "created": 1719000000000,
  "updated": 1719000005000,
  "completed": null,
  "data": [],
  "error": null
}

成功时

{
  "task_id": "a1b2c3d4-e5f6-...",
  "task_status": "success",
  "model": "wan2.1-t2v-turbo",
  "created": 1719000000000,
  "updated": 1719000050000,
  "completed": 1719000050000,
  "data": [{ "url": "https://..." }],
  "error": null
}

失败或取消时

{
  "task_id": "a1b2c3d4-e5f6-...",
  "task_status": "failed",
  "model": "wan2.1-t2v-turbo",
  "created": 1719000000000,
  "updated": 1719000050000,
  "completed": 1719000050000,
  "data": [],
  "error": { "code": "upstream_task_failed", "message": "upstream video generation task failed" }
}

响应字段

字段类型说明
task_idstring任务 ID
task_status'pending' | 'running' | 'success' | 'failed' | 'cancelled'任务状态
modelstring请求模型
creatednumber | null任务创建时间戳,毫秒
updatednumber | null任务更新时间戳,毫秒
completednumber | null任务完成时间戳,毫秒
dataArray<{ url?: string; [key: string]: unknown }>成功时返回视频 URL 和驱动扩展字段
error{ code: string; message: string } | null失败或取消时返回错误信息

状态流转

pending -> running -> success
                  -> failed
                  -> cancelled

SDK 自动轮询

SDK 的 .task() 方法已封装自动轮询:

const result = await rb.video({
  model: 'wan2.1-t2v-turbo',
  prompt: '...',
}).task({ pollInterval: 3000 });  // 每 3 秒轮询一次,默认 2 秒

// 取消轮询
const controller = new AbortController();
setTimeout(() => controller.abort(), 120000);
const result2 = await rb.video({ model: '...', prompt: '...' })
  .task({ signal: controller.signal });

超时建议

  • 创建任务(POST):建议 curl --max-time 30
  • 查询任务(GET):按需轮询,建议间隔 2-5s。SDK 默认 pollInterval: 2000