查询任务状态
GET
/tasks/{task_id}
查询视频生成、电商套图等异步任务的执行状态和结果。
接口信息
| 项目 | 说明 |
|---|---|
| 接口地址 | GET https://api.seeany.com/v1/tasks/{task_id} |
| 认证方式 | Bearer Token |
Path 参数
| 参数 | 类型 | 说明 |
|---|---|---|
task_id | string | 任务 ID,由创建接口返回 |
请求示例
python
from seeany import SeeAny
client = SeeAny(api_key="sk-xxxxx")
status = client.tasks.get("vid_20260603_001")
if status.status == "completed":
print(f"视频URL: {status.video_url}")
print(f"费用: ¥{status.usage.cost}")
elif status.status == "processing":
print(f"进度: {status.progress}%")
print(f"预计还需: {status.estimated_remaining}s")
elif status.status == "failed":
print(f"错误: {status.error.message}")typescript
import SeeAny from "seeany";
const client = new SeeAny({ apiKey: "sk-xxxxx" });
const status = await client.tasks.get("vid_20260603_001");
if (status.status === "completed") {
console.log(`视频URL: ${status.videoUrl}`);
} else if (status.status === "processing") {
console.log(`进度: ${status.progress}%`);
}bash
curl https://api.seeany.com/v1/tasks/vid_20260603_001 \
-H "Authorization: Bearer sk-xxxxx"响应示例
生成中
json
{
"id": "vid_20260603_001",
"object": "video_generation",
"status": "processing",
"progress": 65,
"estimated_remaining": 42
}生成完成
json
{
"id": "vid_20260603_001",
"object": "video_generation",
"status": "completed",
"completed_at": 1748908920,
"video_url": "https://cdn.seeany.com/video/vid_001/output.mp4",
"thumbnail_url": "https://cdn.seeany.com/video/vid_001/thumb.jpg",
"duration": 5,
"resolution": "720p",
"usage": { "cost": 0.70, "cost_unit": "CNY" }
}生成失败
json
{
"id": "vid_20260603_001",
"object": "video_generation",
"status": "failed",
"error": {
"code": "content_policy_violation",
"message": "生成内容违反内容安全策略"
}
}任务状态说明
| 状态 | 说明 |
|---|---|
processing | 生成中,返回 progress(0-100) 和 estimated_remaining(秒) |
completed | 生成完成,返回结果文件 URL |
failed | 生成失败,返回错误码和原因 |
轮询建议
python
import time
def wait_for_task(client, task_id, interval=10, timeout=300):
"""等待任务完成"""
start = time.time()
while time.time() - start < timeout:
status = client.tasks.get(task_id)
if status.status == "completed":
return status
elif status.status == "failed":
raise Exception(f"任务失败: {status.error.message}")
print(f"进度: {status.progress}%,预计还需 {status.estimated_remaining}s")
time.sleep(interval)
raise Exception("任务超时")推荐方式
相比轮询,推荐使用 Webhook 回调获取结果,更高效且节省请求次数。