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 並再次查詢;提交新任務就意味著要為第二段影片付費。目前沒有 callback 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 伺服器、封裝好的 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 頁面。

相關指南