视频生成为异步任务,分两步:① 提交任务获取 taskId,② 轮询状态直至 SUCCEEDED。
| 1 | import requests, time |
| 2 | |
| 3 | BASE = "https://api.prysm-ai.com/v1" |
| 4 | HDR = {"Authorization": "Bearer sk-xxxxxxxx", "Content-Type": "application/json"} |
| 5 | MODEL = "doubao-seedance-2-0-260128" # Seedance 2.0 |
| 6 | |
| 7 | # ① 提交任务 |
| 8 | # 文生视频:仅 prompt |
| 9 | # 首帧 / 首尾帧:images=[{"role":"first_frame","url":...}, {"role":"last_frame","url":...}] |
| 10 | # 参考图:images=[{"role":"reference_image","url":"..."}](不能与首尾帧混用) |
| 11 | # 引用资产库:images=[{"role":"reference_image","url":"asset://<id>"}] |
| 12 | # 视频/音频参考:videos=[{"url":...}] / audios=[{"url":...}] |
| 13 | resp = requests.post(f"{BASE}/videos/generations", headers=HDR, json={ |
| 14 | "model": MODEL, |
| 15 | "prompt": "一只海豚跃出海面,慢动作,超高清", |
| 16 | "resolution": "720P", |
| 17 | "durationSeconds": 5, |
| 18 | "aspectRatio": "16:9", |
| 19 | }) |
| 20 | task_id = resp.json()["taskId"] |
| 21 | print(f"Task ID: {task_id}") |
| 22 | |
| 23 | # ② 轮询状态(每 10 秒) |
| 24 | while True: |
| 25 | r = requests.get( |
| 26 | f"{BASE}/videos/generations/{task_id}", |
| 27 | params={"model": MODEL}, |
| 28 | headers=HDR, |
| 29 | ) |
| 30 | data = r.json() |
| 31 | status = data["status"] |
| 32 | print(f"状态: {status}") |
| 33 | |
| 34 | if status == "SUCCEEDED": |
| 35 | print("视频地址:", data["data"][0]["url"]) |
| 36 | break |
| 37 | elif status == "FAILED": |
| 38 | print("生成失败") |
| 39 | break |
| 40 | |
| 41 | time.sleep(10) |
⚠️ 视频 URL 有效期约 24 小时,请及时下载保存。
</>Request Schema POST /v1/videos/generations(Seedance 2.0)
FieldTypeDescription
modelrequired
string视频模型 ID,如 "doubao-seedance-2-0-260128"(Seedance 2.0);完整列表见下方「模型 ID 参考 → 视频模型」promptrequired
string视频描述文本(必填)resolutionoptional
string分辨率 "480P" | "720P" | "1080P",默认 720P(不同模型支持的档位不同,以模型详情页为准)durationSecondsoptional
integer时长(秒),4–15,默认 5aspectRatiooptional
string宽高比 "adaptive" | "16:9" | "4:3" | "1:1" | "3:4" | "9:16" | "21:9",默认 16:9generateAudiooptional
bool是否生成音频,默认开启;传 false 关闭seedoptional
integer随机种子;相同种子+参数可复现imagesoptional
object[]图生视频:[{ role, url }],role ∈ first_frame | last_frame | reference_image(reference_image 不能与首尾帧混用);url 也可填 asset://<id> 引用资产库videosoptional
object[]参考视频:[{ url }](可选,计费按「带参考视频」档)audiosoptional
object[]参考音频:[{ url }](可选)计费说明:Seedance 系列按上游返回的 usage token 数计费, 单价随「分辨率 × 是否带参考视频」变化;时长越长 token 越多、费用越高。提交时按预估校验余额,任务成功后按实际 token 结算,失败不扣费。各档价格见模型详情页。 旧路径 POST /api/video + GET /api/video/status?task_id=&model= 仍可使用,效果相同。
</>🪪 人像资产库(asset library)—— 复用同一人物角色
想用「同一个虚拟人 IP / 代言人形象」反复出视频?把图片先注册为资产,拿到 asset_id 后, 生成视频时用 asset://<id> 替代 URL, 速度更快、人物特征更稳定。上游按账号隔离资产,本平台再按用户 ID 二次隔离,互不可见。
| 1 | import requests, time |
| 2 | BASE = "https://api.prysm-ai.com" |
| 3 | HDR = {"Authorization": "Bearer sk-xxxxxxxx", "Content-Type": "application/json"} |
| 4 | |
| 5 | MODEL = "doubao-seedance-2-0-260128" # 资产按模型所在线路隔离,创建和生成要用同一个模型 |
| 6 | |
| 7 | # ① 创建资产(异步处理,按次计费) |
| 8 | r = requests.post(f"{BASE}/api/video/assets", headers=HDR, json={ |
| 9 | "model": MODEL, |
| 10 | "url": "https://your-cdn.com/avatar.jpg", |
| 11 | "asset_type": "image", |
| 12 | "note": "代言人 A" # 可选,仅本地备注 |
| 13 | }) |
| 14 | asset_id = r.json()["asset_id"] |
| 15 | |
| 16 | # ② 轮询资产状态(每 5s)直到 READY |
| 17 | while True: |
| 18 | s = requests.get(f"{BASE}/api/video/assets/{asset_id}", headers=HDR).json() |
| 19 | if s.get("status") == "READY": |
| 20 | break |
| 21 | if s.get("status") == "FAILED": |
| 22 | raise RuntimeError("asset 处理失败") |
| 23 | time.sleep(5) |
| 24 | |
| 25 | # ③ 生成视频时引用 asset |
| 26 | resp = requests.post(f"{BASE}/v1/videos/generations", headers=HDR, json={ |
| 27 | "model": MODEL, |
| 28 | "images": [{ "role": "reference_image", "url": f"asset://{asset_id}" }], |
| 29 | "prompt": "让人物在城市夜景下行走", |
| 30 | }) |
| 31 | print(resp.json()) |
</>Resource Schema /api/video/assets
FieldTypeDescription
POST /api/video/assetsrequired
createBody: { model, url, asset_type:"image", note? };返回 { asset_id, status:"PENDING"|"READY", ... }GET /api/video/assetsrequired
list列出当前账号拥有的 asset(?model= 只列该模型线路的,按创建时间倒序,上限 500 条)GET /api/video/assets/{id}required
query查上游最新状态,会同步缓存到本地 status 字段DELETE /api/video/assets/{id}required
unbind解除本地映射;上游 asset 保留(按上游 API key 全局共享,避免被其他用户引用)⚠️ asset 处理通常 10-30 秒,PENDING 状态不能用于生成视频。 失败时返回 FAILED,可重新创建。
</>Response Schema(提交成功 → PENDING)
{} POST /v1/videos/generations · 提交响应JSON
| 1 | { |
| 2 | "taskId": "cgt-20260525095304-fjhbp", |
| 3 | "status": "PENDING", |
| 4 | "done": false, |
| 5 | "timestamps": { |
| 6 | "submitTime": "2026-05-25T09:53:04Z" // ISO 8601 UTC |
| 7 | } |
| 8 | } |
</>Response Schema(轮询 → SUCCEEDED)
{} GET /v1/videos/generations/{taskId}?model= · 完成响应JSON
| 1 | { |
| 2 | "taskId": "cgt-20260525095304-fjhbp", |
| 3 | "status": "SUCCEEDED", // "PENDING" | "SUCCEEDED" | "FAILED" |
| 4 | "done": true, |
| 5 | "data": [ |
| 6 | { |
| 7 | "url": "https://prysm-ai.com/api/video/media/xxxxxxxx.mp4" // 视频文件 |
| 8 | } |
| 9 | ], |
| 10 | "timestamps": { |
| 11 | "submitTime": "2026-05-25T09:53:04Z" |
| 12 | } |
| 13 | } |
</>Parameters GET /v1/videos/generations/{taskId}
FieldTypeDescription
taskId(路径)required
string提交时返回的 taskIdmodel(query)required
string与提交时相同的模型 ID