支持的 AI 模型
为什么选择我们的 API
极速处理
优化的处理管道,<100ms 响应时间,毫秒级延迟。
企业级安全
端到端加密、ISO 27001 认证、企业级隐私保护。
数据隐私
严格遵守 GDPR,用户数据 30 天自动删除。
高可靠性
99.9% 正常运行时间保证,全球多区域部署。
无限扩展
自动扩展架构,支持任意流量,无需担心容量。
完善文档
详细 API 文档、SDK 示例、最佳实践指南。
SDK 安装
快速开始指南
Python SDK
通过 pip 安装
pip install seedance-sdk
通过 poetry 安装
poetry add seedance-sdk
Node.js SDK
通过 npm 安装
npm install seedance-sdk
通过 yarn 安装
yarn add seedance-sdk
快速开始指南
Python 示例
初始化客户端
基础设置
import seedance # Initialize client client = seedance.Client(api_key="your-api-key-here") # Or use environment variable # export SEEDANCE_API_KEY="your-api-key" # client = seedance.Client()
生成图像
Seedream 图像生成
# Generate high-quality images using Seedream 4.5
response = client.seedream.generate(
prompt="A serene mountain landscape at sunset, oil painting style",
model="seedream-4.5",
resolution="4k",
quality="high",
num_images=1,
seed=42 # Optional: for reproducible results
)
# Get results
image_url = response.images[0].url
print(f"Generated image: {image_url}")生成视频
Seedance 视频生成
# Generate video using Seedance 1.5 Pro
response = client.seedance.generate(
prompt="A majestic eagle soaring over snowy mountains",
model="seedance-1.5-pro",
duration=15, # seconds
resolution="1080p",
fps=24
)
# Get async task ID
task_id = response.task_id
print(f"Task submitted: {task_id}")检查任务状态
轮询结果
import time
# Poll task status
while True:
status = client.task.get_status(task_id)
if status.status == "completed":
result = status.result
print(f"Video URL: {result.video_url}")
break
elif status.status == "failed":
print(f"Task failed: {status.error_message}")
break
else:
print(f"Task status: {status.status}")
time.sleep(2) # Check every 2 secondsNode.js / TypeScript 示例
初始化客户端
基础设置
import { SeedanceClient } from 'seedance-sdk';
// Initialize client
const client = new SeedanceClient({
apiKey: 'your-api-key-here'
});
// Or use environment variable
// const client = new SeedanceClient();生成图像
Seedream 图像生成
// Generate images using Seedream 4.5
const response = await client.seedream.generate({
prompt: "A cyberpunk city street with neon signs",
model: "seedream-4.5",
resolution: "4k",
quality: "high",
numImages: 1
});
// Get results
const imageUrl = response.images[0].url;
console.log(`Generated image: ${imageUrl}`);生成视频
Seedance 视频生成
// Generate video using Seedance 1.5 Pro
const response = await client.seedance.generate({
prompt: "A spacecraft entering Earth's atmosphere",
model: "seedance-1.5-pro",
duration: 20, // seconds
resolution: "1080p",
fps: 24
});
// Get task ID
const taskId = response.taskId;
console.log(`Task submitted: ${taskId}`);异步等待
等待完成
// Use waitForCompletion helper function
const result = await client.task.waitForCompletion(taskId, {
maxWaitTime: 300000, // 5 minutes
pollInterval: 2000 // Check every 2 seconds
});
if (result.status === 'completed') {
console.log(`Video URL: ${result.videoUrl}`);
} else {
console.error(`Task failed: ${result.errorMessage}`);
}REST API 使用
cURL 请求示例
生成图像
POST /v1/seedream/generate
curl -X POST https://api.seedance2api.com/v1/seedream/generate \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A beautiful sunset over the ocean",
"model": "seedream-4.5",
"resolution": "4k",
"quality": "high",
"num_images": 1
}' | jq '.images[0].url'生成视频
POST /v1/seedance/generate
curl -X POST https://api.seedance2api.com/v1/seedance/generate \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A runner jogging through a forest",
"model": "seedance-1.5-pro",
"duration": 15,
"resolution": "1080p",
"fps": 24
}' | jq '.task_id'检查任务状态
GET /v1/tasks/:task_id
curl -X GET https://api.seedance2api.com/v1/tasks/task-123-abc \
-H "Authorization: Bearer your-api-key" | jq '.'
# Response example:
# {
# "task_id": "task-123-abc",
# "status": "processing",
# "progress": 45,
# "created_at": "2024-01-15T10:30:00Z",
# "updated_at": "2024-01-15T10:32:15Z"
# }获取最终结果
GET /v1/results/:task_id
curl -X GET https://api.seedance2api.com/v1/results/task-123-abc \
-H "Authorization: Bearer your-api-key" | jq '.'
# Response example:
# {
# "task_id": "task-123-abc",
# "status": "completed",
# "result": {
# "video_url": "https://cdn.seedance2api.com/videos/...",
# "duration": 15,
# "resolution": "1080p"
# },
# "completed_at": "2024-01-15T10:35:00Z"
# }API 参数详解
完整的参数说明和示例
Seedream 图像生成参数
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| prompt | string | 是 | 图像描述文本,最多300字符 | A sunset over mountains |
| model | string | 是 | 模型名称:seedream-3.0, seedream-4.0, seedream-4.5, seedream-5.0 | seedream-4.5 |
| resolution | string | 否 | 输出分辨率:1024x1024, 2048x2048, 4k (4096×4096) | 4k |
| quality | string | 否 | 生成质量:standard, high | high |
| num_images | integer | 否 | 生成图像数量,1-4张 | 1 |
| seed | integer | 否 | 随机种子,用于重现结果 | 42 |
| style | string | 否 | 艺术风格:oil_painting, watercolor, cyberpunk等 | oil_painting |
Seedance 视频生成参数
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
| prompt | string | 是 | 视频描述文本,最多300字符 | Running through forest |
| model | string | 是 | 模型名称:seedance-1.0, seedance-1.5-pro, seedance-2.0 | seedance-1.5-pro |
| duration | integer | 是 | 视频时长(秒),5-30秒 | 15 |
| resolution | string | 否 | 输出分辨率:720p, 1080p, 4k | 1080p |
| fps | integer | 否 | 帧率:24, 30, 60 | 24 |
| image_input | string | 否 | 参考图片URL(可选),用于图生视频 | https://... |
响应格式示例
标准化的 JSON 响应结构
成功响应
图像生成成功
{
"status": "success",
"data": {
"task_id": "task-uuid-12345",
"images": [
{
"id": "img-uuid-001",
"url": "https://cdn.seedance2api.com/images/...",
"width": 2048,
"height": 2048,
"format": "png",
"size_bytes": 4526048
}
],
"model": "seedream-4.5",
"resolution": "4k",
"processing_time_ms": 2500
}
}视频生成已接受
{
"status": "accepted",
"data": {
"task_id": "task-uuid-67890",
"status": "queued",
"estimated_wait_time_seconds": 45,
"check_status_url": "/v1/tasks/task-uuid-67890"
}
}错误响应
错误请求 (400)
{
"status": "error",
"error": {
"code": "INVALID_PROMPT",
"message": "Prompt is too long (max 300 characters)",
"details": {
"field": "prompt",
"value": "...",
"constraint": "max_length",
"limit": 300
}
}
}未授权 (401)
{
"status": "error",
"error": {
"code": "INVALID_API_KEY",
"message": "API key is invalid or expired"
}
}错误处理指南
| HTTP状态码 | 错误代码 | 说明 | 建议操作 |
|---|---|---|---|
| 400 | INVALID_REQUEST | 请求参数无效或缺失 | 检查请求参数格式和必填项 |
| 401 | UNAUTHORIZED | API密钥无效或过期 | 验证API密钥是否正确 |
| 403 | FORBIDDEN | 无权限访问该资源 | 升级账户或联系支持 |
| 429 | RATE_LIMITED | 超出速率限制 | 等待后重试,查看速率限制头 |
| 500 | INTERNAL_ERROR | 服务器内部错误 | 稍后重试或联系技术支持 |
| 503 | SERVICE_UNAVAILABLE | 服务暂时不可用 | 使用指数退避重试机制 |
最佳实践
- 实现指数退避重试策略
- 设置合理的超时时间(建议5分钟)
- 视频生成使用轮询或Webhook获取结果
- 记录所有API错误以便调试
- 使用Webhook避免频繁轮询
速率限制
不同套餐的请求配额说明
请求限制
免费版10次/小时
适合个人测试和小规模使用
专业版1000次/小时
适合中小型应用和开发团队
企业版无限制
适合大规模生产环境,自定义配额
响应头信息
速率限制响应头
HTTP/1.1 200 OK X-RateLimit-Limit: 1000 X-RateLimit-Remaining: 999 X-RateLimit-Reset: 1705315200 X-RateLimit-RetryAfter: 3600 # Explanation: # X-RateLimit-Limit: Total quota for current period # X-RateLimit-Remaining: Remaining requests # X-RateLimit-Reset: Quota reset timestamp # X-RateLimit-RetryAfter: Recommended retry wait time in seconds
认证方式 - API Key
如何获取API密钥
- 1
注册账户
访问 seedance2api.com 注册新账户
- 2
验证邮箱
完成邮箱验证激活账户
- 3
进入控制台
登录后进入开发者控制台
- 4
生成密钥
在API密钥页面生成新的密钥
如何使用API密钥
HTTP请求中使用
# Method 1: Using Authorization header
curl -X POST https://api.seedance2api.com/v1/seedream/generate \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{"prompt": "..."}'
# Method 2: Using X-API-Key header
curl -X POST https://api.seedance2api.com/v1/seedream/generate \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"prompt": "..."}'安全提示
- • 不要在客户端代码中暴露API密钥
- • 使用环境变量存储密钥
- • 定期轮换密钥
- • 如果密钥泄露,立即删除并重新生成
Webhook 支持
实时通知
配置Webhook接收任务完成通知,无需频繁轮询API。支持自动重试和签名验证。
- 任务完成自动通知
- 失败通知
- 进度更新(可选)
- 自动重试机制
Webhook事件示例
{
"event": "task.completed",
"timestamp": "2024-01-15T10:35:00Z",
"data": {
"task_id": "task-uuid-12345",
"status": "completed",
"model": "seedance-1.5-pro",
"result": {
"video_url": "https://cdn.seedance2api.com/...",
"duration": 15,
"resolution": "1080p"
}
}
}如何设置Webhook
- 1. 在控制台配置Webhook URL
- 2. 选择要接收的事件类型
- 3. 验证Webhook签名确保安全
- 4. 在请求中添加webhook_url参数
免费额度说明
定价预览
灵活的定价方案,满足从个人开发者到企业的各种需求
常见问题
快速找到您需要的答案