Claude Opus 5.5 已在 SeedRouter 上线

Seedance API 使用教程:API Key、请求、轮询与参考素材

一步步调用 Seedance API:创建 API Key、发送视频任务、轮询拿到视频 URL、添加图片/视频/音频参考素材,以及交给编程 Agent 执行。

以 Markdown 阅读

调用 Seedance API 的步骤是:创建 API Key,把官方 ModelArk 视频任务请求体发送到一个端点,然后轮询返回的任务,直到视频 URL 就绪。同样的步骤适用于 Seedance 2.0、Seedance 2.0 Fast、Seedance 2.0 Mini 和 Seedance 2.5;只有 model 的值和少数模型专属限制不同。

本教程用可运行的代码逐步讲解每一步,然后介绍如何添加参考素材、如何用 Seedance 2.5 编辑片段,以及如何把任务交给编程 Agent。

发送第一个请求前需要准备什么?

  1. 一个 API Key。 在 API Key 页面创建,并保存在你的服务端。绝不要把它放进浏览器端代码。
  2. 额度。 在账单页充值余额。额度永不过期,失败的任务不收费。
  3. 一个模型 ID。 从下表中选择一个。
模型 ID模型分辨率片段时长
dreamina-seedance-2-0Seedance 2.0480p 到 4K4–15 秒
dreamina-seedance-2-0-fastSeedance 2.0 Fast480p、720p4–15 秒
dreamina-seedance-2-0-miniSeedance 2.0 Mini480p、720p4–15 秒
dreamina-seedance-2-5Seedance 2.5480p 到 1080p4–30 秒

不确定选哪个?Seedance 2.0、Fast 与 Mini 对比指南和 Seedance 2.5 与 2.0 对比指南对它们做了比较。

export SEEDROUTER_API_KEY="your-key"

如何发送 Seedance 请求?

把任务 POST 到 /v1/contents/generations/tasks。请求体就是官方 ModelArk 的"创建视频生成任务"请求:

curl https://api.seedrouter.ai/v1/contents/generations/tasks \
  -H "Authorization: Bearer $SEEDROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dreamina-seedance-2-0",
    "content": [{"type": "text", "text": "A red paper boat drifts across a calm pond at sunrise, slow dolly-in"}],
    "resolution": "720p",
    "ratio": "16:9",
    "duration": 5,
    "generate_audio": true
  }'

响应是一个任务 ID,而不是视频:

{"id": "task_..."}

如果你已经在调用 ModelArk,只需把 base URL 改为 https://api.seedrouter.ai/v1,并换成对应的 API Key。未知字段会在任何扣费之前被拒绝,模型不支持的设置同样如此,例如在 Fast 或 Mini 上使用 1080p。

如何拿到生成的视频?

每隔 10 到 20 秒轮询一次任务,直到 status 变为 succeeded、failed 或 expired。一个 5 秒 720p 片段通常需要两到三分钟。Python 示例:

import os
import time
import requests

API = "https://api.seedrouter.ai/v1"
headers = {"Authorization": f"Bearer {os.environ['SEEDROUTER_API_KEY']}"}

response = requests.post(
    f"{API}/contents/generations/tasks",
    headers=headers,
    json={
        "model": "dreamina-seedance-2-0",
        "content": [{"type": "text", "text": "A red paper boat drifts across a calm pond at sunrise, slow dolly-in"}],
        "resolution": "720p",
        "ratio": "16:9",
        "duration": 5,
    },
    timeout=60,
)
response.raise_for_status()
task_id = response.json()["id"]

deadline = time.monotonic() + 1800
while time.monotonic() < deadline:
    result = requests.get(f"{API}/contents/generations/tasks/{task_id}", headers=headers, timeout=30)
    result.raise_for_status()
    task = result.json()
    if task["status"] == "succeeded":
        print(task["content"]["video_url"])
        break
    if task["status"] in ("failed", "expired"):
        raise RuntimeError(task["error"]["message"])
    time.sleep(15)
else:
    raise TimeoutError(f"Still waiting. Resume polling task {task_id}.")

成功的任务在 content.video_url 中给出视频,在 usage.completion_tokens 中给出计费的视频 token,并给出实际渲染时使用的设置,包括模型选用的 seed。视频托管在我们的存储上;如需长期保存,请下载到你自己的存储中。

轮询超时并不意味着视频生成失败。请保留任务 ID 并再次查询;提交新任务就意味着要为第二段视频付费。没有回调 URL,所以轮询是获取结果的方式,且已提交的任务无法取消。

如何添加图片、视频和音频?

在 content 中添加条目,每个条目带一个公开 URL 和一个 role:

