> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloudsome-inc.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 影片快速生成

建立任務 → 查詢狀態 → 取得影片連結。替換 API Key，確認已開通範例模型及 videos 權限，即可生成一段 5 秒、720p 的影片；無需先上傳素材或呼叫估價介面。

> [tab] Python
>
> 先執行 pip install requests，再複製執行以下 Python 範例，自動查詢並輸出影片連結。
>
> ```python theme={null}
> import time
> import requests
>
> BASE = "https://api.cloudsome-inc.ai/v1"
> HEADERS = {"Authorization": "Bearer sk_live_your_key_here"}
>
> response = requests.post(f"{BASE}/videos", headers=HEADERS, json={
>     "model": "dreamina-seedance-2.5",
>     "prompt": "A golden retriever running on the beach at sunset",
>     "duration": 5,
>     "resolution": "720p",
> }, timeout=60)
> response.raise_for_status()
> task_id = response.json()["tasks"][0]["id"]
> print("Task ID:", task_id)
>
> for _ in range(120):
>     response = requests.get(f"{BASE}/videos/{task_id}", headers=HEADERS, timeout=30)
>     response.raise_for_status()
>     task = response.json()
>     if task["status"] == "completed":
>         url = task.get("download_url") or task.get("url")
>         if not url:
>             raise RuntimeError(f"Video URL unavailable; query task {task_id} again.")
>         print(url)
>         break
>     if task["status"] in ("failed", "cancelled", "expired"):
>         raise RuntimeError(task.get("error") or task["status"])
>     time.sleep(5)
> else:
>     raise TimeoutError(f"Keep querying task {task_id}; do not create it again.")
> ```

> [tab] Node.js
>
> 使用 Node.js 18+，將範例儲存為 video.mjs，執行 node video.mjs，自動查詢並輸出影片連結。
>
> ```javascript theme={null}
> const BASE = "https://api.cloudsome-inc.ai/v1";
> const headers = {
>   Authorization: "Bearer sk_live_your_key_here",
>   "Content-Type": "application/json",
> };
>
> async function request(path, options = {}) {
>   const response = await fetch(BASE + path, {
>     ...options, headers, signal: AbortSignal.timeout(60_000),
>   });
>   if (!response.ok) throw new Error(await response.text());
>   return response.json();
> }
>
> const batch = await request("/videos", {
>   method: "POST",
>   body: JSON.stringify({
>     model: "dreamina-seedance-2.5",
>     prompt: "A golden retriever running on the beach at sunset",
>     duration: 5,
>     resolution: "720p",
>   }),
> });
> const taskId = batch.tasks[0].id;
> console.log("Task ID:", taskId);
>
> for (let attempt = 0; ; attempt++) {
>   if (attempt === 120) throw new Error("Keep querying task " + taskId + "; do not create it again.");
>   const task = await request("/videos/" + taskId);
>   if (task.status === "completed") {
>     const url = task.download_url || task.url;
>     if (!url) throw new Error("Video URL unavailable; query task " + taskId + " again.");
>     console.log(url);
>     break;
>   }
>   if (["failed", "cancelled", "expired"].includes(task.status)) {
>     throw new Error(JSON.stringify(task.error || task.status));
>   }
>   await new Promise((resolve) => setTimeout(resolve, 5000));
> }
> ```

> [tab] cURL
>
> 先執行第一條命令建立任務，再將回應中的 tasks\[0].id 填入第二條命令的 VIDEO\_ID（不要使用頂層批次 id）。每隔約 5 秒重複第二條命令，直到 status 為 completed、failed、cancelled 或 expired。
>
> ```bash theme={null}
> curl --fail-with-body -sS https://api.cloudsome-inc.ai/v1/videos \
>   -H "Authorization: Bearer sk_live_your_key_here" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "model": "dreamina-seedance-2.5",
>     "prompt": "A golden retriever running on the beach at sunset",
>     "duration": 5,
>     "resolution": "720p"
>   }'
>
> curl --fail-with-body -sS https://api.cloudsome-inc.ai/v1/videos/VIDEO_ID \
>   -H "Authorization: Bearer sk_live_your_key_here"
> ```

成功後開啟 download\_url 或 url 即可下載，失敗原因見 error。連結有效期為 15 分鐘，過期後重新查詢任務即可。儲存任務 ID；腳本達到查詢次數上限或查詢中斷時，繼續查詢原任務，不要重新建立。

任務 stage 區分 waiting\_submission、submitting、upstream\_queued、generating、saving、completed、failed 與 verification\_pending。原有 status 及費用欄位維持相容。request\_id 為請求 ID；created\_at 與 completed\_at 是平台觀測時間，不代表模型計算或瀏覽器首幀時間。處理或結算未完成時每 5 秒查詢一次，完成且結算後停止輪詢。

儲存階段 save\_retrying=true 表示正在重試儲存，請繼續查詢原任務。僅 status=failed 且 retryable=true 的任務可使用新冪等鍵及 n=1 重新生成，並按新請求計費。error.category 區分輸入審核、輸出審核及版權限制，error.provider\_code 保留上游原始錯誤碼。佇列滿額或限流回傳 429，請稍後重試。提交結果不明及用量不完整需等待核實，不會自動重新生成。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.