视频 API
Videos API 视频生成
Videos API 视频生成
功能概览
本页用于说明 Videos API 视频生成 的核心能力、调用入口和接入要点,帮助开发者快速判断适用场景并完成集成。
适用场景
- 产品原型验证:快速接入模型能力,验证内容生成、理解或编辑流程。
- 生产业务接入:用于批量任务、自动化工作流和多模型组合调用。
- 能力迁移适配:适合从原有模型或 SDK 平滑切换到亿速API统一接口。
接入建议
- 优先确认模型名称、请求路径和响应字段,再接入具体业务流程。
- 对异步任务、媒体生成和长耗时请求,建议在业务侧加入重试与状态轮询。
- 上线前建议准备日志追踪、错误兜底和内容安全校验,便于稳定运行。
接口总览
POST /v1/videos
GET /v1/videos/{video_id}
GET /v1/videos/{video_id}/content
当前支持文生视频、图生视频、异步状态查询和视频下载。
POST /v1/videos
创建异步视频生成任务。创建成功后返回视频任务对象,客户端需要轮询状态,完成后再下载内容。
文生视频
curl "/v1/videos" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video",
"prompt": "一只橘猫在舞台上弹钢琴,电影感镜头",
"size": "720x1280",
"seconds": 6,
"n": 1
}'
创建响应示例:
{
"id": "video_req_xxx",
"object": "video",
"created_at": 1710000000,
"status": "queued",
"model": "grok-imagine-video"
}
图生视频
推荐使用 input_reference.image_url 传参考图。
curl "/v1/videos" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video",
"prompt": "让参考图中的主体缓慢转身,背景有轻微风吹动",
"input_reference": {
"image_url": "https://example.com/input.png"
},
"size": "720x1280",
"seconds": 6
}'
data URL 图生视频
curl "/v1/videos" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video",
"prompt": "让参考图中的角色向镜头挥手,电影感光影",
"input_reference": {
"image_url": "data:image/png;base64,..."
},
"size": "1280x720",
"seconds": 6
}'
多图图生视频
推荐使用 input_reference.image_url 数组传多张参考图,最多 6 张。
多图会按数组顺序传入。通常建议把最重要的主体图、首帧图或主参考图放在第 1 张,后续图片用于补充角色、场景、风格、动作或构图参考。
curl "/v1/videos" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video",
"prompt": "参考第1张图的人物主体、第2张图的背景风格,生成自然连贯的电影感镜头。人物从画面左侧走向镜头,背景轻微运动,保持主体一致。",
"input_reference": {
"image_url": [
"https://example.com/person.png",
"https://example.com/background.png"
]
},
"size": "1280x720",
"seconds": 6,
"n": 1
}'
创建成功后返回视频任务对象:
{
"id": "video_req_xxx",
"object": "video",
"created_at": 1710000000,
"status": "queued",
"model": "grok-imagine-video"
}
之后轮询任务状态:
curl "/v1/videos/video_req_xxx" \
-H "Authorization: Bearer <API_TOKEN>"
任务完成后下载视频:
curl "/v1/videos/video_req_xxx/content" \
-H "Authorization: Bearer <API_TOKEN>" \
--output output.mp4
URL 和 data URL 混用
数组里可以同时使用公网图片 URL 和 data:image/...;base64,...。
curl "/v1/videos" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video",
"prompt": "参考多张图片生成视频,保持第1张图主体一致,融合第2张图场景氛围,镜头缓慢推进。",
"input_reference": {
"image_url": [
"https://example.com/input-1.png",
"data:image/png;base64,..."
]
},
"size": "720x1280",
"seconds": 10
}'
顶层兼容写法
推荐新接入优先使用 input_reference.image_url。如果已有客户端更方便传顶层字段,也可以使用 image_urls:
curl "/v1/videos" \
-H "Authorization: Bearer <API_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video",
"prompt": "根据多张参考图生成一段产品展示视频,镜头缓慢推进,突出主体细节。",
"image_urls": [
"https://example.com/product-front.png",
"https://example.com/product-side.png",
"https://example.com/product-scene.png"
],
"size": "1280x720",
"seconds": 6
}'
多图字段说明
| 字段 | 推荐度 | 说明 |
|---|---|---|
input_reference.image_url | 推荐 | 参考图字段,支持单个字符串或最多 6 张图片数组 |
image_urls | 兼容 | 顶层多图数组别名 |
input_images | 兼容 | 顶层多图数组别名 |
images | 兼容 | 顶层多图数组别名 |
image_url | 兼容 | 顶层参考图别名,通常用于单图,也可传数组 |
input_image | 兼容 | 顶层参考图别名,通常用于单图 |
image | 兼容 | 顶层参考图别名,通常用于单图 |
input_reference.file_id | 不支持 | 返回 unsupported_video_input_reference_file |
多图注意事项
- 多图最多
6张,超过会返回invalid_video_image。 - 图片必须是
http(s)URL 或data:image/...;base64,...。 - 当前不支持
file_id。 - 多图顺序有意义,建议把最重要的主体图或首帧图放在第
1张。 - 如果使用公网图片 URL,图片必须能被服务正常访问。
- 视频是异步任务,
POST /v1/videos只创建任务,不直接返回视频文件。 - 任务完成后使用
GET /v1/videos/{video_id}/content下载视频。 - 后台视频测试页如果只提供单图输入,则只会发单张图;多图请优先通过 API 请求测试。
兼容图片字段
除 input_reference.image_url 外,当前也兼容以下顶层图片字段:
image_url
input_image
image
input_image_url
first_frame_image
reference_image
reference_image_url
images
image_urls
input_images
推荐新接入只使用 input_reference.image_url。多图也兼容 images、image_urls、input_images。
参数支持状态
| 参数 | 必填 | 当前支持 | 说明 |
|---|---|---|---|
model | 是 | 支持 | 视频模型名称,示例使用 grok-imagine-video |
prompt | 是 | 支持 | 视频提示词,不能为空,最长 32000 字符 |
size | 否 | 支持 | 未传使用后台视频生成设置中的默认值 |
seconds | 否 | 支持 | 未传使用后台默认值;当前支持 6 或 10 |
n | 否 | 只支持 1 | 不传或传 1;其它值返回 invalid_video_n |
input_reference | 否 | 支持 | 参考图对象 |
input_reference.image_url | 否 | 支持 | http(s) 图片 URL、data:image/...;base64,... 或最多 6 张图片数组 |
input_reference.file_id | 否 | 不支持 | 返回 unsupported_video_input_reference_file |
image_url | 否 | 兼容支持 | 顶层参考图 URL 别名 |
input_image | 否 | 兼容支持 | 顶层参考图输入别名 |
image | 否 | 兼容支持 | 顶层参考图输入别名 |
response_format | 否 | 不支持 | 返回 unsupported_video_response_format |
stream | 否 | 不支持 | 返回 unsupported_video_stream |
支持尺寸
当前支持尺寸由后台视频生成设置控制,代码内置可选值如下:
854x480
480x854
480x480
720x480
480x720
1280x720
720x1280
720x720
1080x720
720x1080
默认尺寸当前为:
1280x720
支持时长
当前支持:
6
10
默认时长当前为:
6
查询视频任务
curl "/v1/videos/video_req_xxx" \
-H "Authorization: Bearer <API_TOKEN>"
响应示例:
{
"id": "video_req_xxx",
"object": "video",
"created_at": 1710000000,
"status": "completed",
"model": "grok-imagine-video"
}
失败响应中的任务对象会包含 error:
{
"id": "video_req_xxx",
"object": "video",
"created_at": 1710000000,
"status": "failed",
"model": "grok-imagine-video",
"error": {
"code": "service_error",
"message": "The service failed to process the request. Please try again."
}
}
如果任务超时,error.code 会是 request_timeout。如果请求可能违反内容规范,error.code 会是 content_policy_violation。如果任务没有产出可用视频,error.code 会是 content_not_returned。
状态值:
queued
in_progress
completed
failed
expired
下载视频内容
curl "/v1/videos/video_req_xxx/content" \
-H "Authorization: Bearer <API_TOKEN>" \
--output output.mp4
如果任务未完成,会返回 video_not_completed。如果文件不存在,会返回 video_content_not_found。
图生视频图片输入格式
支持:
https://example.com/image.png
http://example.com/image.jpg
多图支持数组形式,最多 6 张:
{
"input_reference": {
"image_url": [
"https://example.com/image-1.png",
"data:image/png;base64,..."
]
}
}
也兼容对象形式:
{
"input_reference": {
"image_url": {
"url": "https://example.com/image.png"
}
}
}
也兼容 base64 对象:
{
"input_reference": {
"b64_json": "...",
"mime_type": "image/png"
}
}
缓存和 late final
相同视频请求可能命中结果缓存,命中后会直接创建已完成任务。worker 超时后如果稍后返回 final,网关也会尝试补完成原视频任务。
常见错误
| code | 说明 |
|---|---|
invalid_prompt | prompt 为空或超过长度 |
invalid_video_size | size 不在支持列表中 |
invalid_video_seconds | seconds 不是 6 或 10 |
invalid_video_n | n 不是 1 |
invalid_video_image | 参考图不是 http(s) URL 或图片 data URL |
unsupported_video_input_reference_file | 不支持 input_reference.file_id |
unsupported_video_response_format | 不支持 response_format |
unsupported_video_stream | 不支持 stream |
video_not_found | 视频任务不存在 |
video_not_completed | 视频任务尚未完成 |
video_content_not_found | 视频文件不存在 |
request_timeout | 请求处理超时 |
content_policy_violation | 请求可能违反内容规范,未产出视频 |
content_not_returned | 请求未产出可用视频内容 |
service_error | 视频任务处理失败或生成内容无法处理 |