推理 API

视频

查看 Markdown

视频生成

/v1/videos/generations

根据文本提示生成视频,也可选择提供图像。 这是异步操作,会返回用于轮询的 request_id。

请求体

响应体

request_idstring

(string,必填)— 用于轮询结果的唯一请求 ID。

代码示例

**响应示例:**


Example
curl -s https://api.x.ai/v1/videos/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{
    "model": "grok-imagine-video-1.5",
    "prompt": "A serene lake at sunrise with mist rolling over the water"
  }'
Exampletext

text

{
  "request_id": "41eb9a5f-cbd4-9f21-8d59-79005f1e61b7"
}

视频编辑

/v1/videos/edits

根据 prompt 编辑视频。 这是一个异步操作,会返回可用于轮询的 request_id。

请求体

promptstring

(string,必填)— 视频编辑的 prompt。

videoobject

(object,必填)— 用于编辑和扩展请求的视频输入。 接受公开 URL、base64 编码 data URL 或 xAI 文件 API 中的 file_id。

响应体

request_idstring

(string,必填)— 用于轮询结果的唯一请求 ID。

代码示例

**响应示例:**


Example
curl -s https://api.x.ai/v1/videos/edits \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d "{
    \"model\": \"grok-imagine-video\",
    \"prompt\": \"Give the woman a silver necklace\",
    \"video\": {
      \"url\": \"$VIDEO_URL\"
    }
  }"
Exampletext

text

{
  "request_id": "69ad8ab2-3459-9c92-a372-cb3dcc3533b2"
}

视频扩展

/v1/videos/extensions

通过生成延续内容来扩展视频。 这是一个异步操作,会返回可用于轮询的 request_id。

请求体

promptstring

(string,必填)— 描述视频中接下来应发生什么的 prompt。

videoobject

(object,必填)— 用于编辑和扩展请求的视频输入。 接受公开 URL、base64 编码 data URL 或 xAI 文件 API 中的 file_id。

响应体

request_idstring

(string,必填)— 用于轮询结果的唯一请求 ID。

Exampletext

text

{
  "prompt": "The camera slowly zooms out to reveal the city skyline",
  "video": {
    "url": "https://example.com/video.mp4"
  },
  "model": "grok-imagine-video",
  "duration": 6
}
Exampletext

text

{
  "request_id": "a3d1008e-4544-40d4-d075-11527e794e4a"
}

获取视频生成结果

/v1/videos/{request_id}

获取延迟视频生成请求的结果。

路径参数

request_idstring

(string,必填)— 先前视频生成请求返回的延迟请求 id。

响应体

statusstring

(string,必填)— 视频生成状态;视频就绪时为 "done"。

代码示例

**响应示例:**

Example
curl -s "https://api.x.ai/v1/videos/$VIDEO_REQUEST_ID" \
  -H "Authorization: Bearer $XAI_API_KEY"
Exampletext

text

{
  "status": "done",
  "video": {
    "url": "https://vidgen.x.ai/xai-vidgen-bucket/xai-video-cb3a83ec-322f-4318-990d-166bab11d328.mp4",
    "duration": 1,
    "respect_moderation": true
  },
  "model": "grok-imagine-video",
  "usage": {
    "cost_in_usd_ticks": 500000000
  },
  "progress": 100
}

最后更新:2026 年 4 月 13 日