Skip to content

创建视频任务 ​

Seedance API(v3)

使用 https://api.tokenlio.ai 和平台 Bearer Key。model 从当前可用模型目录复制;详细字段含义可参考文末官方资料,实际调用以本页的地址、鉴权和示例为准。

提交一组 model/content 创建视频任务。HTTP200 与 id 表示受理,视频完成后通过任务查询或回调获取结果。

请求参数 ​

字段类型默认值说明
modelstring必填当前目录中的精确公共模型 ID;选型见模型与输入能力。
contentobject[]必填非空文本/媒体输入数组。
resolutionstring720p所选模型支持的输出分辨率。
ratiostringadaptive16:9、9:16、3:4、1:1、4:3、21:9、adaptive;Mini 自适应比例按可用能力提供。
durationinteger模型默认值2.0 系列 4–15 秒,2.5 为 4–30 秒;-1 表示自动时长。2.5 默认 -1,Mini 的 -1 按可用能力提供。
generate_audiobooleantrue生成音轨。Fast/Mini 示例显式传 false,音频生成按可用能力提供。
return_last_framebooleanfalse支持时返回尾帧 URL。
watermarkbooleanfalse添加生成内容水印。
seedinteger—随机种子,不保证完全相同的输出。
output_formatstringmp42.5 另支持 mov。
priorityinteger00–9。
execution_expires_afterinteger172800有效期(秒),3600–259200。
toolsobject[]—纯文本输入,最多一个 {"type":"web_search"}。
omni_reference_task_typestringauto2.5 的 auto / reference;edit / extend 按可用能力提供。
draftbooleanfalse2.5 草稿模式,按可用能力提供。
callback_urlstring—public HTTPS 生成回调,平台投递任务对象;按 X-Tokenlio-Event-Id 幂等。

字段区分大小写;布尔值与整数使用对应 JSON 类型,不使用的字段直接省略,请求正文不超过 64 MiB。创建、单任务查询和 DELETE 不使用查询参数;列表参数见任务管理。

content 元素 ​

type内容字段role
texttext—
image_urlimage_url.urlreference_image、first_frame、last_frame
video_urlvideo_url.urlreference_video
audio_urlaudio_url.urlreference_audio
draft_taskdraft_task.id—

role 与媒体对象同级,不能放进 image_url 等对象内部。媒体可使用公开 HTTPS URL 或 asset://ASSET_ID;图片还支持在 image_url.url 中直接传入 Base64 Data URL,见下方图片输入。不在素材 URL 中携带 API Key。首尾帧输入与参考素材互斥;2.0 系列参考音频需搭配图片或视频,2.5 支持纯音频参考。2.5 首尾帧模式需 ratio=adaptive。

图片输入:URL、Base64 与素材 ID ​

content[].image_url.url 支持以下三种方式,首帧、尾帧和参考图片均使用此字段:

方式image_url.url 的值使用说明
公网图片 URLhttps://example.com/valley.png可直接访问的图片地址,处理期间保持有效。
本地图片 Base64data:image/png;base64,<完整 Base64 编码>将图片文件编码后内联到 JSON,无需先上传到图床或调用 CreateAsset。
素材 IDasset://ASSET_ID引用已有素材;素材管理见素材接口。

Base64 必须使用完整格式 data:image/<图片格式>;base64,<Base64 编码>,图片格式使用小写并与真实文件一致,例如 PNG 用 image/png、JPEG 用 image/jpeg、WebP 用 image/webp。仅传裸 Base64、本机路径或 file:// 地址不能代替 Data URL。请使用标准 Base64 编码,保持编码连续、无换行,并替换示例中的全部占位符。

图片要求以官方创建接口为依据:

  • 格式:jpeg、png、webp、bmp、tiff、gif;Seedance 2.0 及以上还支持 heic、heif。
  • 每张图片小于 30 MB;宽、高均为 300–6000 px;宽高比为 0.4–2.5。
  • 平台生成请求总上限为 64 MiB,包括 JSON、全部图片编码及其他字段。Base64 约为原文件体积的 4/3,多图需合计,大文件优先使用公网 URL 或素材 ID。
  • 编码方式不改变素材数量、角色与模型限制,见模型与输入能力。first_frame 是视频起始画面,reference_image 是生成参考,不能与首尾帧模式混用。

本地图片的完整示例见Base64 图生视频。这里的内联图片提交属于生成接口,不是素材管理 Action 上传;素材 Action 的 32 KiB 正文上限不适用于此生成请求。

创建与查询 ​

