Appearance
Videos 视频生成 (Sora)
OpenAI 兼容的视频生成接口。
参考文档: https://platform.openai.com/docs/api-reference/videos
创建视频
POST /v1/videos
提交视频生成任务,支持文生视频和图生视频。返回任务 ID 用于轮询状态。
认证
使用 Bearer Token 认证,格式: Authorization: Bearer sk-xxxxxx
请求体 (multipart/form-data)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 否 | 模型/风格 ID(如 sora、kling-v1) |
| prompt | string | 否 | 文本描述提示词 |
| image | string | 否 | 图片输入(URL 或 Base64) |
| duration | number | 否 | 视频时长(秒),如 5 |
| width | integer | 否 | 视频宽度,如 1280 |
| height | integer | 否 | 视频高度,如 720 |
| fps | integer | 否 | 视频帧率,如 30 |
| seed | integer | 否 | 随机种子 |
| n | integer | 否 | 生成视频数量 |
| response_format | string | 否 | 响应格式,如 url |
| user | string | 否 | 用户标识 |
| metadata | object | 否 | 扩展参数(如 negative_prompt、style、quality_level) |
请求示例
bash
curl -X POST "https://your-api-base/v1/videos" \
-H "Authorization: Bearer sk-xxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "sora",
"prompt": "A cat walking on the beach at sunset",
"duration": 5,
"width": 1280,
"height": 720
}'python
import requests
response = requests.post(
"https://your-api-base/v1/videos",
headers={"Authorization": "Bearer sk-xxxxxx"},
json={
"model": "sora",
"prompt": "A cat walking on the beach at sunset",
"duration": 5,
"width": 1280,
"height": 720
}
)
print(response.json())200 成功响应
json
{
"id": "video_abc123",
"object": "video",
"model": "sora",
"status": "queued",
"task_id": "abcd1234efgh"
}获取视频任务状态
GET /v1/videos/{task_id}
查询视频生成任务的详细状态。
路径参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| task_id | string | 是 | 任务 ID |
请求示例
bash
curl -X GET "https://your-api-base/v1/videos/abcd1234efgh" \
-H "Authorization: Bearer sk-xxxxxx"200 成功响应
json
{
"id": "video-abc123",
"task_id": "abcd1234efgh",
"object": "video",
"model": "sora",
"status": "completed",
"progress": 100,
"created_at": 1677858242,
"completed_at": 1677858300,
"expires_at": 1677944642,
"url": "https://example.com/video.mp4",
"format": "mp4",
"metadata": {
"duration": 5,
"fps": 30,
"width": 1280,
"height": 720,
"seed": 20231234
}
}status 可能的值:
| 状态 | 说明 |
|---|---|
| queued | 排队中 |
| in_progress | 生成中 |
| completed | 已完成 |
| failed | 生成失败 |
失败响应
json
{
"task_id": "abcd1234efgh",
"status": "failed",
"error": {
"code": 500,
"message": "Video generation failed"
}
}获取视频内容
GET /v1/videos/{task_id}/content
获取生成的视频文件内容,直接返回视频文件数据。
路径参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| task_id | string | 是 | 任务 ID |
请求示例
bash
curl -X GET "https://your-api-base/v1/videos/abcd1234efgh/content" \
-H "Authorization: Bearer sk-xxxxxx" \
--output video.mp4响应
直接返回视频文件二进制内容。
备用端点
以下端点也可用于视频生成任务:
| 端点 | 方法 | 说明 |
|---|---|---|
/v1/video/generations | POST | 创建视频生成任务 |
/v1/video/generations/{task_id} | GET | 获取视频生成任务状态 |