Grok Video API 接入文档

Grok 视频生成 API 的完整接入说明,包括模型列表、创建任务、轮询查询、图生视频参数、错误排查和 JavaScript 示例。

This page is accessible in English navigation, but the full body has not been translated yet. The original Chinese content is kept below for accuracy.

基础信息

GEThttps://img.gpt88.cc/v1/models
POSThttps://img.gpt88.cc/v1/video/generations
GEThttps://img.gpt88.cc/v1/video/generations/{task_id}
  • Base URLstringRequired
    https://img.gpt88.cc
  • 鉴权方式stringRequired
    Authorization: Bearer <YOUR_API_KEY>
  • 请求格式stringRequired
    application/json
  • 响应格式stringRequired
    JSON。
  • 任务类型stringRequired
    异步任务。创建成功后先返回 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>"
  • idstringRequired
    模型 ID,例如 grok-image-video
  • objectstringRequired
    固定为 "model"
  • createdinteger
    模型上架时间戳,Unix 秒。
  • owned_bystring
    模型归属 provider,例如 xai
  • capabilitiesstring[]
    支持能力,例如 video / image / streaming
  • modalitiesstring[]
    支持模态,例如 videoimage

创建视频任务

接口:

POSThttps://img.gpt88.cc/v1/video/generations
  • modelstringRequired
    模型 ID,例如 grok-image-videogrok-video-1.5
  • promptstringRequired
    视频提示词。
  • secondsinteger
    视频秒数,默认建议 4
  • aspect_ratiostring
    画幅比例,默认建议 16:9
  • resolutionstring
    清晰度,建议 720p480p
  • image_urlsarray<string>
    参考图 URL 或 base64 data URL 列表。
  • imagesarray<string>
    兼容字段,含义与 image_urls 相同。不要和 image_urls 同时传。
  • input_referenceobject | string
    单参考图字段,可传 { "image_url": "..." }
  • reference_imagesarray<string>
    多参考图字段。不要和 input_reference 同时传。

参数建议

  • secondsgrok-image-video 的文生视频和单图生视频建议使用 468101215;多参考图建议使用 46810
  • 时长规则grok-image-video 文生视频和单图生视频最长支持 15s;多参考图最长支持 10s,超过会自动按 10s 处理。
  • aspect_ratiogrok-image-video 推荐 1:116:99:164:33:43:22:3grok-video-1.5 仅建议 16:99:16
  • resolution:常用 720p480p。如果你做批量素材,可优先低分辨率;如果要封面或主视觉,优先高分辨率。
  • 图片要求:参考图最好使用公网可直接访问的 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_referencereference_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"
    ]
  }'

创建响应

创建成功后会返回任务对象。关键字段是 idtask_id

create-response.jsonjson
{
  "id": "task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "task_id": "task_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "object": "video",
  "model": "grok-image-video",
  "status": "queued",
  "progress": 0,
  "created_at": 1780000000
}
  • idstringRequired
    任务唯一 ID。
  • task_idstringRequired
    任务唯一 ID 的别名,建议保存这个字段。
  • objectstringRequired
    固定为 "video"
  • modelstringRequired
    实际使用的模型 ID。
  • statusstringRequired
    任务状态,例如 queued
  • progressinteger | stringRequired
    任务进度,常见为百分比字符串。
  • 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."
  }
}
  • codestringRequired
    通常为 success
  • messagestringRequired
    接口消息。
  • data.task_idstringRequired
    任务 ID。
  • data.statusstringRequired
    任务状态:SUBMITTED / QUEUED / IN_PROGRESS / NOT_START / SUCCESS / FAILURE
  • data.progressstringRequired
    进度字符串,例如 30%100%
  • data.result_urlstring
    成功后的临时视频直链。
  • data.fail_reasonstring
    失败原因。
  • data.status == "SUCCESS"data.result_url 非空,表示成功。
  • data.status == "FAILURE",读取 data.fail_reason 展示给用户。
  • data.statusSUBMITTEDQUEUEDIN_PROGRESSNOT_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 requiredprompt 为空。
  • 400 model field is requiredmodel 为空或模型 ID 写错。
  • 400 only supports exactly one reference imagegrok-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 判断结果。