bash
curl -sS --fail-with-body "https://api.tokenlio.ai/api/v3/contents/generations/tasks" \
  -H "Authorization: Bearer $TOKENLIO_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{
    "model": "seedance-2.0",
    "content": [
      {
        "type": "text",
        "text": "窗边柔光中的陶瓷茶壶,镜头缓慢环绕"
      }
    ],
    "resolution": "1080p",
    "duration": 5,
    "generate_audio": false
  }'

curl -sS --fail-with-body "https://api.tokenlio.ai/api/v3/contents/generations/tasks/TASK_ID" \
  -H "Authorization: Bearer $TOKENLIO_API_KEY"

创建响应:

json
{
  "id": "dfc68868-d388-4d83-a173-d44e47a8bec7"
}

输入与模式示例 ​

以下 JSON 均提交至同一创建地址。媒体 URL 和任务 ID 应替换为自己的可访问输入;各模式能力与素材数量限制见模型文档。

首帧 ​

json
{
  "model": "seedance-2.0",
  "content": [
    {
      "type": "text",
      "text": "镜头缓慢靠近画面中的主体"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://example.com/first.png"
      },
      "role": "first_frame"
    }
  ],
  "duration": 5,
  "generate_audio": false
}

首尾帧 ​

json
{
  "model": "seedance-2.5",
  "content": [
    {
      "type": "text",
      "text": "从日出平滑过渡到傍晚"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://example.com/first.png"
      },
      "role": "first_frame"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://example.com/last.png"
      },
      "role": "last_frame"
    }
  ],
  "ratio": "adaptive",
  "duration": 8,
  "generate_audio": false
}

参考图片 ​

json
{
  "model": "seedance-2.0",
  "content": [
    {
      "type": "text",
      "text": "图片1中的角色在花园中漫步"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://example.com/character.png"
      },
      "role": "reference_image"
    }
  ],
  "duration": 5,
  "generate_audio": false
}

本地图片 Base64 图生视频 ​

下面先用 Python 3 标准库读取本地 PNG,生成 request.json;这一步只处理本地文件,不会发起生成。将 ./valley.png 换成你的图片。若改用 JPEG,需同时把 Data URL 前缀改为 data:image/jpeg;base64,,不能仅改扩展名。

python
import base64
import json
from pathlib import Path

image = Path("./valley.png").read_bytes()
if not image or len(image) >= 30_000_000:
    raise ValueError("Image must be nonempty and smaller than 30 MB")

payload = {
    "model": "seedance-2.0",
    "content": [
        {
            "type": "text",
            "text": "参考图中的山谷、湖面与云层,云影缓慢移动,水面泛起细微波纹,镜头平稳向前推进,画面自然真实",
        },
        {
            "type": "image_url",
            "image_url": {
                "url": "data:image/png;base64," + base64.b64encode(image).decode("ascii")
            },
            "role": "reference_image",
        },
    ],
    "duration": 5,
    "resolution": "720p",
    "ratio": "16:9",
    "generate_audio": False,
}
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
if len(body) > 64 * 1024 * 1024:
    raise ValueError("Encoded request exceeds 64 MiB; use a URL or asset ID")
Path("request.json").write_bytes(body)

确认参数后执行以下命令提交真实生成请求,按实际用量计费。通过 --data-binary @request.json 读取完整正文,避免将大段 Base64 放入命令行参数:

bash
curl -sS --fail-with-body "https://api.tokenlio.ai/api/v3/contents/generations/tasks" \
  -H "Authorization: Bearer $TOKENLIO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $SEEDANCE_REQUEST_ID" \
  --data-binary @request.json

事先设置平台 Key 和本次请求唯一的 SEEDANCE_REQUEST_ID;同一意图恢复时保留原幂等键与原 request.json,新意图使用新键,不自动重发创建。成功受理返回 {"id":"平台UUID"},保存后按任务查询获取状态与 content.video_url;受理不代表视频已生成。

若希望以原图作为视频的起始画面,将示例中的 reference_image 改为 first_frame;若使用 Seedance 2.5 首帧模式,还需设 ratio:"adaptive"。request.json 含完整图片数据,应按原始素材保管,避免写入日志或提交代码仓库。

参考视频 ​

json
{
  "model": "seedance-2.0",
  "content": [
    {
      "type": "text",
      "text": "参考视频1的运镜,场景改为雪中的街道"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://example.com/movement.mp4"
      },
      "role": "reference_video"
    }
  ],
  "duration": 5,
  "generate_audio": false
}

