help.khb.com 视频系列 API: 获取视频生成链接 (Video Status)

API: 获取视频生成链接 (Video Status)

Get Video Status

Query the status of a video generation request. Once the video is generated, the response will include a download URL (valid for 10 minutes).

端点:POST /v1/video/status

Request Body

requestId (string, required)

/v1/video/submit 接口返回的请求 ID。

代码示例

Python

import requests
import time

# 1. 提交视频生成任务
submit_url = "https://khb.net.cn/v1/video/submit"
submit_payload = {
    "model": "Wan-AI/Wan2.2-T2V-A14B",
    "prompt": "a beautiful sunset over the ocean, waves gently crashing",
    "image_size": "1280x720"
}
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}

response = requests.post(submit_url, json=submit_payload, headers=headers)
request_id = response.json()["requestId"]
print(f"Request ID: {request_id}")

# 2. 轮询查询状态
status_url = "https://khb.net.cn/v1/video/status"
while True:
    status_resp = requests.post(
        status_url,
        json={"requestId": request_id},
        headers=headers
    ).json()

    status = status_resp.get("status")
    print(f"Status: {status}")

    if status == "completed":
        video_url = status_resp["videoUrl"]
        print(f"Video URL (10 分钟内有效): {video_url}")
        # 立即下载
        video_data = requests.get(video_url).content
        with open("output.mp4", "wb") as f:
            f.write(video_data)
        print("视频已保存为 output.mp4")
        break
    elif status == "failed":
        print(f"生成失败: {status_resp.get('error')}")
        break
    else:
        time.sleep(10)  # 等待 10 秒后重试

Response Body

处理中:

{
  "status": "in_progress",
  "requestId": "video-1741685396-abc123"
}

已完成:

{
  "status": "completed",
  "requestId": "video-1741685396-abc123",
  "videoUrl": "https://xxx.khb.com.cn/videos/xxx.mp4",
  "duration": 5.2,
  "resolution": "1280x720"
}

失败:

{
  "status": "failed",
  "requestId": "video-1741685396-abc123",
  "error": "Prompt contains prohibited content"
}

轮询建议

  • 建议每 10~15 秒轮询一次,避免过于频繁触发 Rate Limits
  • 视频生成通常需要 1~5 分钟,取决于模型与队列负载
  • 视频链接有效期为 10 分钟,请及时下载并转存

错误码

状态码 说明
200 查询成功
400 参数错误(requestId 缺失等)
401 API Key 无效
403 权限不足
404 请求不存在
429 触发 Rate Limits
500/503/504 服务端错误

Related Post