快速开始
5 分钟跑通你的第一个 Seedance 视频生成任务。
前置条件
- 已在本平台注册账号
- 已在 用户中心 → API Keys 创建一个 API Key (格式:
sk-...) - 账户有足够余额(参考 计费说明)
Step 1: 创建视频任务
最简单的文生视频请求, 复制即用:
bash
curl -X POST https://www.dianlitoken.com/v1/videos \
-H "Authorization: Bearer sk-你的KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-2.0-fast",
"content": [
{"type": "text", "text": "一只橘猫在草地上奔跑,阳光明媚"}
],
"resolution": "480p",
"duration": 4
}'返回示例:
json
{
"id": "cgt-20260527165600-kf7rt",
"task_id": "cgt-20260527165600-kf7rt",
"object": "video",
"model": "seedance-2.0-fast",
"status": "queued",
"progress": 0,
"created_at": 1779869660
}记下 id — 这是你的任务 ID, 下一步会用。
Step 2: 轮询任务状态
把上一步的 id 填进去:
bash
TASK_ID=cgt-20260527165600-kf7rt
KEY=sk-你的KEY
curl https://www.dianlitoken.com/v1/videos/$TASK_ID \
-H "Authorization: Bearer $KEY"每 10 秒查一次, 状态会经过(OpenAI 风格):
queued → in_progress → completed成功后的返回:
json
{
"id": "cgt-20260527165600-kf7rt",
"task_id": "cgt-20260527165600-kf7rt",
"object": "video",
"model": "seedance-2.0-fast",
"status": "completed",
"progress": 100,
"created_at": 1779869660,
"completed_at": 1779869780,
"metadata": {
"url": "https://ark-aigc-cn-beijing.tos-cn-beijing.volces.com/.../xxxxxx.mp4?X-Tos-Signature=..."
}
}视频下载地址在 metadata.url, token 消耗在 metadata.usage.total_tokens。
OpenAI 路由 vs Volcengine 路由
- OpenAI 路由
/v1/videos/{id}: 视频 URL 在metadata.url, usage / 分辨率 / 时长等在metadata.{usage, resolution, duration, ratio, framespersecond, seed} - Volcengine 路由
/api/v3/contents/generations/tasks/{id}: 视频 URL 在content.video_url, usage / 维度字段在响应顶层(跟 Volcengine 即梦官方 SDK 字段位置一致)
两个路由都能拿到 tokens 和金额,不需要再去控制台日志页查。
完整字段说明见 03 查询任务。
Step 3: 下载或转存视频
bash
curl -o my-cat.mp4 "https://ark-aigc-cn-beijing.tos-cn-beijing.volces.com/.../xxxxxx.mp4?X-Tos-Signature=..."⚠️ URL 24 小时内有效, 之后会失效。务必下载或转存到自己的存储里。
完整 Python 示例
python
import requests
import time
API_KEY = "sk-你的KEY"
BASE_URL = "https://www.dianlitoken.com"
# 1. 创建任务
resp = requests.post(
f"{BASE_URL}/v1/videos",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"model": "seedance-2.0-fast",
"content": [{"type": "text", "text": "一只橘猫在草地上奔跑"}],
"resolution": "480p",
"duration": 4,
},
)
resp.raise_for_status()
task_id = resp.json()["id"]
print(f"Task created: {task_id}")
# 2. 轮询
while True:
time.sleep(10)
resp = requests.get(
f'{BASE_URL}/v1/videos/{task_id}',
headers={'Authorization': f'Bearer {API_KEY}'},
)
data = resp.json()
status = data['status']
print(f'Status: {status}')
if status == 'completed':
video_url = data['metadata']['url']
print(f'Video ready: {video_url}')
break
if status == 'failed':
print(f'Task failed: {data.get("error", {}).get("message")}')
break
# 3. 下载
if status == 'completed':
video = requests.get(video_url)
with open('my-cat.mp4', 'wb') as f:
f.write(video.content)
print(f'Saved to my-cat.mp4 ({len(video.content)} bytes)')Node.js 示例
javascript
const API_KEY = 'sk-你的KEY'
const BASE_URL = 'https://www.dianlitoken.com'
async function generateVideo() {
// 1. 创建任务
const createRes = await fetch(`${BASE_URL}/v1/videos`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'seedance-2.0-fast',
content: [{ type: 'text', text: '一只橘猫在草地上奔跑' }],
resolution: '480p',
duration: 4,
}),
})
const { id: taskId } = await createRes.json()
console.log(`Task created: ${taskId}`)
// 2. 轮询
while (true) {
await new Promise(r => setTimeout(r, 10000))
const queryRes = await fetch(`${BASE_URL}/v1/videos/${taskId}`, {
headers: { 'Authorization': `Bearer ${API_KEY}` },
})
const data = await queryRes.json()
console.log(`Status: ${data.status}`)
if (data.status === 'completed') {
const videoUrl = data.metadata.url
console.log(`Video ready: ${videoUrl}`)
return videoUrl
}
if (data.status === 'failed') {
throw new Error(`Task failed: ${data.error?.message}`)
}
}
}
generateVideo().catch(console.error)用 Volcengine 风格 (即梦 SDK 直连兼容)
如果你之前用即梦官方 SDK / Ark SDK, 直接换 Base URL 即可, 响应字段也按 Volcengine 官方 spec 返回:
bash
# 创建 — 只返一个字段 { "id": "cgt-xxx" }
curl -X POST https://www.dianlitoken.com/api/v3/contents/generations/tasks \
-H "Authorization: Bearer sk-你的KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-2.0-pro",
"content": [{"type":"text","text":"..."}]
}'
# 查询 — 视频 URL 在 content.video_url, usage / seed / dimensions 都在顶层
curl https://www.dianlitoken.com/api/v3/contents/generations/tasks/$TASK_ID \
-H "Authorization: Bearer sk-你的KEY"终态响应示例:
json
{
"id": "cgt-xxx",
"model": "seedance-2.0-pro",
"status": "succeeded",
"content": {"video_url": "https://..."},
"usage": {"completion_tokens": 40594, "total_tokens": 40594},
"seed": 42,
"resolution": "720p",
"duration": 5,
"ratio": "16:9",
"framespersecond": 24,
"created_at": 1779872160,
"updated_at": 1779872279,
"execution_expires_after": 172800
}状态枚举 6 个: queued / running / succeeded / failed / expired / cancelled(比 OpenAI 路由的 4 个更细)。
id 跟官方一致
响应里的 id 就是上游 Volcengine 的 cgt-yyyymmddhhmmss-xxxxx 格式,跟即梦官方 SDK 完全兼容,直接拷代码就能用。 后续查询时用这个 id 作为 task_id 参数即可。
跑通后做什么
- 想测试更多参数 / 模型 → 02 创建任务
- 不想轮询, 想要回调通知 → 04 回调 (Webhook)
- 想用图片做参考 → 02 创建任务 § image2video
- 想上传素材重复使用 → 05 素材库
- 想做带人脸的视频 → 06 真人认证
- 看价格 → 07 计费
下一篇: 02 创建任务 →