Grok Imagine Video
grok-imagine-video-1.5-preview 使用 OpenAI 兼容的视频任务接口。该模型是图生视频模型,请求必须带至少一张参考图。
接口地址
| 能力 | 方法 | 路径 |
|---|---|---|
| 创建视频任务 | POST | /v1/videos |
| 查询视频任务 | GET | /v1/videos/{video_id} |
| 下载视频文件 | GET | /v1/videos/{video_id}/content |
支持模型
| 模型 | 说明 |
|---|---|
grok-imagine-video-1.5-preview | Grok Imagine 1.5 预览版图生视频模型,必须提供图片输入 |
实际可用模型以账户权限和平台配置为准。
支持模式
| 模式 | 输入方式 |
|---|---|
| 图生视频 | JSON 请求中使用 input_reference、image 或 image_url |
| 多图参考 | input_reference 数组,或 multipart 中重复传 input_reference[] |
| 文件上传 | multipart/form-data,字段名为 input_reference[] |
该模型不支持纯文生视频请求。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 固定使用 grok-imagine-video-1.5-preview |
prompt | string | 是 | 视频生成描述 |
seconds | string 或 integer | 否 | 视频时长,支持 6、10、12、16、20,默认 6 |
size | string | 否 | 视频尺寸,默认 720x1280 |
resolution_name | string | 否 | 清晰度,可选 480p、720p;不传时根据 size 自动选择 |
preset | string | 否 | 风格预设,可选 custom、normal、fun、spicy,默认 custom |
input_reference | string、object 或 array | 是 | JSON 请求中的参考图输入,支持图片 URL 或 data URI |
image | string 或 object | 否 | 单张参考图,等价于单图 input_reference |
image_url | string | 否 | 单张参考图 URL,等价于单图 input_reference |
input_reference[] | file[] | 是 | multipart/form-data 请求中的参考图文件字段,最多使用前 7 张 |
input_reference、image、image_url、input_reference[] 至少提供一种。grok-imagine-video-1.5-preview 不支持纯文生视频请求。
支持尺寸
size | 比例 | 默认清晰度 |
|---|---|---|
720x1280 | 9:16 | 720p |
1280x720 | 16:9 | 720p |
1024x1024 | 1:1 | 720p |
1024x1792 | 9:16 | 720p |
1792x1024 | 16:9 | 720p |
调用示例
JSON 请求
bash
curl -X POST https://cubicspaces.cloud/v1/videos \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "grok-imagine-video-1.5-preview",
"prompt": "A gentle cinematic camera push over the reference image, soft light, realistic motion",
"seconds": "6",
"size": "720x1280",
"preset": "custom",
"input_reference": {
"image_url": "https://example.com/reference.png"
}
}'也可以直接传单张图片 URL:
json
{
"model": "grok-imagine-video-1.5-preview",
"prompt": "Make the product slowly rotate in a clean studio scene",
"seconds": "10",
"size": "1280x720",
"image_url": "https://example.com/product.png"
}文件上传
使用 multipart/form-data 时,参考图字段名为 input_reference[]:
bash
curl -X POST https://cubicspaces.cloud/v1/videos \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=grok-imagine-video-1.5-preview" \
-F "prompt=A cinematic product shot with a slow dolly move" \
-F "seconds=6" \
-F "size=720x1280" \
-F "preset=custom" \
-F "input_reference[]=@reference.png"多张参考图可以重复传 input_reference[],系统最多使用前 7 张。
返回和查询
创建成功后会返回异步视频任务对象:
json
{
"id": "video_xxx",
"object": "video",
"created_at": 1770000000,
"status": "queued",
"model": "grok-imagine-video-1.5-preview",
"progress": 0,
"prompt": "A gentle cinematic camera push over the reference image",
"seconds": "6",
"size": "720x1280",
"quality": "standard"
}保存 id,用于后续查询任务和下载视频。
查询任务:
bash
curl https://cubicspaces.cloud/v1/videos/video_xxx \
-H "Authorization: Bearer YOUR_API_KEY"生成中:
json
{
"id": "video_xxx",
"object": "video",
"status": "queued",
"model": "grok-imagine-video-1.5-preview",
"progress": 35,
"seconds": "6",
"size": "720x1280",
"quality": "standard"
}完成后:
json
{
"id": "video_xxx",
"object": "video",
"status": "completed",
"model": "grok-imagine-video-1.5-preview",
"progress": 100,
"completed_at": 1770000060,
"seconds": "6",
"size": "720x1280",
"quality": "standard"
}获取视频内容
任务完成后调用 /content 下载最终 MP4:
bash
curl -L https://cubicspaces.cloud/v1/videos/video_xxx/content \
-H "Authorization: Bearer YOUR_API_KEY" \
-o grok-video.mp4SDK 示例
python
import time
import requests
base_url = "https://cubicspaces.cloud/v1"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
}
task = requests.post(
f"{base_url}/videos",
headers=headers,
json={
"model": "grok-imagine-video-1.5-preview",
"prompt": "A gentle cinematic camera push over the reference image",
"seconds": "6",
"size": "720x1280",
"input_reference": {
"image_url": "https://example.com/reference.png"
},
},
).json()
video_id = task["id"]
while True:
current = requests.get(f"{base_url}/videos/{video_id}", headers=headers).json()
if current["status"] == "completed":
break
if current["status"] == "failed":
raise RuntimeError(current.get("error", {}).get("message", "video failed"))
time.sleep(5)
content = requests.get(f"{base_url}/videos/{video_id}/content", headers=headers).content
with open("grok-video.mp4", "wb") as f:
f.write(content)js
import fs from "node:fs/promises";
const baseURL = "https://cubicspaces.cloud/v1";
const headers = {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
};
const taskResponse = await fetch(`${baseURL}/videos`, {
method: "POST",
headers,
body: JSON.stringify({
model: "grok-imagine-video-1.5-preview",
prompt: "A gentle cinematic camera push over the reference image",
seconds: "6",
size: "720x1280",
input_reference: {
image_url: "https://example.com/reference.png"
}
})
});
const task = await taskResponse.json();
while (true) {
const currentResponse = await fetch(`${baseURL}/videos/${task.id}`, { headers });
const current = await currentResponse.json();
if (current.status === "completed") break;
if (current.status === "failed") {
throw new Error(current.error?.message || "video failed");
}
await new Promise((resolve) => setTimeout(resolve, 5000));
}
const response = await fetch(`${baseURL}/videos/${task.id}/content`, { headers });
await fs.writeFile("grok-video.mp4", Buffer.from(await response.arrayBuffer()));常见错误
| 错误 | 说明 |
|---|---|
Model 'grok-imagine-video-1.5-preview' requires at least one input image | 未提供参考图 |
seconds must be one of [6, 10, 12, 16, 20] | seconds 不在支持范围内 |
size must be one of [...] | size 不在支持尺寸范围内 |
resolution_name must be one of [480p, 720p] | 清晰度参数不支持 |
注意事项
grok-imagine-video-1.5-preview必须带参考图,不要发送纯文生视频请求。- JSON 请求可以使用公网图片 URL 或
data:image/...;base64,...。 - 上传本地文件时使用
multipart/form-data,字段名为input_reference[]。 - 视频任务是异步任务,请先保存
id,再轮询查询接口。 - 任务完成后通过
/v1/videos/{video_id}/content下载 MP4 文件。