Sora-2(创建视频)
POST v1/videov1/videos 接口核心必选参数为 model/prompt/duration/resolution,其余为可选增强配置;
prompt 支持精细化描述(时长、镜头、风格、氛围),是视频生成效果的核心控制项;
不同 Sora-2 版本对应不同的时长 / 分辨率上限,需匹配参数避免报错;
input_media 可传入参考素材,weight 参数控制素材参考程度,适合定制化场景;
异步场景建议配置 webhook_url,同步场景直接接收返回的视频 URL 即可。
请求参数
Authorization
在 Header 添加参数 Authorization,其值为在 Bearer 之后拼接 Token。
Authorization: Bearer ******************Body 参数
Content-Type: application/json
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 必需 | 模型 ID。指定使用的视频生成模型版本。 |
| prompt | string | 必需 | 提示词。描述期望生成的视频内容、动作和场景。 |
| duration | integer | 必需 | 视频时长。生成视频的持续时间(通常以秒为单位)。 |
| resolution | string | 必需 | 分辨率。视频的清晰度规格(例如 "1024x576", "720p")。 |
| fps | integer | 必需 | 帧率。每秒显示的帧数,影响视频的流畅度。 |
| style_preset | string | 必需 | 风格预设。预定义的视觉风格标签(例如 "cinematic", "anime", "3d-model")。 |
| aspect_ratio | string | 必需 | 宽高比。视频画面的比例(例如 "16:9", "9:16")。 |
| guidance_scale | integer | 必需 | 引导系数。控制模型对提示词的遵循程度,值越高越贴合提示词但可能降低多样性。 |
| response_format | string | 必需 | 响应格式。指定返回数据的格式(如 "mp4", "gif" 或数据编码格式)。 |
| num_variations | integer | 必需 | 变体数量。一次性生成的视频版本数量,便于用户从中挑选最佳结果。 |
请求示例 (JSON)
{
"model": "sora-2",
"prompt": "A realistic 1080p video of a surfer riding a wave at sunrise, ocean waves crash gently, golden light on the water, camera follows the surfer from behind, 30 seconds long, calm and peaceful atmosphere",
"duration": 30,
"resolution": "1080p",
"fps": 30,
"style_preset": "cinematic",
"aspect_ratio": "16:9",
"guidance_scale": 8.0,
"response_format": "mp4",
"num_variations": 1
}返回响应
200 成功
Content-Type: application/json
响应参数
| 字段名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | string | 必需 | 任务 ID。本次生成任务的唯一标识符。 |
| object | string | 必需 | 对象类型。通常为 "video.generation"。 |
| created | integer | 必需 | 创建时间戳。任务创建时的 Unix 时间戳。 |
| model | string | 必需 | 模型名称。执行此任务的模型 ID(例如 veo-3.1-generate-preview)。 |
| status | string | 必需 | 最终状态。此时应为 "SUCCEEDED" 或 "COMPLETED"。 |
| data | array [object] | 必需 | 结果数据数组。包含生成的视频文件信息。 |
| ├─ video_id | string | 可选 | 视频 ID。视频资源的内部标识符。 |
| ├─ url | string | 可选 | 视频下载链接。生成的视频文件的访问地址。 |
| ├─ expires_at | integer | 可选 | 过期时间戳。链接失效的时间。 |
| ├─ format | string | 可选 | 文件格式。例如 "mp4"。 |
| ├─ resolution | string | 可选 | 分辨率。例如 "1920x1080"。 |
| ├─ duration_actual | integer | 可选 | 实际时长。视频的实际播放时长(秒)。 |
| ├─ fps | integer | 可选 | 帧率。每秒帧数。 |
| ├─ aspect_ratio | string | 可选 | 宽高比。例如 "16:9"。 |
| ├─ size_bytes | integer | 可选 | 文件大小。视频文件占用的字节数。 |
| └─ variation_index | integer | 可选 | 变体索引。如果是批量生成多个视频,表示这是第几个。 |
| metadata | object | 可选 | 元数据。包含生成时的配置信息。 |
| ├─ prompt | string | 必需 | 提示词。用于生成视频的原始文本提示。 |
| ├─ negative_prompt | string | 必需 | 反向提示词。生成时使用的负面提示词。 |
| ├─ style | string | 必需 | 风格。使用的风格预设。 |
| ├─ seed | integer | 必需 | 种子值。生成时使用的随机种子。 |
| └─ guidance_scale | integer | 必需 | 引导系数。生成时使用的引导比例。 |
| generation_time_seconds | number | 必需 | 生成耗时。实际处理该任务花费的时间(秒)。 |
| usage | object | 必需 | 用量统计。关于 Token 消耗的统计信息。 |
| ├─ prompt_tokens | integer | 必需 | 提示词 Token。输入文本消耗的 Token 数。 |
| ├─ video_tokens | integer | 必需 | 视频 Token。生成视频内容消耗的 Token 数。 |
| ├─ total_tokens | integer | 必需 | 总 Token 数。此次请求的总消耗量。 |
| └─ duration_billed_seconds | integer | 必需 | 计费时长。用于计费的视频时长(秒)。 |
| error | null | 必需 | 错误信息。如果成功则为 null;如果失败则包含错误详情。 |
响应示例
{
"id": "video-8e7b9c2d1a3f4e5d8b7a6c9e8b7d6a5f",
"object": "video.completion",
"created": 1735689600,
"model": "sora-2",
"status": "completed",
"data": [
{
"video_id": "vid-1234567890abcdef",
"url": "https://oaidalleapiprodscus.blob.core.windows.net/private/org-xxxx/user-xxxx/video-8e7b9c2d1a3f4e5d8b7a6c9e8b7d6a5f.mp4?se=2026-02-13T08%3A00%3A00Z&sig=xxxx&sp=r&sr=b&sv=2021-08-06",
"expires_at": 1736899200,
"format": "mp4",
"metadata": {
"resolution": "1080p",
"duration": 30.0,
"fps": 30,
"aspect_ratio": "16:9",
"style_preset": "cinematic",
"camera_movement": "tracking",
"seed": 458921763,
"guidance_scale": 8.0
},
"size_bytes": 185423987,
"variation_index": 0
}
],
"usage": {
"prompt_tokens": 128,
"video_tokens": 45600,
"total_tokens": 45728,
"duration_seconds_billed": 30
},
"metadata": {
"prompt": "A realistic 1080p video of a surfer riding a wave at sunrise, ocean waves crash gently, golden light on the water, camera follows the surfer from behind, 30 seconds long, calm and peaceful atmosphere",
"generation_time_seconds": 45.2,
"model_version": "sora-2-202601"
},
"error": null
}示例代码
python
import http.client
import json
conn = http.client.HTTPSConnection("nxaiapp.com")
payload = json.dumps({
"model": "sora-2",
"prompt": "A realistic 1080p video of a surfer riding a wave at sunrise, ocean waves crash gently, golden light on the water, camera follows the surfer from behind, 30 seconds long, calm and peaceful atmosphere",
"duration": 30,
"resolution": "1080p",
"fps": 30,
"style_preset": "cinematic",
"aspect_ratio": "16:9",
"guidance_scale": 8,
"response_format": "mp4",
"num_variations": 1
})
headers = {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
}
conn.request("POST", "/v1/videos", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))