> ## 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.