SDK 与代码示例
Seedance 2.0 API 使用标准 REST 接口,可直接用任意 HTTP 客户端调用,无需安装任何 SDK。本页按三种生成模式给出完整可复制代码。
Base URL
https://api.evolink.ai
所有示例请先
export EVOLINK_API_KEY="your-api-key-here"。
文生视频(text-to-video)
Python
import os
import time
import requests
API_KEY = os.environ["EVOLINK_API_KEY"]
BASE_URL = "https://api.evolink.ai"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# 1. 创建任务
response = requests.post(
f"{BASE_URL}/v1/videos/generations",
headers=headers,
json={
"model": "seedance-2.0-text-to-video",
"prompt": "夕阳下的海面,电影级广角镜头",
"duration": 5,
"quality": "720p",
"aspect_ratio": "16:9"
}
)
task_id = response.json()["id"]
print(f"Task created: {task_id}")
# 2. 轮询
while True:
result = requests.get(f"{BASE_URL}/v1/tasks/{task_id}", headers=headers).json()
if result["status"] == "completed":
print(f"Video URL: {result['results'][0]}")
break
if result["status"] == "failed":
print("Generation failed")
break
print(f"Progress: {result['progress']}%")
time.sleep(5)
Node.js
const API_KEY = process.env.EVOLINK_API_KEY;
const BASE_URL = "https://api.evolink.ai";
const headers = {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json"
};
// 1. 创建任务
const createRes = await fetch(`${BASE_URL}/v1/videos/generations`, {
method: "POST",
headers,
body: JSON.stringify({
model: "seedance-2.0-text-to-video",
prompt: "夕阳下的海面,电影级广角镜头",
duration: 5,
quality: "720p",
aspect_ratio: "16:9"
})
});
const { id: taskId } = await createRes.json();
console.log(`Task created: ${taskId}`);
// 2. 轮询
while (true) {
const res = await fetch(`${BASE_URL}/v1/tasks/${taskId}`, { headers });
const result = await res.json();
if (result.status === "completed") {
console.log(`Video URL: ${result.results[0]}`);
break;
}
if (result.status === "failed") {
console.log("Generation failed");
break;
}
console.log(`Progress: ${result.progress}%`);
await new Promise(r => setTimeout(r, 5000));
}
cURL
# 1. 创建任务
curl -X POST https://api.evolink.ai/v1/videos/generations \
-H "Authorization: Bearer $EVOLINK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-2.0-text-to-video",
"prompt": "夕阳下的海面,电影级广角镜头",
"duration": 5,
"quality": "720p"
}'
# 响应: {"id": "task-unified-...", "status": "pending", ...}
# 2. 查询状态
curl https://api.evolink.ai/v1/tasks/TASK_ID \
-H "Authorization: Bearer $EVOLINK_API_KEY"
图生视频(image-to-video)
首帧驱动(1 张图)
response = requests.post(
f"{BASE_URL}/v1/videos/generations",
headers=headers,
json={
"model": "seedance-2.0-image-to-video",
"prompt": "模特缓缓转身,头发在风中轻轻飘动",
"image_urls": ["https://example.com/portrait.jpg"],
"duration": 5,
"quality": "720p",
"aspect_ratio": "adaptive"
}
)
首尾帧过渡(2 张图)
response = requests.post(
f"{BASE_URL}/v1/videos/generations",
headers=headers,
json={
"model": "seedance-2.0-image-to-video",
"prompt": "从黎明的海面平滑过渡到日落的同一片海",
"image_urls": [
"https://example.com/sunrise.jpg",
"https://example.com/sunset.jpg"
],
"duration": 6,
"quality": "720p"
}
)
参考生视频(reference-to-video)
同时使用图片、视频、音频参考素材:
response = requests.post(
f"{BASE_URL}/v1/videos/generations",
headers=headers,
json={
"model": "seedance-2.0-reference-to-video",
"prompt": (
"参考视频 1 的第一人称视角和镜头节奏;"
"以音频 1 作为整段背景音乐。"
"内容:年轻骑手穿越雨后的城市街道,霓虹反射在湿漉漉的路面上。"
),
"image_urls": ["https://example.com/rider-style.jpg"],
"video_urls": ["https://example.com/pov-reference.mp4"],
"audio_urls": ["https://example.com/synthwave-bgm.mp3"],
"duration": 10,
"quality": "720p",
"aspect_ratio": "16:9"
}
)
注意:
reference-to-video没有@Image1、@Video1之类的标签语法。用自然语言描述每份素材的作用即可。
使用 Fast 系列
把 model 字段从 seedance-2.0-xxx 换成 seedance-2.0-fast-xxx,其它参数完全不变:
response = requests.post(
f"{BASE_URL}/v1/videos/generations",
headers=headers,
json={
"model": "seedance-2.0-fast-text-to-video", # ← 唯一改动
"prompt": "夕阳下的海面,电影级广角镜头",
"duration": 5,
"quality": "720p"
}
)
详见 Fast 系列。
使用 Webhook 替代轮询
response = requests.post(
f"{BASE_URL}/v1/videos/generations",
headers=headers,
json={
"model": "seedance-2.0-text-to-video",
"prompt": "一只弹钢琴的猫",
"duration": 5,
"callback_url": "https://yourapp.com/api/video-callback"
}
)
# 任务完成时,你的回调端点会收到 POST 请求,包含与任务查询接口相同的响应体
详见 Webhooks。
兼容 OpenAI 客户端
本 API 遵循 OpenAI 风格的 REST 约定(Bearer Token、JSON body、统一响应结构),你可以用任意 HTTP 客户端库调用,无需专用 SDK。