查询视频生成任务
本接口用于查询单个视频生成任务的当前状态与结果。创建任务后,您可以使用此接口轮询任务状态,直到状态变为 succeeded,然后从 content.video_url 字段获取生成视频的下载地址。
请求方法
GET:<ai-api-base-url>/llm/v1/contents/generations/tasks/{task_id}
其中,<ai-api-base-url> 为您的 API Key 所属数据中心的域名:
- 北京数据中心:
https://ai.rong-api.com - 北美数据中心:
https://ai.us-light-api.com
请求头参数
| 参数名 | 类型 | 是否必填 | 默认值 | 说明 |
|---|---|---|---|---|
| Authorization | string | 是 | - | 身份认证令牌,格式为 Bearer <your API key>,需替换为实际 API Key,用于验证用户权限。 |
路径参数
| 参数名 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| task_id | string | 是 | 创建视频生成任务时返回的任务 ID(id 字 段的值)。 |
请求示例
- cURL
- Python
- JavaScript
bash
curl --request GET \
--url '<ai-api-base-url>/llm/v1/contents/generations/tasks/cgt-2025xxxxxx-xxxx' \
--header 'Authorization: Bearer <token>'
python
import requests
import time
headers = {
"Authorization": "Bearer <token>"
}
# 轮询查询任务状态
task_id = "cgt-2025xxxxxx-xxxx" # 替换为实际任务 ID
while True:
response = requests.get(
f"<ai-api-base-url>/llm/v1/contents/generations/tasks/{task_id}",
headers=headers
)
result = response.json()
status = result.get("status")
if status == "succeeded":
print("视频生成成功")
print("视频下载地址:", result["content"]["video_url"])
break
elif status in ("failed", "cancelled", "expired"):
print(f"任务结束,状态:{status}")
if result.get("error"):
print("错误信息:", result["error"]["message"])
break
else:
print(f"当前状态:{status},10 秒后重试...")
time.sleep(10)
JavaScript
const taskId = 'cgt-2025xxxxxx-xxxx'; // 替换为实际任务 ID
const options = {
method: 'GET',
headers: {
'Authorization': 'Bearer <token>'
}
};
fetch(`<ai-api-base-url>/llm/v1/contents/generations/tasks/${taskId}`, options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
返回结果
| 参数名 | 类型 | 是否必返 | 说明 |
|---|---|---|---|
| id | string | 是 | 视频生成任务 ID。 |
| model | string | 是 | 执行本次任务所使用的模型名称。 |
| status | enum<string> | 是 | 任务当前状态。可能的值:queued(排队中)、running(生成中)、succeeded(已完成)、failed(已失败)、cancelled(已取消)、expired(已超时)。 |
| content | object | 否 | 任务完成(status 为 succeeded)后返回,包含生成内容信息。 |
| content.video_url | string | 否 | 生成视频的下载地址(MP4 格式)。有效期 24 小时,请及时转存。 |
| content.last_frame_url | string | 否 | 视频尾帧图像的下载地址(PNG 格式,无水印)。仅在创建任务时设置了 return_last_frame: true 时返回。有效期 24 小时,请及时转存。 |
| usage | object | 否 | 本次任务的 token 用量统计。 |
| usage.completion_tokens | integer | 否 | 生成视频消耗的 token 数量。 |
| usage.total_tokens | integer | 否 | 总 token 消耗(视频生成模型不统计输入 token,故与 completion_tokens 相同)。 |
| error | object | 否 | 任务失败时返回,包含错误详情。 |
| error.code | string | 否 | 错误码。 |
| error.message | string | 否 | 错误描述信息。 |
| created_at | integer | 是 | 任务创建时间(Unix 时间戳,单位:秒)。 |
| updated_at | integer | 是 | 任务最后更新时间(Unix 时间戳,单位:秒)。 |
| seed | integer | 否 | 本次生成使用的随机种子。 |
| resolution | string | 否 | 生成视频的分辨率,如 "720p"。 |
| ratio | string | 否 | 生成视频的宽高比,如 "16:9"。 |
| duration | integer | 否 | 生成视频的时长(单位:秒)。创建任务时未指定 frames 时返回此字段。 |
| framespersecond | integer | 否 | 生成视频的帧率(FPS)。 |
| generate_audio | boolean | 否 | 生成的视频是否包含同步音频。 |