Grok 视频
grok-imagine-video-1.5 按秒计费的文生 / 图生 / 参考图生视频,多图写法,以及走 grok-imagine-video 的视频编辑与延长
POST /v1/videos/generations · POST /v1/videos/edits · POST /v1/videos/extensions
异步两段式:提交拿到任务 ID → 轮询状态 → 取片。生成用 grok-imagine-video-1.5,编辑与延长用不带版本号的 grok-imagine-video。
按秒计费,见 Grok 对话。最后验证:2026-09-12。
基本调用
# 1. 提交
curl https://www.vibeapi.cn/v1/videos/generations \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video-1.5",
"prompt": "a blue ball rolling slowly on a white floor",
"duration": 6,
"resolution": "720p",
"aspect_ratio": "16:9"
}'
# 2. 轮询(每 5–6 秒一次)
curl "https://www.vibeapi.cn/v1/videos/$TASK_ID" -H "Authorization: Bearer $API_KEY"
# 3. 取片
curl -L "https://www.vibeapi.cn/v1/videos/$TASK_ID/content" \
-H "Authorization: Bearer $API_KEY" -o out.mp4import time, requests
BASE = "https://www.vibeapi.cn/v1"
H = {"Authorization": "Bearer YOUR_API_KEY"}
task = requests.post(f"{BASE}/videos/generations", headers=H, json={
"model": "grok-imagine-video-1.5",
"prompt": "a blue ball rolling slowly on a white floor",
"duration": 6,
"resolution": "720p",
"aspect_ratio": "16:9",
}).json()
while True:
s = requests.get(f"{BASE}/videos/{task['id']}", headers=H).json()
if s["status"] in ("completed", "failed"):
break
time.sleep(5)
if s["status"] == "completed":
mp4 = requests.get(f"{BASE}/videos/{task['id']}/content", headers=H).content
open("out.mp4", "wb").write(mp4) # 视频会被回收,生成后立即落盘import fs from "fs";
const BASE = "https://www.vibeapi.cn/v1";
const H = { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json" };
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const task = await (await fetch(`${BASE}/videos/generations`, {
method: "POST",
headers: H,
body: JSON.stringify({
model: "grok-imagine-video-1.5",
prompt: "a blue ball rolling slowly on a white floor",
duration: 6,
resolution: "720p",
aspect_ratio: "16:9",
}),
})).json();
let s;
while (true) {
s = await (await fetch(`${BASE}/videos/${task.id}`, { headers: H })).json();
if (s.status === "completed" || s.status === "failed") break;
await sleep(5000);
}
if (s.status === "completed") {
const mp4 = Buffer.from(await (await fetch(`${BASE}/videos/${task.id}/content`, { headers: H })).arrayBuffer());
fs.writeFileSync("out.mp4", mp4); // 视频会被回收,生成后立即落盘
}提交、轮询与取片
提交返回任务对象:
{"id": "task_xxx", "request_id": "task_xxx", "object": "video", "status": "queued"}轮询 GET /v1/videos/{id},status 取值 queued → in_progress → completed / failed
(本网关统一成这套;xAI 原生是 pending / done / expired / failed)。建议每 5–6 秒查一次,2 秒视频约 20–30 秒完成,6 秒约 40 秒。
{
"id": "task_xxx",
"status": "completed",
"progress": 100,
"seconds": "6",
"metadata": {"url": "https://www.vibeapi.cn/v1/videos/task_xxx/content"}
}取片 GET /v1/videos/{id}/content,返回 video/mp4 文件流,需带同一个 Authorization 头。
视频不长期保存,请务必下载落盘。 /content 是实时代理,每次请求都从上游拉取转发,平台只存任务元数据;
上游会回收文件,数小时后再取可能返回 Video request not found,此时任务状态仍是 completed 但内容已取不回。
请求参数
| 参数 | 支持 | 取值 / 说明 |
|---|---|---|
prompt | ✅ | 文生视频必填;带 image / reference_images / last_frame 时可省略 |
duration | ✅ | 1–15 秒,超出返回 400;seconds 是等价别名 |
resolution | ✅ | 480p(默认)/ 720p / 1080p(1.5 的文生、图生支持 1080p;参考图生视频上限 720p) |
aspect_ratio | ✅ | 1:1、16:9(默认)/ 9:16、4:3 / 3:4、3:2 / 2:3;图生视频默认跟随输入图 |
image | ✅ | 图生视频:{"url": "..."},锁定首帧 |
reference_images | ✅ | 参考图,支持多张,见下文 |
last_frame | — | 仅 1.5:锁定末帧;与 image 同传即首尾帧插值。未实测 |
generate_audio | — | 默认 true(成片带音轨),false 出静音视频。未实测 |
reference_audios | ⚠️ | 官方已开放预置音色,最多 3 个 {"voice_id": "eve"},提示词用 <AUDIO_0> 引用;自定义音频仍限受信任伙伴。本网关未验证 |
size | ⚠️ | 无效,静默忽略;改用 resolution |
费用 = 每秒单价 × 实际输出秒数 × 分组倍率。按实际产出秒数结算,生成失败或超时全额退款;分辨率不影响单价。
多图生成视频
image 与 reference_images 都能传图,语义不同:
// image:锁定首帧,视频从这张图开始运动
{"prompt": "make it spin", "image": {"url": "https://..."}}
// reference_images:引导内容与风格,不锁首帧,用 <IMAGE_n> 引用
{"prompt": "<IMAGE_1> slowly rotating", "reference_images": [{"url": "https://..."}]}多图有三种写法,都能正常出片;提示词里用 <IMAGE_1> <IMAGE_2> 指代对应图片:
// 写法一 · reference_images(推荐,与单图一致)
{
"model": "grok-imagine-video-1.5",
"prompt": "<IMAGE_1> and <IMAGE_2> together, slow pan",
"reference_images": [{"url": "https://..."}, {"url": "https://..."}],
"duration": 4
}
// 写法二 · image_urls(字符串数组)
{"prompt": "...", "image_urls": ["https://...", "https://..."]}
// 写法三 · frame_images(按帧引导)
{"prompt": "...", "frame_images": ["https://...", "https://..."]}每张图必须可公网直接获取。 许多站点禁止外链引用,会失败并返回
Failed to download the provided image ... the image host returned HTTP status 400;用自有对象存储,或用生图接口返回的图片 URL。
视频编辑与延长
与生成共用同一套异步流程。模型都用不带版本号的 grok-imagine-video,-1.5 在这两个接口上返回 400。
| 写法 | 模型 | 结果 |
|---|---|---|
POST /v1/videos/edits + video | grok-imagine-video | ✅ 成片与源片等长(官方端点) |
POST /v1/videos/edits + video | grok-imagine-video-1.5 | ❌ 400 Video editing is not supported for this model. |
POST /v1/videos/generations + video(旧写法) | grok-imagine-video-1.5,不传 duration | ✅ 但成片时长翻倍(4 秒变 8 秒) |
POST /v1/videos/extensions + video + duration: 3 | grok-imagine-video | ✅ 成片 7 秒 = 4 + 3 |
POST /v1/videos/extensions | grok-imagine-video-1.5 | ❌ 400 Video extension is not supported for this model. |
编辑
curl https://www.vibeapi.cn/v1/videos/edits \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video",
"prompt": "Add a small blue ribbon tied around the apple",
"video": {"url": "https://.../source.mp4"}
}'编辑不接受 duration / aspect_ratio / resolution,输出继承源片,分辨率上限 720p、时长上限 8.7 秒。
video.url 可以是公网直链、data:video/mp4;base64,... 或 Files API 的 file_id。
旧写法 /v1/videos/generations + video 仍能提交,但用 1.5 且不传 duration 时成片翻倍、计费也翻倍;不建议再用。
延长
curl https://www.vibeapi.cn/v1/videos/extensions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video",
"prompt": "The camera slowly zooms out revealing the whole table",
"duration": 4,
"video": {"url": "https://.../source.mp4"}
}'duration 只是延长部分的秒数:4 秒源片 + duration: 3 = 7 秒成片,轮询响应里的 seconds 也只报延长部分。
编辑、延长各自产出的视频重新按秒计费。