grok-image-video
- 通用默认模型。
- 文生视频最长 15 秒。
- 单参考图生视频最长 15 秒。
- 多参考图生视频最长 10 秒。
- 最多支持 7 张参考图。
Developer Docs / Video Generation
视频生成是异步任务。创建接口会返回 task_id 或
id,客户端需要保存该 ID,并持续查询任务状态,直到成功返回
result_url 或失败返回 fail_reason。
本 API 用于提交文生视频、单参考图生视频、多参考图生视频请求。推荐调用方先通过
/v1/models 动态读取可用模型,再根据模型能力构造请求。
默认推荐模型为 grok-image-video。如果使用
grok-video-1.5,当前必须提供且只能提供 1 张参考图。
测试连通性时,建议使用真实请求地址、站内 Key 和映射后的模型名进行端到端测试。不要只依赖 newapi/sub2api 的测试按钮判断可用性。
调用 GET /v1/models 获取当前可用模型,避免把模型列表写死。
调用 POST /v1/video/generations,提交提示词、秒数、画幅和参考图。
使用 response.task_id || response.id 作为后续查询 ID。
每 5 秒查询一次,成功后立即下载 result_url 对应的视频文件。
所有接口使用 Bearer Token。请在用户控制台创建或复制 API Key,并放入请求头。
Authorization: Bearer <YOUR_API_KEY>
Content-Type: application/json
不要把 API Key 写入前端网页、移动端安装包或公开仓库。生产环境建议由自己的后端服务代为调用。
curl -X GET "https://img.apixgo.com/v1/models" \
-H "Authorization: Bearer <YOUR_API_KEY>"
grok-image-videogrok-video-1.516:9 或 9:16。| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string | 是 | 模型 ID,例如 grok-image-video。 |
prompt |
string | 是 | 视频提示词,不能为空。 |
seconds |
integer | 否 | 视频秒数,默认建议 4。多参考图建议不超过 10。 |
aspect_ratio |
string | 否 | 画幅比例,默认建议 16:9。 |
resolution |
string | 否 | 清晰度,建议 720p 或 480p。 |
image_urls |
array<string> | 否 | 参考图 URL 或完整 base64 data URL 列表,推荐优先使用。 |
input_reference |
object/string | 否 | 单参考图字段,可传 { "image_url": "..." }。 |
reference_images |
array<string> | 否 | 多参考图字段。不要与 input_reference 同时传。 |
秒数:
grok-image-video 画幅:
grok-video-1.5 画幅:
清晰度:
data:image/png;base64,...。iVBORw0KGgo...。curl -X POST "https://img.apixgo.com/v1/video/generations" \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-image-video",
"prompt": "A cinematic shot of a red sports car driving through rainy neon streets at night",
"seconds": 6,
"aspect_ratio": "16:9",
"resolution": "720p"
}'
curl -X POST "https://img.apixgo.com/v1/video/generations" \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-image-video",
"prompt": "Animate the product with a slow rotating camera, soft studio light, premium commercial style",
"seconds": 6,
"aspect_ratio": "9:16",
"resolution": "720p",
"image_urls": [
"https://example.com/product.png"
]
}'
curl -X POST "https://img.apixgo.com/v1/video/generations" \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-image-video",
"prompt": "Create a smooth product showcase video using these references, luxury lighting, clean background",
"seconds": 10,
"aspect_ratio": "16:9",
"resolution": "720p",
"image_urls": [
"https://example.com/ref-1.png",
"https://example.com/ref-2.png"
]
}'
const BASE_URL = 'https://img.apixgo.com';
const API_KEY = process.env.NEWAPI_API_KEY;
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
function validateVideoRequest({ model, imageUrls }) {
if (model === 'grok-video-1.5' && imageUrls.length !== 1) {
throw new Error('grok-video-1.5 only supports exactly one reference image.');
}
if (model === 'grok-image-video' && imageUrls.length > 7) {
throw new Error('grok-image-video supports at most 7 reference images.');
}
}
async function createVideo({
model = 'grok-image-video',
prompt,
seconds = 4,
aspectRatio = '16:9',
resolution = '720p',
imageUrls = [],
}) {
validateVideoRequest({ model, imageUrls });
const body = {
model,
prompt,
seconds,
aspect_ratio: aspectRatio,
resolution,
};
if (imageUrls.length > 0) {
body.image_urls = imageUrls;
if (imageUrls.length >= 2 && Number(body.seconds) > 10) {
body.seconds = 10;
}
}
const createResponse = await fetch(`${BASE_URL}/v1/video/generations`, {
method: 'POST',
headers: {
Authorization: `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
});
const created = await createResponse.json();
if (!createResponse.ok) {
throw new Error(`Video request failed: ${JSON.stringify(created)}`);
}
const taskId = created.task_id || created.id;
if (!taskId) {
throw new Error(`No task_id returned: ${JSON.stringify(created)}`);
}
for (let i = 0; i < 60; i += 1) {
await sleep(5000);
const pollResponse = await fetch(`${BASE_URL}/v1/video/generations/${taskId}`, {
headers: { Authorization: `Bearer ${API_KEY}` },
});
const result = await pollResponse.json();
if (!pollResponse.ok) {
throw new Error(`Video poll failed: ${JSON.stringify(result)}`);
}
const task = result.data;
if (task?.status === 'SUCCESS' && task.result_url) {
return { task_id: task.task_id, video_url: task.result_url, raw_response: result };
}
if (task?.status === 'FAILURE') {
throw new Error(`Video generation failed: ${task.fail_reason || JSON.stringify(result)}`);
}
}
throw new Error(`Video generation timeout: ${taskId}`);
}
{
"id": "task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"object": "video",
"model": "grok-image-video",
"status": "queued",
"progress": 0,
"created_at": 1780000000
}
{
"code": "success",
"message": "",
"data": {
"task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"status": "IN_PROGRESS",
"progress": "30%",
"result_url": "",
"fail_reason": ""
}
}
{
"code": "success",
"message": "",
"data": {
"task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"status": "SUCCESS",
"progress": "100%",
"result_url": "https://example.com/generated-video.mp4",
"fail_reason": ""
}
}
{
"code": "success",
"message": "",
"data": {
"task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"status": "FAILURE",
"progress": "100%",
"result_url": "",
"fail_reason": "Image URL could not be fetched: Fetching image failed with HTTP status 400 Bad Request."
}
}
| 轮询间隔 | 建议每 5 秒一次。 |
|---|---|
| 最大轮询时长 | 建议 5 分钟。 |
| 最大轮询次数 | 60 次。 |
| 成功判断 | data.status == "SUCCESS" 且 data.result_url 非空。 |
| 失败判断 | data.status == "FAILURE",读取并展示 data.fail_reason。 |
curl -L -o "grok_video_$(date +%s).mp4" "$result_url"
result_url 有效期约 1 小时。建议生成成功后立即下载,并把视频保存到自己的对象存储或业务文件系统。
| 状态或错误 | 含义 | 建议处理 |
|---|---|---|
SUBMITTED / QUEUED / IN_PROGRESS / NOT_START |
任务仍在处理中。 | 继续按轮询策略查询。 |
SUCCESS |
任务成功。 | 读取 data.result_url 并立即下载。 |
FAILURE |
任务失败。 | 展示 data.fail_reason,保留 task_id 便于排查。 |
401 |
API Key 缺失或错误。 | 检查 Authorization: Bearer <YOUR_API_KEY>。 |
403 |
权限、额度或分组限制。 | 检查账号余额、令牌权限和可用模型。 |
400 prompt is required |
prompt 为空。 |
提交前要求用户填写提示词。 |
400 model field is required |
model 为空。 |
使用模型列表中的模型 ID。 |
400 only supports exactly one reference image |
grok-video-1.5 没有传图或传了多张图。 |
该模型只传 1 张参考图。 |
| 图片抓取失败 | 图片 URL 无法被服务端访问。 | 换成真实 HTTPS 直链或完整 base64 data URL。 |
| 轮询超时 | 任务耗时较长或暂时没有结果。 | 保留 task_id,稍后继续查询。 |
注意:progress: "100%" 只表示任务流程已结束,不一定代表成功。是否成功必须看
data.status。
/v1/models 动态读取。
grok-image-video 最多支持 7 张参考图,多参考图视频最长 10 秒。
grok-video-1.5 能做文生视频吗?data.status 判断结果,并在失败时读取 data.fail_reason。
result_url 是临时直链,有效期约 1 小时,成功后应立即下载。