跳转到主要内容

Documentation Index

Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt

Use this file to discover all available pages before exploring further.

通过选择与您的任务类型匹配的提供商工作流来使用 CometAPI 视频模型文档。大多数视频端点都会创建异步任务,因此请保存任务 ID,并使用轮询来获取结果。仅当对应的模型页面文档说明支持回调时,才添加回调。

选择视频 API

创建 Sora 视频

创建 Sora 视频任务。

获取 Sora 视频

查询 Sora 视频任务。

Runway 图像转视频

从图像生成 Runway 视频。

Kling 文本转视频

根据文本 Prompt 生成 Kling 视频。

Seedance 创建

创建 Seedance 视频任务。

xAI 视频生成

生成 xAI 视频任务。

创建并轮询视频任务

使用来自模型页面模型目录的支持视频的 model ID。下面的示例使用 POST /v1/videos 创建视频任务,然后轮询返回的任务 ID,直到任务进入终态。
这些示例使用占位符 your-video-model-id。在运行请求之前,请将其替换为来自模型页面模型目录的可用视频 model ID。
打开 CreateQuery 以使用 API playground 和端点 schema。
import os
import time
import requests

headers = {"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]}

create_response = requests.post(
    "https://api.cometapi.com/v1/videos",
    headers=headers,
    data={
        "model": "your-video-model-id",
        "prompt": "A calm camera move across a desk with a paper airplane",
    },
    timeout=30,
)
create_response.raise_for_status()
task = create_response.json()
task_id = task["id"]

terminal_statuses = {"completed", "failed", "error"}

while True:
    poll_response = requests.get(
        f"https://api.cometapi.com/v1/videos/{task_id}",
        headers=headers,
        timeout=30,
    )
    poll_response.raise_for_status()
    result = poll_response.json()
    print(result["status"], result.get("progress"))

    if result["status"] in terminal_statuses:
        print(result.get("video_url"))
        break

    time.sleep(10)

响应示例

成功的创建响应可能如下所示。在开始轮询之前,请先保存任务 ID:
{
  "id": "task_example",
  "task_id": "task_example",
  "object": "video",
  "model": "your-video-model-id",
  "status": "queued",
  "progress": 0,
  "created_at": 1779872000
}
成功的轮询响应可能如下所示。已完成的响应中可能包含 video_url;某些提供商格式会使用模型特定的结果字段,或在该路由有文档说明时使用视频内容路由:
{
  "id": "task_example",
  "object": "video",
  "model": "your-video-model-id",
  "status": "completed",
  "progress": 100,
  "completed_at": 1779872300,
  "video_url": "https://example.com/generated-video.mp4"
}

model 记录示例

此示例模型目录响应展示了 /api/models 的响应外层结构以及一种视频模型记录的格式。它不是完整的模型列表。
cURL
curl https://api.cometapi.com/api/models
{
  "success": true,
  "page": 1,
  "page_size": 20,
  "total": 302,
  "data": [
    {
      "created": 1767529753,
      "id": "your-video-model-id",
      "code": "your-video-model-id",
      "provider": "ExampleProvider",
      "provider_code": "example",
      "name": "Example video model",
      "model_type": "video",
      "features": [
        "text-to-video"
      ],
      "endpoints": "{\n  \"seedance\": {\n    \"path\": \"/v1/videos\",\n    \"method\": \"POST\"\n  }\n}",
      "pricing": {
        "currency": "USD / M Tokens",
        "input": null,
        "output": null,
        "per_request": null,
        "per_second": 0.024
      }
    }
  ]
}

常见错误

在从您的任务处理程序返回之前,先保存创建响应中的 ID。
在状态检查之间添加延迟和退避。
使用所选视频端点文档中说明的 duration 和 resolution 字段。
video_url 视为可选字段,并在可用时回退到模型特定的结果字段或内容路由。
使用轮询作为事实来源,并验证您的回调 URL 能够接受 POST 请求。

错误代码与重试策略

在修复 prompt、文件、duration 或 size 字段之前,不要重试。
在 API key 已存在且有效之前,不要重试。
重试之前,请检查任务 ID、base URL、path 和 model ID。
重试之前请减小上传大小。
使用指数退避进行重试,并降低创建或轮询的并发度。
使用退避重试任务创建;除非任务进入终态错误,否则继续轮询现有任务。

价格与模型目录

模型页面

了解 CometAPI 如何在文档中展示 model ID。

模型目录

浏览模型可用性和能力。

价格

在调用模型之前查看价格。
Last modified on May 28, 2026