视频/Sora 视频生成

通过 OpenAI 兼容视频协议使用 Sora 从文本提示生成视频。

Sora 视频生成

通过 UniGateway 使用 Sora 从文本提示生成视频。请求格式为 multipart/form-data

前置条件

  • 已获取 UniGateway API Key,保存在 UNIGATEWAY_API_KEY
  • 已通过 GET /v1/models 确认 Sora 模型可用

接口说明

操作方法路径Content-Type
创建视频POST/v1/videosmultipart/form-data
查询状态GET/v1/videos/{id}
下载视频GET/v1/videos/{id}/content

Base URL: https://api.unigateway.ai/v1

支持的模型

模型 ID说明
sora-2通用视频生成
sora-2-pro高质量视频生成

创建视频

curl -sS -X POST "https://api.unigateway.ai/v1/videos" \
  -H "Authorization: Bearer $UNIGATEWAY_API_KEY" \
  -F 'model=sora-2' \
  -F 'prompt=A cinematic aerial shot of a coastline at golden hour.' \
  -F 'size=1280x720' \
  -F 'seconds=5'

响应:

{
  "id": "task_4kX5fFNCbHgMJLx",
  "object": "video",
  "status": "queued",
  "model": "sora-2",
  "progress": 0,
  "size": "1280x720",
  "seconds": "5"
}

查询视频状态

curl -sS "https://api.unigateway.ai/v1/videos/{id}" \
  -H "Authorization: Bearer $UNIGATEWAY_API_KEY"

响应(处理中):

{
  "id": "task_4kX5fFNCbHgMJLx",
  "object": "video",
  "status": "in_progress",
  "model": "sora-2",
  "progress": 0,
  "size": "1280x720",
  "seconds": "5"
}

响应(已完成):

{
  "id": "task_4kX5fFNCbHgMJLx",
  "object": "video",
  "status": "completed",
  "model": "sora-2",
  "progress": 100,
  "size": "1280x720",
  "seconds": "5",
  "video_url": "https://<your-cdn>/videos/output.mp4"
}

下载视频

curl -sS "https://api.unigateway.ai/v1/videos/{id}/content" \
  -H "Authorization: Bearer $UNIGATEWAY_API_KEY" \
  -o output.mp4

参数说明(创建)

参数必填说明
model模型 ID:sora-2sora-2-pro
prompt期望视频的文字描述
size输出分辨率,例如 1280x720
seconds目标时长(秒),例如 45

轮询策略

  • 创建后 5-10 秒首次查询
  • 随等待时间增长逐步拉大间隔
  • 在调用方设置总超时

Sora 与其他视频模型对比

视频家族Base URL协议Content-Type模型示例
Sorahttps://api.unigateway.ai/v1OpenAI 兼容 /v1/videosmultipart/form-datasora-2
Seedancehttps://video.unigateway.ai/api/v3/contents/generations/tasksapplication/jsondoubao-seedance-2.0-fast

常见错误

状态码原因处理方式
400参数错误或尺寸不支持检查 sizeseconds
401API Key 无效或缺失检查 Authorization 请求头
404模型不存在通过 GET /v1/models 确认
429触发限流增加退避并重试
500服务或上游异常指数退避重试

Example request

Run it in your stack

Pick the SDK style that matches your app and copy the snippet directly into your project.

import requests

key = "<YOUR_UNIGATEWAY_API_KEY>"
resp = requests.post(
    "https://api.unigateway.ai/v1/videos",
    headers={"Authorization": f"Bearer {key}", "Content-Type": "application/json"},
    json={"model": "sora-2", "prompt": "A cinematic aerial shot of a coastline.", "size": "1280x720", "seconds": "5"}
)
print(resp.json())