视频生成/Seedance 创建任务

通过 Seedance 接口创建异步视频生成任务。

Seedance 创建任务

创建异步 Seedance 视频生成任务。

接口

项目
方法POST
路径/api/v3/contents/generations/tasks
Base URLhttps://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。最终视频地址和用量数据需要通过查询任务接口获取。

请求体

字段类型必填说明
modelstring账号可用的 Seedance 模型 ID,例如 doubao-seedance-2-0-fast-260128
contentarray输入项。文本、图片、视频、音频可以组合
ratiostring16:94:31:13:49:1621:9adaptive
durationinteger输出时长,单位秒
generate_audioboolean是否生成与画面同步的声音
toolsarray工具配置。当前支持 type: web_search
resolutionstring输出分辨率:480p720p
seedinteger随机种子。-1 表示默认;也可以传 04294967295
service_tierstring模型支持时可指定服务档位

Content URL 来源

图片、视频、音频输入里的 url 支持:

  • 公网可访问 URL
  • Data URI,例如 data:image/png;base64,{base64_image}
  • 素材库引用,例如 asset://<ASSET_ID>

请求体不能超过 64 MB。大文件不要使用 base64 编码。

文本输入

{
  "type": "text",
  "text": "天空飘着一朵白云。"
}

图片输入

image_url 可用于首帧、尾帧和参考图。

规则
格式jpegpngwebpbmptiffgifheicheif
宽高比大于 0.4 且小于 2.5
宽高长度3006000 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_framelast_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"
  }
]

参考图需要设置 rolereference_image。Seedance 最多支持 9 张参考图。

{
  "type": "image_url",
  "image_url": {
    "url": "asset://ua_123"
  },
  "role": "reference_image"
}

视频输入

参考视频使用 video_url,并将 role 设置为 reference_video

规则
容器格式mp4mov
支持视频编码H.264/AVC、H.265/HEVC
支持音频编码AAC、MP3
参考视频分辨率480p720p1080p
时长单个视频 2 到 15 秒
数量最多 3 个参考视频
总时长所有参考视频总计不超过 15 秒
宽高比0.42.5
宽高长度3006000 px
总像素数4096002086876
大小单个视频不超过 50 MB
FPS2460
{
  "type": "video_url",
  "video_url": {
    "url": "https://example.com/reference-video.mp4"
  },
  "role": "reference_video"
}

音频输入

参考音频使用 audio_url,并将 role 设置为 reference_audio

规则
格式wavmp3
时长单个音频 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 / 403API Key 无效或权限不足检查 API Key 和账号权限
404模型不存在从模型库确认模型 ID
429触发限流或审核提交上限退避并排队请求
5xx网关或上游供应商异常使用封顶退避重试