Grok Video API 接入文档
Grok 视频生成 API 的完整接入说明,包括模型列表、创建任务、轮询查询、图生视频参数、错误排查和 JavaScript 示例。
基础信息
GEThttps://img.gpt88.cc/v1/models
POSThttps://img.gpt88.cc/v1/video/generations
GEThttps://img.gpt88.cc/v1/video/generations/{task_id}
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
Base URL | string | 必填 | https://img.gpt88.cc。 |
鉴权方式 | string | 必填 | Authorization: Bearer <YOUR_API_KEY>。 |
请求格式 | string | 必填 | application/json。 |
响应格式 | string | 必填 | JSON。 |
任务类型 | string | 必填 | 异步任务。创建成功后先返回 task_id,再轮询查询。 |
Base URLstring必填https://img.gpt88.cc。鉴权方式string必填Authorization: Bearer <YOUR_API_KEY>。请求格式string必填application/json。响应格式string必填JSON。任务类型string必填异步任务。创建成功后先返回task_id,再轮询查询。
获取 API Key
请在 Agent API Keys 创建或复制 API Key。调用时放入请求头:
auth-headerbash
Authorization: Bearer <YOUR_API_KEY>不要把 API Key 写进前端页面、移动端安装包或公开仓库。推荐只在你的后端服务里转发请求。
查询可用模型
list-models.shbash
curl -X GET "https://img.gpt88.cc/v1/models" \
-H "Authorization: Bearer <YOUR_API_KEY>"| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 必填 | 模型 ID,例如 grok-image-video。 |
object | string | 必填 | 固定为 "model"。 |
created | integer | 可选 | 模型上架时间戳,Unix 秒。 |
owned_by | string | 可选 | 模型归属 provider,例如 xai。 |
capabilities | string[] | 可选 | 支持能力,例如 video / image / streaming。 |
modalities | string[] | 可选 | 支持模态,例如 video、image。 |
idstring必填模型 ID,例如grok-image-video。objectstring必填固定为"model"。createdinteger模型上架时间戳,Unix 秒。owned_bystring模型归属 provider,例如xai。capabilitiesstring[]支持能力,例如video/image/streaming。modalitiesstring[]支持模态,例如video、image。
创建视频任务
接口:
POSThttps://img.gpt88.cc/v1/video/generations
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 必填 | 模型 ID,例如 grok-image-video 或 grok-video-1.5。 |
prompt | string | 必填 | 视频提示词。 |
seconds | integer | 可选 | 视频秒数,默认建议 4。 |
aspect_ratio | string | 可选 | 画幅比例,默认建议 16:9。 |
resolution | string | 可选 | 清晰度,建议 720p 或 480p。 |
image_urls | array<string> | 可选 | 参考图 URL 或 base64 data URL 列表。 |
images | array<string> | 可选 | 兼容字段,含义与 image_urls 相同。不要和 image_urls 同时传。 |
input_reference | object | string | 可选 | 单参考图字段,可传 { "image_url": "..." }。 |
reference_images | array<string> | 可选 | 多参考图字段。不要和 input_reference 同时传。 |
modelstring必填模型 ID,例如grok-image-video或grok-video-1.5。promptstring必填视频提示词。secondsinteger视频秒数,默认建议4。aspect_ratiostring画幅比例,默认建议16:9。resolutionstring清晰度,建议720p或480p。image_urlsarray<string>参考图 URL 或 base64 data URL 列表。imagesarray<string>兼容字段,含义与image_urls相同。不要和image_urls同时传。input_referenceobject | string单参考图字段,可传{ "image_url": "..." }。reference_imagesarray<string>多参考图字段。不要和input_reference同时传。
参数建议
- seconds:
grok-image-video的文生视频和单图生视频建议使用4、6、8、10、12、15;多参考图建议使用4、6、8、10。 - 时长规则:
grok-image-video文生视频和单图生视频最长支持15s;多参考图最长支持10s,超过会自动按10s处理。 - aspect_ratio:
grok-image-video推荐1:1、16:9、9:16、4:3、3:4、3:2、2:3;grok-video-1.5仅建议16:9或9:16。 - resolution:常用
720p和480p。如果你做批量素材,可优先低分辨率;如果要封面或主视觉,优先高分辨率。 - 图片要求:参考图最好使用公网可直接访问的 HTTPS 直链,或者完整的 base64 data URL。
curl -X POST "https://img.gpt88.cc/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"
}'请求示例
6.1 文生视频
text-to-video.shbash
curl -X POST "https://img.gpt88.cc/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"
}'6.2 单参考图生视频
single-reference-image.shbash
curl -X POST "https://img.gpt88.cc/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"
]
}'单参考图场景下,你也可以使用 input_reference,例如:
single-reference-image.jsonjson
{
"model": "grok-image-video",
"prompt": "Animate the product with a slow rotating camera",
"seconds": 6,
"aspect_ratio": "9:16",
"resolution": "720p",
"input_reference": {
"image_url": "https://example.com/product.png"
}
}6.3 多参考图生视频
multi-reference-image.shbash
curl -X POST "https://img.gpt88.cc/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"
]
}'多参考图时,请不要同时传 input_reference 和 reference_images。 如果你要控制单个商品在多个角度之间切换,建议先整理好图片顺序,再提交任务。
6.4 grok-video-1.5 单图生视频
grok-video-1.5.shbash
curl -X POST "https://img.gpt88.cc/v1/video/generations" \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-video-1.5",
"prompt": "Use the reference image as the main subject and create a smooth cinematic motion",
"seconds": 4,
"aspect_ratio": "16:9",
"resolution": "480p",
"image_urls": [
"https://example.com/reference.png"
]
}'创建响应
创建成功后会返回任务对象。关键字段是 id 或 task_id:
create-response.jsonjson
{
"id": "task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"object": "video",
"model": "grok-image-video",
"status": "queued",
"progress": 0,
"created_at": 1780000000
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 必填 | 任务唯一 ID。 |
task_id | string | 必填 | 任务唯一 ID 的别名,建议保存这个字段。 |
object | string | 必填 | 固定为 "video"。 |
model | string | 必填 | 实际使用的模型 ID。 |
status | string | 必填 | 任务状态,例如 queued。 |
progress | integer | string | 必填 | 任务进度,常见为百分比字符串。 |
created_at | integer | 可选 | 创建时间戳,Unix 秒。 |
idstring必填任务唯一 ID。task_idstring必填任务唯一 ID 的别名,建议保存这个字段。objectstring必填固定为"video"。modelstring必填实际使用的模型 ID。statusstring必填任务状态,例如queued。progressinteger | string必填任务进度,常见为百分比字符串。created_atinteger创建时间戳,Unix 秒。
客户端建议统一保存:task_id = response.task_id || response.id
查询任务状态
poll-task.shbash
curl -X GET "https://img.gpt88.cc/v1/video/generations/task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Authorization: Bearer <YOUR_API_KEY>"典型处理中响应:
poll-progress.jsonjson
{
"code": "success",
"message": "",
"data": {
"task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"status": "IN_PROGRESS",
"progress": "30%",
"result_url": "",
"fail_reason": ""
}
}典型成功响应:
poll-success.jsonjson
{
"code": "success",
"message": "",
"data": {
"task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"status": "SUCCESS",
"progress": "100%",
"result_url": "https://example.com/generated-video.mp4",
"fail_reason": ""
}
}典型失败响应:
poll-failure.jsonjson
{
"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."
}
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
code | string | 必填 | 通常为 success。 |
message | string | 必填 | 接口消息。 |
data.task_id | string | 必填 | 任务 ID。 |
data.status | string | 必填 | 任务状态:SUBMITTED / QUEUED / IN_PROGRESS / NOT_START / SUCCESS / FAILURE。 |
data.progress | string | 必填 | 进度字符串,例如 30% 或 100%。 |
data.result_url | string | 可选 | 成功后的临时视频直链。 |
data.fail_reason | string | 可选 | 失败原因。 |
codestring必填通常为success。messagestring必填接口消息。data.task_idstring必填任务 ID。data.statusstring必填任务状态:SUBMITTED/QUEUED/IN_PROGRESS/NOT_START/SUCCESS/FAILURE。data.progressstring必填进度字符串,例如30%或100%。data.result_urlstring成功后的临时视频直链。data.fail_reasonstring失败原因。
data.status == "SUCCESS"且data.result_url非空,表示成功。data.status == "FAILURE",读取data.fail_reason展示给用户。data.status为SUBMITTED、QUEUED、IN_PROGRESS、NOT_START时,任务还在处理中。
JavaScript 示例
grok-video.tstypescript
const BASE_URL = 'https://img.gpt88.cc'
const API_KEY = process.env.NEWAPI_API_KEY
function sleep(ms) {
return 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}\`)
}常见错误
- 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没有传图或传了多张图。 - 图片抓取失败:图片 URL 无法被服务端访问,换成真实直链或 base64。
- 任务 FAILURE:上游生成失败、图片不可访问或参数不支持,读取
data.fail_reason。 - 轮询超时:保留
task_id,稍后继续查询。
接入注意事项
- 不要把模型 ID 写死成单个模型,建议通过 GET /v1/models 动态读取。
- 默认推荐使用
grok-image-video。 grok-video-1.5当前仅用于单参考图生视频。grok-image-video文生视频和单图生视频最长 15 秒,多参考图最长 10 秒。grok-image-video多参考图最多 7 张;多参考图请求超过 10 秒会自动按 10 秒处理。grok-video-1.5只支持单图生视频,最长 15 秒。- 最终视频 URL 在查询接口的
data.result_url字段中,建议在生成成功后立即下载。 - 任务失败时可能会出现
progress: "100%",这是正常结束状态,请以data.status判断结果。