图片、视频与音频参考 ​

json
{
  "model": "seedance-2.0",
  "content": [
    {
      "type": "text",
      "text": "使用图片1的角色、视频1的动作和音频1的节奏"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "https://example.com/character.png"
      },
      "role": "reference_image"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://example.com/movement.mp4"
      },
      "role": "reference_video"
    },
    {
      "type": "audio_url",
      "audio_url": {
        "url": "https://example.com/rhythm.mp3"
      },
      "role": "reference_audio"
    }
  ],
  "duration": 8,
  "generate_audio": false
}

2.5 纯音频参考 ​

json
{
  "model": "seedance-2.5",
  "content": [
    {
      "type": "text",
      "text": "随音频1节奏变化的抽象风景"
    },
    {
      "type": "audio_url",
      "audio_url": {
        "url": "https://example.com/rhythm.mp3"
      },
      "role": "reference_audio"
    }
  ],
  "duration": 10,
  "generate_audio": false
}

素材 ID 引用 ​

json
{
  "model": "seedance-2.0-mini",
  "content": [
    {
      "type": "text",
      "text": "参考角色向镜头挥手"
    },
    {
      "type": "image_url",
      "image_url": {
        "url": "asset://ASSET_ID"
      },
      "role": "reference_image"
    }
  ],
  "resolution": "720p",
  "duration": 5,
  "generate_audio": false
}

素材创建见素材与真人认证 Action。

联网搜索 ​

json
{
  "model": "seedance-2.5",
  "content": [
    {
      "type": "text",
      "text": "以纪录片风格介绍提示词中指定的城市"
    }
  ],
  "tools": [
    {
      "type": "web_search"
    }
  ],
  "duration": 10,
  "generate_audio": false
}

返回尾帧 ​

json
{
  "model": "seedance-2.0",
  "content": [
    {
      "type": "text",
      "text": "一艘小船抵达安静的码头"
    }
  ],
  "duration": 5,
  "return_last_frame": true,
  "generate_audio": false
}

成功后读取 content.last_frame_url。

MOV 输出 ​

json
{
  "model": "seedance-2.5",
  "content": [
    {
      "type": "text",
      "text": "缓慢俯拍森林树冠"
    }
  ],
  "duration": 8,
  "output_format": "mov",
  "generate_audio": false
}

长镜头 ​

json
{
  "model": "seedance-2.5",
  "content": [
    {
      "type": "text",
      "text": "20秒连续镜头:旅人离开车站,穿过庭院,走近等待的列车"
    }
  ],
  "resolution": "1080p",
  "duration": 20,
  "generate_audio": false
}

2.5 视频编辑与延长 ​

两种模式都需要参考视频和 ratio=adaptive。编辑使用 duration=-1,待编辑视频为 4–30 秒。延长应明确描述后续动作;模式按可用能力提供。

json
{
  "model": "seedance-2.5",
  "content": [
    {
      "type": "text",
      "text": "将视频1的白天场景改为日落"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://example.com/source.mp4"
      },
      "role": "reference_video"
    }
  ],
  "omni_reference_task_type": "edit",
  "ratio": "adaptive",
  "duration": -1,
  "generate_audio": false
}
json
{
  "model": "seedance-2.5",
  "content": [
    {
      "type": "text",
      "text": "接续视频1,主体转身走向大海"
    },
    {
      "type": "video_url",
      "video_url": {
        "url": "https://example.com/source.mp4"
      },
      "role": "reference_video"
    }
  ],
  "omni_reference_task_type": "extend",
  "ratio": "adaptive",
  "duration": 8,
  "generate_audio": false
}

草稿转正式视频 ​

先创建 480p 草稿。成功后以草稿任务 ID 作为 content 唯一元素,输出设为 1080p。正式请求省略继承参数 draft、duration、ratio、seed、generate_audio、omni_reference_task_type、tools、bitrate_mode;草稿不请求尾帧。

json
{
  "model": "seedance-2.5",
  "content": [
    {
      "type": "text",
      "text": "穿过竹林的电影感跟拍镜头"
    }
  ],
  "draft": true,
  "resolution": "480p",
  "duration": 5,
  "generate_audio": false
}
json
{
  "model": "seedance-2.5",
  "content": [
    {
      "type": "draft_task",
      "draft_task": {
        "id": "dfc68868-d388-4d83-a173-d44e47a8bec7"
      }
    }
  ],
  "resolution": "1080p"
}

下一步 ​

官方参考 ​

通过统一接口访问领先的 AI 模型