Seedance 创建任务
创建异步 Seedance 视频生成任务。
接口
| 项目 | 值 |
|---|---|
| 方法 | POST |
| 路径 | /api/v3/contents/generations/tasks |
| Base URL | https://api.unigateway.ai |
| 鉴权 | Authorization: Bearer $UNIGATEWAY_API_KEY |
请求
Example request
Run it in your stack
Pick the SDK style that matches your app and copy the snippet directly into your project.
import requests
api_key = "<YOUR_UNIGATEWAY_API_KEY>"
base_url = "https://api.unigateway.ai"
headers = {
"Authorization": "Bearer " + api_key,
"Content-Type": "application/json",
}
resp = requests.post(
base_url + "/api/v3/contents/generations/tasks",
headers=headers,
json={
"model": "doubao-seedance-2-0-fast-260128",
"content": [
{
"type": "text",
"text": "A cinematic tracking shot of a sports car driving through neon streets at night.",
}
],
"ratio": "16:9",
"duration": 5,
"resolution": "720p",
"generate_audio": False,
"seed": -1,
},
)
resp.raise_for_status()
print(resp.json())curl -sS -X POST "https://api.unigateway.ai/api/v3/contents/generations/tasks" \
-H "Authorization: Bearer $UNIGATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seedance-2-0-fast-260128",
"content": [
{
"type": "text",
"text": "一辆跑车在夜晚的霓虹街道上行驶,电影跟踪镜头。"
}
],
"ratio": "16:9",
"duration": 5,
"resolution": "720p",
"generate_audio": false,
"seed": -1
}'
响应:
{
"id": "task_123456"
}
创建接口只返回任务 ID。最终视频地址和用量数据需要通过查询任务接口获取。
请求体
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 账号可用的 Seedance 模型 ID,例如 doubao-seedance-2-0-fast-260128 |
content | array | 是 | 输入项。文本、图片、视频、音频可以组合 |
ratio | string | 否 | 16:9、4:3、1:1、3:4、9:16、21:9 或 adaptive |
duration | integer | 否 | 输出时长,单位秒 |
generate_audio | boolean | 否 | 是否生成与画面同步的声音 |
tools | array | 否 | 工具配置。当前支持 type: web_search |
resolution | string | 否 | 输出分辨率:480p 或 720p |
seed | integer | 否 | 随机种子。-1 表示默认;也可以传 0 到 4294967295 |
service_tier | string | 否 | 模型支持时可指定服务档位 |
Content URL 来源
图片、视频、音频输入里的 url 支持:
- 公网可访问 URL
- Data URI,例如
data:image/png;base64,{base64_image} - 素材库引用,例如
asset://<ASSET_ID>
请求体不能超过 64 MB。大文件不要使用 base64 编码。
文本输入
{
"type": "text",
"text": "天空飘着一朵白云。"
}
图片输入
image_url 可用于首帧、尾帧和参考图。
| 规则 | 值 |
|---|---|
| 格式 | jpeg、png、webp、bmp、tiff、gif、heic、heif |
| 宽高比 | 大于 0.4 且小于 2.5 |
| 宽高长度 | 300 到 6000 px |
| 大小 | 单张小于 30 MB |
| 图生视频首帧 | 1 张 |
| 图生视频首尾帧 | 2 张 |
| 多模态参考生视频 | 1 到 9 张 |
只有一张首帧图片时,role 可以省略,也可以设置为 first_frame。
{
"type": "image_url",
"image_url": {
"url": "https://example.com/first-frame.png"
},
"role": "first_frame"
}
首尾帧生成需要分别设置 first_frame 和 last_frame。
[
{
"type": "image_url",
"image_url": {
"url": "https://example.com/first-frame.png"
},
"role": "first_frame"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/last-frame.png"
},
"role": "last_frame"
}
]
参考图需要设置 role 为 reference_image。Seedance 最多支持 9 张参考图。
{
"type": "image_url",
"image_url": {
"url": "asset://ua_123"
},
"role": "reference_image"
}
视频输入
参考视频使用 video_url,并将 role 设置为 reference_video。
| 规则 | 值 |
|---|---|
| 容器格式 | mp4、mov |
| 支持视频编码 | H.264/AVC、H.265/HEVC |
| 支持音频编码 | AAC、MP3 |
| 参考视频分辨率 | 480p、720p、1080p |
| 时长 | 单个视频 2 到 15 秒 |
| 数量 | 最多 3 个参考视频 |
| 总时长 | 所有参考视频总计不超过 15 秒 |
| 宽高比 | 0.4 到 2.5 |
| 宽高长度 | 300 到 6000 px |
| 总像素数 | 409600 到 2086876 |
| 大小 | 单个视频不超过 50 MB |
| FPS | 24 到 60 |
{
"type": "video_url",
"video_url": {
"url": "https://example.com/reference-video.mp4"
},
"role": "reference_video"
}
音频输入
参考音频使用 audio_url,并将 role 设置为 reference_audio。
| 规则 | 值 |
|---|---|
| 格式 | wav、mp3 |
| 时长 | 单个音频 2 到 15 秒 |
| 数量 | 最多 3 段参考音频 |
| 总时长 | 所有参考音频总计不超过 15 秒 |
| 大小 | 单个音频不超过 15 MB |
{
"type": "audio_url",
"audio_url": {
"url": "https://example.com/reference-audio.mp3"
},
"role": "reference_audio"
}
多模态示例
{
"model": "doubao-seedance-2-0-fast-260128",
"content": [
{
"type": "text",
"text": "生成一段产品主视觉视频,保持角色外观一致,镜头运动平滑。"
},
{
"type": "image_url",
"image_url": {
"url": "asset://ua_character_reference"
},
"role": "reference_image"
},
{
"type": "video_url",
"video_url": {
"url": "https://example.com/motion-reference.mp4"
},
"role": "reference_video"
}
],
"ratio": "16:9",
"duration": 5,
"resolution": "720p",
"generate_audio": false,
"seed": -1
}
常见失败
| 状态码 | 原因 | 处理 |
|---|---|---|
400 | 字段结构不合法或参数不支持 | 移除可选字段,用最小请求重试 |
401 / 403 | API Key 无效或权限不足 | 检查 API Key 和账号权限 |
404 | 模型不存在 | 从模型库确认模型 ID |
429 | 触发限流或审核提交上限 | 退避并排队请求 |
5xx | 网关或上游供应商异常 | 使用封顶退避重试 |