curl https://api.seedrouter.ai/v1/contents/generations/tasks \
  -H "Authorization: Bearer $SEEDROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dreamina-seedance-2-0",
    "content": [
      {"type": "text", "text": "The character from the image walks through the market in the video, same camera move"},
      {"type": "image_url", "image_url": {"url": "https://example.com/character.png"}, "role": "reference_image"},
      {"type": "video_url", "video_url": {"url": "https://example.com/market.mp4"}, "role": "reference_video"}
    ],
    "ratio": "adaptive",
    "duration": 8
  }'
模式content 中放什么
文生视频一个文本条目
首帧文本加一张 role 为 first_frame 的图片
首尾帧文本加一张 first_frame 图片和一张 last_frame 图片
参考素材文本加任意组合的 reference_image、reference_video 和 reference_audio

Seedance 2.0 及其 Fast、Mini 版本最多接受 9 张参考图、3 段视频和 3 段音频;Seedance 2.5 最多接受 30、10 和 10。媒体必须是 URL:不接受 base64 和文件上传。模型不支持包含真人面部的参考图和参考视频。媒体在任务开始时检查,违反限制的文件会让任务在生成之前失败,不收费。

如何用 Seedance 2.5 编辑或延长片段?

把片段作为 reference_video 发送,并设置 omni_reference_task_type:

{
  "model": "dreamina-seedance-2-5",
  "content": [
    {"type": "text", "text": "Change the jacket to red. Keep everything else the same."},
    {"type": "video_url", "video_url": {"url": "https://example.com/clip.mp4"}, "role": "reference_video"}
  ],
  "omni_reference_task_type": "edit"
}

用 edit 修改素材中的内容,用 extend 让它在最后一帧之后继续。使用 edit 时,让 duration 保持默认值 -1;两种模式下都让 ratio 保持为 adaptive。输入秒数按参考费率计费,详见价格指南。

如何让编程 Agent 调用 Seedance API?

Claude Code、Codex 或 Cursor 这类编程 Agent 可以通过 shell 命令或一段简短脚本调用 API。SeedRouter 不提供 MCP server、打包好的 skill 或 ComfyUI 节点;下面这段提示词就是全部的接入方式。先导出 Key,然后粘贴:

Use the SeedRouter API to generate a Seedance video for me.

Security: read SEEDROUTER_API_KEY from my local environment. Never ask me to paste it and never print it.

Goal: [subject, action, camera move, lighting, what the clip is for]
Model: [dreamina-seedance-2-0 | dreamina-seedance-2-0-fast | dreamina-seedance-2-0-mini | dreamina-seedance-2-5]
Resolution: [480p | 720p | 1080p | 4k]    Ratio: [16:9 | 9:16 | 1:1 | adaptive]    Duration: [seconds]
References: [public image, video or audio URLs with their roles, or none]

Send POST https://api.seedrouter.ai/v1/contents/generations/tasks with
{"model": "...",
 "content": [{"type": "text", "text": "..."}],
 "resolution": "...", "ratio": "...", "duration": 5}
Media goes in content as image_url, video_url or audio_url items with a role,
never base64. Do not add fields that are not in the API reference.

Before sending, show me the request body and wait for my approval: each
task is charged. Then poll GET https://api.seedrouter.ai/v1/contents/generations/tasks/{id}
every 15 seconds until status is succeeded, failed or expired. If polling
times out, keep checking the same task; never resubmit. Save
content.video_url into ./videos/ and tell me the file path.

审批这一步很重要:Agent 花的是你的余额,所以它绝不应该自行提交。

常见问题

如何获取 Seedance API Key?

登录后打开 API Key 页面并创建一个 Key。同一个 Key 适用于所有 Seedance 模型,以及 SeedRouter 上的其他模型。

Seedance API 文档在哪里?

Seedance 2.0 和 Seedance 2.5 API 文档列出了每个字段、限制和错误,附 cURL、Python、Node.js 和 Go 示例,另有 OpenAPI 文件和可复制的 Markdown 版本。

可以一次生成多个视频吗?

每个视频发送一个任务,并并行轮询这些任务。每个任务返回一个视频,并单独计费。要列出最近的任务,调用 GET /v1/contents/generations/tasks,带上 page_num、page_size 以及 filter.status 等筛选条件。

需要处理哪些错误?

400 表示请求体违反了某条规则,例如未知字段或不支持的分辨率,不会扣费。以 failed 或 expired 结束的任务会带有错误码和错误信息,同样不收费。错误指南列出了每个错误码以及何时重试。

发送你的第一个请求

创建一个 Key,充值少量余额,然后运行上面的 Python 示例;或者在 Seedance 2.0 playground 中无需写代码试试同一个请求。需要更长的片段和编辑功能时,把模型改为 dreamina-seedance-2-5,并查看 Seedance 2.5 页面。

相关指南