---
title: "Grok 视频生成"
url: "/docs/grok-video"
base_url:
  - "https://api.o1key.com"  # 主地址
auth: "Authorization: Bearer <API Key>"
endpoints:
  - "POST /grok/v1/videos/generations"
  - "GET /grok/v1/videos/{task_id}"
  - "POST /grok/v1/videos/edits"
  - "POST /grok/v1/videos/extensions"
---

# Grok 视频生成

支持视频生成、视频编辑和视频延长三种操作。三个接口共用同一查询端点。

## Agent 调用规则

1. 按需求选择接口：生成 POST `/grok/v1/videos/generations`，编辑 `/grok/v1/videos/edits`，延长 `/grok/v1/videos/extensions`。记录返回的 `request_id`。
2. 定期 GET `/grok/v1/videos/{request_id}`，`pending` 时继续查询。
3. `done`：把 `video.url` 返回给用户。
4. `failed` 或 `expired`：把 `error` 告诉用户，不要自动重试。

## 简明说明

### 这个接口做什么？

用 Grok 生成视频，也可以编辑或延长一段已有视频。三种操作提交后都返回 `request_id`，并用同一个查询接口拿结果。

### 你需要提供的信息

- **用哪个模型**：`model`，例如 `grok-imagine-video-1.5`。
- **想要什么画面**：`prompt`；编辑和延长时写要改什么、接着发生什么。
- **素材（按操作）**：图生视频传 `image`；编辑和延长传 `video`，公网 URL 或 Base64。

### 怎么拿到结果

- **状态**：`pending` 继续等待；`done` 完成；`failed`、`expired` 失败。
- **视频地址**：`video.url`，时长见 `video.duration`。

## 视频生成

`POST /grok/v1/videos/generations`

从文本、图片或多模态参考素材生成视频。

### 模型

| 模型名称 | 最高分辨率 | 说明 |
|---|---|---|
| `grok-imagine-video` | 720p | 支持文生、图生和多参考素材生成 |
| `grok-imagine-video-1.5` | 1080p | 文生和图生支持 1080p；多参考素材上限 720p |

### 请求参数

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `model` | string | 是 | 模型名称 |
| `prompt` | string | 条件 | 文生视频和多参考素材必填；图生可选 |
| `duration` | integer | 否 | 1-15 秒，默认 8 秒 |
| `aspect_ratio` | string | 否 | `16:9`（默认）、`9:16`、`1:1`、`4:3`、`3:4`、`3:2`、`2:3` |
| `resolution` | string | 否 | `480p`（默认）、`720p`、`1080p` |
| `image` | object | 条件 | 图生视频输入，填 `url` 或 `image_url`；公网 URL 或 Base64 |
| `reference_images` | array | 否 | 参考图数组，最多 7 张 |
| `reference_audios` | array | 否 | 参考音频，每项可用 `url` 或 `voice_id`，最多 3 个 |

> **互斥规则**：`image` 和 `reference_images` 不能同时使用。

### 请求示例

#### 文生视频

```bash
curl https://api.o1key.com/grok/v1/videos/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-video-1.5",
    "prompt": "A spacecraft crosses Saturn rings, cinematic tracking shot.",
    "duration": 10,
    "resolution": "1080p",
    "aspect_ratio": "16:9"
  }'
```

#### 图生视频

```bash
curl https://api.o1key.com/grok/v1/videos/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-video-1.5",
    "image": {"url": "https://cdn.example.com/ref.jpg"},
    "prompt": "让画面中的人物微笑并挥手",
    "duration": 10,
    "resolution": "1080p"
  }'
```

#### 多参考素材

```bash
curl https://api.o1key.com/grok/v1/videos/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-video-1.5",
    "prompt": "Fashion film with character from first image and style from second.",
    "reference_images": [
      {"url": "https://cdn.example.com/char.jpg"},
      {"url": "https://cdn.example.com/style.jpg"}
    ],
    "reference_audios": [{"voice_id": "nova"}],
    "duration": 8,
    "resolution": "720p"
  }'
```

### 响应

```json
{"request_id": "task_grok_xxxxxxxxxx"}
```

## 查询任务

`GET /grok/v1/videos/{task_id}`

使用创建接口返回的 `request_id` 查询任务状态和结果。

| 响应字段 | 说明 |
|---|---|
| `status` | `pending`（处理中）、`done`（完成）、`failed`（失败）、`expired`（过期） |
| `model` | 使用的模型名称 |
| `progress` | 进度百分比（0-100） |
| `video.url` | 视频下载地址（完成后可用） |
| `video.duration` | 视频时长（秒） |
| `error` | 失败时的错误信息 |

### 请求

```bash
curl https://api.o1key.com/grok/v1/videos/<task_id> \
  -H "Authorization: Bearer $API_KEY"
```

### 响应示例

#### 完成

```json
{
  "status": "done",
  "model": "grok-imagine-video-1.5",
  "video": {
    "url": "https://cdn.example.com/grok-result.mp4",
    "duration": 15
  },
  "progress": 100
}
```

#### 处理中

```json
{
  "status": "pending",
  "model": "grok-imagine-video-1.5",
  "progress": 42
}
```

#### 失败

```json
{
  "status": "failed",
  "model": "grok-imagine-video",
  "error": {
    "code": "content_policy_violation",
    "message": "The request could not be completed."
  }
}
```

## 视频编辑

`POST /grok/v1/videos/edits`

基于提示词编辑输入视频。输出保持输入的时长和宽高比，分辨率上限 720p。

> **时长限制**：输入视频不超过 8.7 秒。

### 请求参数

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `model` | string | 是 | 模型名称 |
| `prompt` | string | 是 | 编辑指令 |
| `video` | object | 是 | 输入视频，填 `url` 或 `file_id`；公网 URL 或 Base64 |

**不支持的参数**：`duration`、`aspect_ratio`、`resolution`、`image`、`reference_images`、`reference_audios`

### 请求

```bash
curl https://api.o1key.com/grok/v1/videos/edits \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-video-1.5",
    "prompt": "Make the sky turn golden with a dramatic sunset, keep everything else unchanged.",
    "video": {"url": "https://cdn.example.com/input.mp4"}
  }'
```

### 响应

```json
{"request_id": "task_grok_edit_xxxxxxxxxx"}
```

## 视频延长

`POST /grok/v1/videos/extensions`

延长输入视频。`duration` 参数控制延长部分的时长，输出总时长 = 输入时长 + duration。

### 请求参数

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `model` | string | 是 | 模型名称 |
| `prompt` | string | 是 | 延长部分的内容描述 |
| `video` | object | 是 | 输入视频，填 `url` 或 `file_id`；公网 URL 或 Base64 |
| `duration` | integer | 否 | 延长部分时长 2-10 秒，默认 6 秒 |

**不支持的参数**：`aspect_ratio`、`resolution`、`image`、`reference_images`、`reference_audios`

### 请求

```bash
curl https://api.o1key.com/grok/v1/videos/extensions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-video-1.5",
    "prompt": "Continue the camera movement smoothly, revealing more of the landscape.",
    "video": {"url": "https://cdn.example.com/clip.mp4"},
    "duration": 5
  }'
```

输入 10 秒视频 + duration=5 → 输出 15 秒视频。

### 响应

```json
{"request_id": "task_grok_extend_xxxxxxxxxx"}
```
