CokeAPI
视频生成系列

Sora 2 Official

OpenAI Sora 2 Azure 官方版视频生成,1280x720,支持 4/8/12 秒时长,文生视频与图生视频。

CokeAPI 接入 OpenAI Sora 2 Azure 官方版视频模型。默认是异步任务: POST 创建后拿到 task_id,再通过 GET /v1/generations/{task_id} 轮询直到 succeeded

图生视频提示:生成接口不再接收内联 base64 图片数据。请先使用 文件上传接口 上传参考图片获取 URL,再传入 image_urls

模型 ID: sora-2-official

调用示例

curl https://cokeapi.com/v1/video/generations \
  -H "Authorization: Bearer sk-xxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sora-2-official",
    "prompt": "一只橘猫在雪地中奔跑,电影级画面,超高清",
    "aspect_ratio": "16:9",
    "duration": 8
  }'
curl https://cokeapi.com/v1/video/generations \
  -H "Authorization: Bearer sk-xxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sora-2-official",
    "prompt": "镜头缓慢推进,主体转身面向镜头",
    "image_urls": ["https://cdn.cokeapi.com/uploads/2026/05/17/photo.png"],
    "aspect_ratio": "16:9",
    "duration": 4
  }'
TASK_ID="01HX..."
curl https://cokeapi.com/v1/generations/$TASK_ID \
  -H "Authorization: Bearer sk-xxxxxxxx"
import httpx, time

BASE = "https://cokeapi.com/v1"
HEADERS = {"Authorization": "Bearer sk-xxxxxxxx"}

r = httpx.post(
    f"{BASE}/video/generations",
    headers=HEADERS,
    json={
        "model": "sora-2-official",
        "prompt": "一只橘猫在雪地中奔跑,电影级画面",
        "aspect_ratio": "16:9",
        "duration": 8,
    },
    timeout=60,
)
task_id = r.json()["id"]

while True:
    r = httpx.get(f"{BASE}/generations/{task_id}", headers=HEADERS, timeout=30)
    data = r.json()
    if data["status"] in ("succeeded", "failed", "refunded"):
        print(data)
        break
    time.sleep(5)
const BASE = "https://cokeapi.com/v1";
const KEY = process.env.COKEAPI_KEY;

const create = await fetch(`${BASE}/video/generations`, {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "sora-2-official",
    prompt: "一只橘猫在雪地中奔跑,电影级画面",
    aspect_ratio: "16:9",
    duration: 8,
  }),
});
const { id: taskId } = await create.json();

while (true) {
  const poll = await fetch(`${BASE}/generations/${taskId}`, {
    headers: { "Authorization": `Bearer ${KEY}` },
  });
  const data = await poll.json();
  if (["succeeded", "failed", "refunded"].includes(data.status)) {
    console.log(data);
    break;
  }
  await new Promise((r) => setTimeout(r, 5000));
}

请求参数

参数类型必填默认值说明
modelstringsora-2-official
promptstring视频描述文本
durationint8时长秒数: 4 / 8 / 12
aspect_ratiostring16:916:9 / 9:16
image_urlsstring[]参考图片 URL 列表,用于图生视频
seedint随机种子,可复现结果
asyncbooltrue是否立即返回任务态
callback_urlstring任务完成时 POST 回调到此 URL

响应

创建任务 (POST)

{
  "id": "01HX...",
  "task_id": "01HX...",
  "object": "video.generation.task",
  "status": "queued",
  "progress": 0,
  "model": "sora-2-official",
  "kind": "video",
  "mode": "text_to_video",
  "created": 1714200000
}

查询任务 (GET /v1/generations/{task_id})

进行中:

{
  "id": "01HX...",
  "task_id": "01HX...",
  "object": "video.generation.task",
  "status": "running",
  "progress": 45,
  "model": "sora-2-official",
  "kind": "video",
  "mode": "text_to_video",
  "created": 1714200000
}

完成后:

{
  "id": "01HX...",
  "task_id": "01HX...",
  "object": "video.generation.task",
  "status": "succeeded",
  "progress": 100,
  "model": "sora-2-official",
  "kind": "video",
  "mode": "text_to_video",
  "result": {
    "id": "01HX...",
    "object": "video.generation",
    "created": 1714200000,
    "model": "sora-2-official",
    "data": [
      {
        "url": "https://cdn.cokeapi.com/v/01HX....mp4",
        "duration_ms": 8000,
        "width": 1280,
        "height": 720
      }
    ]
  },
  "created": 1714200000
}

Sora 2 任务平均耗时 60-180 秒。推荐每 5 秒轮询一次。也可以在创建时传 callback_url,任务完成后主动 POST 推送结果。超过 15 分钟仍未完成会自动标记为 failed 并退款。统一查询入口见 异步任务

计费

按任务固定计费,不区分分辨率。以 6 秒为基准档,超过 6 秒按 10 秒档计费(费用 = 基准价 × 10/6)。

计费档位价格
6 秒基准价$0.128
10 秒价$0.213

实际可选时长为 4/8/12 秒;4 秒按 6 秒基准价计费,8/12 秒按 10 秒档计费。

失败任务不计费,自动退款。价格为 2026-07 快照,以 模型列表页 实时价目为准。

注意事项

  • 任务最长保留 24 小时,超过会被清理。需要长期存储请下载到自有 OSS
  • 图生视频请先通过 文件上传接口 上传参考图片获取 URL,再通过 image_urls 传入
  • Azure 官方通道,稳定性更高
  • 失败的任务不计费,会自动返还预扣点数

本页目录