Seedance API 接入教程:从获取 API Key 到生成第一个视频
本教程用 Seedance 2.0 演示完整流程,Seedance 2.5 只需更换模型 ID。全程约 5 分钟。
1. 注册账号并充值
打开 注册页 创建账号,登录后在「钱包」充值。批量充值和企业结算请联系我们。
2. 创建 API Key
进入「API 密钥」,点击创建,得到以 sk- 开头的 Key。只在服务端保存,不要放进前端或 App:
export DECODE_API_KEY="sk-..."
3. 选择接口地址和模型
| 接口地址 | 适用 |
|---|---|
https://decode8.com | 默认地址,海外用户 |
https://cn.decode8.com | 中国大陆推荐,视频从国内存储下载 |
| 模型 | 国内模型 ID | 海外模型 ID | 分辨率 | 时长(秒) | 参考图 / 视频 / 音频上限 |
|---|---|---|---|---|---|
| Seedance 2.5 | doubao-seedance-2-5-261111 | dreamina-seedance-2-5-261111 | 480p、720p、1080p | 4–30 | 30 / 10 / 10 |
| Seedance 2.0 | doubao-seedance-2-0-261111 | dreamina-seedance-2-0-261111 | 480p、720p、1080p、4K | 4–15 | 9 / 3 / 3 |
4. 提交生成任务
POST /api/v3/contents/generations/tasks,返回任务 ID。下面的示例提交任务后会自动轮询直到完成:
curl https://decode8.com/api/v3/contents/generations/tasks \
-H "Authorization: Bearer $DECODE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seedance-2-0-261111",
"content": [
{
"type": "text",
"text": "一只橘猫在洒满阳光的窗台上伸懒腰,镜头缓慢推近,暖色调,电影感"
}
],
"resolution": "720p",
"ratio": "16:9",
"duration": 5,
"generate_audio": true
}'import os
import time
import requests
BASE_URL = "https://decode8.com/api/v3/contents/generations/tasks"
HEADERS = {"Authorization": f"Bearer {os.environ['DECODE_API_KEY']}"}
payload = {
"model": "doubao-seedance-2-0-261111",
"content": [
{
"type": "text",
"text": "一只橘猫在洒满阳光的窗台上伸懒腰,镜头缓慢推近,暖色调,电影感"
}
],
"resolution": "720p",
"ratio": "16:9",
"duration": 5,
"generate_audio": True
}
# 1. 提交任务,拿到任务 ID
task_id = requests.post(BASE_URL, headers=HEADERS, json=payload).json()["id"]
# 2. 每 10 秒查询一次,直到结束
while True:
task = requests.get(f"{BASE_URL}/{task_id}", headers=HEADERS).json()
if task["status"] in ("succeeded", "failed", "cancelled", "expired"):
break
time.sleep(10)
print(task["status"], task.get("content", {}).get("video_url"))const BASE_URL = 'https://decode8.com/api/v3/contents/generations/tasks'
const headers = {
Authorization: `Bearer ${process.env.DECODE_API_KEY}`,
'Content-Type': 'application/json',
}
const payload = {
"model": "doubao-seedance-2-0-261111",
"content": [
{
"type": "text",
"text": "一只橘猫在洒满阳光的窗台上伸懒腰,镜头缓慢推近,暖色调,电影感"
}
],
"resolution": "720p",
"ratio": "16:9",
"duration": 5,
"generate_audio": true
}
// 1. 提交任务,拿到任务 ID
const { id } = await fetch(BASE_URL, {
method: 'POST',
headers,
body: JSON.stringify(payload),
}).then((res) => res.json())
// 2. 每 10 秒查询一次,直到结束
let task
do {
await new Promise((resolve) => setTimeout(resolve, 10_000))
task = await fetch(`${BASE_URL}/${id}`, { headers }).then((res) => res.json())
} while (['queued', 'running'].includes(task.status))
console.log(task.status, task.content?.video_url)想用图片或参考素材?看对应的功能页: 文生视频 · 图生视频 · 参考生视频
5. 查询任务并下载视频
curl https://decode8.com/api/v3/contents/generations/tasks/task_xxxxxxxx \
-H "Authorization: Bearer $DECODE_API_KEY"状态变为 succeeded 后,从 content.video_url 下载 MP4。视频保存 60 天。
使用参考素材(可选)
常用的参考图、视频、音频可以先上传到素材库,之后用 asset://素材ID 反复引用:
curl https://decode8.com/v1/materials \
-H "Authorization: Bearer $DECODE_API_KEY" \
-F file=@product.png \
-F name=产品正面
素材通过审核(status: active)后即可引用。素材按 Key 隔离,连续 30 天未使用自动删除。完整接口见素材库文档。
从官方 API 迁移
- 接口地址:
https://ark.cn-beijing.volces.com/api/v3或 BytePlus 地址 →https://decode8.com/api/v3 - API Key → Decode 的
sk-Key - 模型名 → 上表中的模型 ID
callback_url不支持,改为轮询查询接口
常见错误
| HTTP | 原因 |
|---|---|
| 401 | Key 无效、已禁用或已过期 |
| 400 | 参数有误;参考素材超过上限或未通过审核;时长超出范围(不扣费) |
| 403 | 余额不足;素材存储或分组数量达到上限 |
| 404 | 任务或素材不存在,或不属于当前 Key |
| 429 | 请求过于频繁 |
联系技术支持时请附上错误信息中的 request id。
常见问题
已经用官方 SDK 接入,怎么切换?
把 SDK 的 base_url 设为 https://decode8.com/api/v3,api_key 换成 Decode 的 Key,模型名换成本站的模型 ID 即可,请求代码不用改。
不会写代码能用吗?
可以。登录后在「视频控制台」里填提示词、上传参考素材即可生成,「素材库」页面可以管理素材。
视频生成要多久?
取决于模型、分辨率、时长和上游排队情况,一般几十秒到数分钟。建议每 10 秒查询一次。