SDK 与代码示例
Seedance 2.0 API 使用标准 REST 接口。以下是主流编程语言的完整集成示例。
基础 URL
https://api.evolink.ai
Python
import requests
import time
API_KEY = "YOUR_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",
"prompt": "A sunset over the ocean, cinematic wide shot",
"duration": 5,
"quality": "1080p",
"aspect_ratio": "16:9"
}
)
task = response.json()
task_id = task["id"]
print(f"Task created: {task_id}")
# 2. 轮询任务状态
while True:
status = requests.get(
f"{BASE_URL}/v1/tasks/{task_id}",
headers=headers
)
result = status.json()
if result["status"] == "completed":
print(f"Video URL: {result['results'][0]}")
break
elif result["status"] == "failed":
print("Generation failed")
break
print(f"Progress: {result['progress']}%")
time.sleep(5)
Node.js
const API_KEY = "YOUR_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",
prompt: "A sunset over the ocean, cinematic wide shot",
duration: 5,
quality: "1080p",
aspect_ratio: "16:9"
})
});
const task = await createRes.json();
const taskId = task.id;
console.log(`Task created: ${taskId}`);
// 2. 轮询任务状态
const poll = async () => {
while (true) {
const statusRes = await fetch(`${BASE_URL}/v1/tasks/${taskId}`, { headers });
const result = await statusRes.json();
if (result.status === "completed") {
console.log(`Video URL: ${result.results[0]}`);
return;
}
if (result.status === "failed") {
console.log("Generation failed");
return;
}
console.log(`Progress: ${result.progress}%`);
await new Promise(r => setTimeout(r, 5000));
}
};
await poll();
cURL
# 1. 创建视频生成任务
curl -X POST https://api.evolink.ai/v1/videos/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-2.0",
"prompt": "A sunset over the ocean, cinematic wide shot",
"duration": 5,
"quality": "1080p"
}'
# 响应: {"id": "task-unified-...", "status": "pending", ...}
# 2. 查询任务状态
curl https://api.evolink.ai/v1/tasks/TASK_ID \
-H "Authorization: Bearer YOUR_API_KEY"
# 完成时: {"status": "completed", "results": ["https://...mp4"], ...}
图生视频示例
# 将单张图像制作成动画
response = requests.post(
f"{BASE_URL}/v1/videos/generations",
headers=headers,
json={
"model": "seedance-2.0",
"prompt": "The woman turns her head slowly, hair flowing in the wind",
"image_urls": ["https://example.com/portrait.jpg"],
"duration": 5,
"quality": "1080p"
}
)
首尾帧示例
# 在两个关键帧之间生成过渡
response = requests.post(
f"{BASE_URL}/v1/videos/generations",
headers=headers,
json={
"model": "seedance-2.0",
"prompt": "Smooth camera pan revealing the landscape",
"image_urls": [
"https://example.com/frame-start.jpg",
"https://example.com/frame-end.jpg"
],
"duration": 8,
"quality": "1080p"
}
)
多模态示例
# 使用 @tag 组合图像、视频和音频引用
response = requests.post(
f"{BASE_URL}/v1/videos/generations",
headers=headers,
json={
"model": "seedance-2.0",
"prompt": "@Image1 as first frame, replicate @Video1 camera movement, @Audio1 for BGM rhythm. A cinematic night cityscape.",
"image_urls": ["https://example.com/scene.jpg"],
"video_urls": ["https://example.com/camera-ref.mp4"],
"audio_urls": ["https://example.com/bgm.mp3"],
"duration": 10,
"quality": "1080p"
}
)
使用回调 URL
# 使用 callback_url 代替轮询
response = requests.post(
f"{BASE_URL}/v1/videos/generations",
headers=headers,
json={
"model": "seedance-2.0",
"prompt": "A cat playing piano",
"callback_url": "https://yourapp.com/api/video-callback"
}
)
# 任务完成后,你的回调端点将收到任务结果
兼容 OpenAI
该 API 遵循 OpenAI 兼容规范。你可以使用现有的 HTTP 客户端库 — 只需将基础 URL 设置为 https://api.evolink.ai。