使用 GET /v1/videos/ 通过 id 在 CometAPI 上轮询一个 Seedance 视频任务。适用于 Seedance 1.0 Pro、1.5 Pro 和 2.0 任务。返回当前状态、进度,以及任务达到 SUCCESS 后的已签名 video_url。
curl https://api.cometapi.com/v1/videos/<TASK_ID> \
-H "Authorization: Bearer <COMETAPI_KEY>"
id 是创建调用返回的值,无论该任务是由哪个 Seedance 模型生成的。
SUBMITTED 和 IN_PROGRESS 为非终态;SUCCESS、FAILED 和 ERROR 为终态,任务不会再继续变化。
| Status | Meaning | Terminal |
|---|---|---|
SUBMITTED | 已接受并进入渲染队列。 | 否 |
IN_PROGRESS | 正在渲染中。 | 否 |
SUCCESS | 已完成。响应中会包含 video_url。 | 是 |
FAILED | 提供方拒绝了该任务。 | 是 |
ERROR | 内部错误导致无法完成。 | 是 |
import time
import requests
TASK_ID = "<TASK_ID>"
headers = {"Authorization": "Bearer <COMETAPI_KEY>"}
TERMINAL = {"SUCCESS", "FAILED", "ERROR"}
while True:
response = requests.get(
f"https://api.cometapi.com/v1/videos/{TASK_ID}",
headers=headers,
timeout=15,
)
response.raise_for_status()
data = response.json()
if data["status"] in TERMINAL:
print(data.get("video_url"))
break
time.sleep(10)
status — 决定你的轮询循环何时停止。progress — 0 到 100 的整数,可用于在 UI 中展示。video_url — 已签名的下载 URL,仅在 SUCCESS 时出现。签名有时间限制;请在签名过期前下载文件或将其重新托管。completed_at — Unix 时间戳,在任务进入终态后填充。model — 回显任务创建时使用的 Seedance model id。400 且 message: "task_not_exist" 表示该 id 不存在。请确认你记录的是成功的 POST /v1/videos 响应中返回的 id,并且按原样使用它。401 表示 bearer token 缺失或无效。请检查请求头是否为 Authorization: Bearer <COMETAPI_KEY>。Bearer token authentication. Use your CometAPI key.
Task id returned by POST /v1/videos.
Current task state.
Task id.
Object type, always video.
Model id that generated the task.
Task status. SUBMITTED and IN_PROGRESS are non-terminal. SUCCESS, FAILED, and ERROR are terminal.
SUBMITTED, IN_PROGRESS, SUCCESS, FAILED, ERROR Completion percentage.
0 <= x <= 100Task creation time as a Unix timestamp in seconds.
Signed download URL for the finished video. Present only when status is SUCCESS. The signature is time-limited, so download or re-upload the file to your own storage soon after you receive it.
Task completion time as a Unix timestamp in seconds. null while the task is non-terminal.
curl https://api.cometapi.com/v1/videos/<TASK_ID> \
-H "Authorization: Bearer <COMETAPI_KEY>"