# 创建 Grok 视频

使用 grok-imagine-video-1.5 通过文本、首尾帧、关键帧或参考图创建异步视频生成任务。

- 原文: https://www.unifyllm.com/zh/docs/api-reference/create-grok-video/
- 语言: zh-CN

## 接口

```http
POST https://api.unifyllm.top/v1/videos
```

认证与请求头以本页调用示例为准。 Content-Type: application/json

## 生成流程

该接口创建异步任务，不会在创建响应中直接返回视频文件。

- 使用 UnifyLLM API Key 调用 POST /v1/videos，保存响应中的完整 id。

- 通过 GET /v1/videos/{task_id} 查询状态；queued 或 in_progress 时每隔 5–10 秒轮询。

- 状态为 completed 后先检查 error，确认没有审核拦截等错误，再通过 GET /v1/videos/{task_id}/content 下载。

## 生成模式

| 模式 | 输入 | 用途 |
| --- | --- | --- |
| 文生视频 | prompt | 按文字描述生成视频 |
| 图生视频 | prompt + image | 以图片作为首帧 |
| 尾帧 | prompt + last_frame | 指定结束画面 |
| 首尾帧 | prompt + image + last_frame | 锁定起止画面 |
| 关键帧 | prompt + keyframes，可搭配首尾帧 | 指定中间时刻的画面 |
| 参考图 | prompt + reference_images | 参考角色、画风等视觉内容，不锁定精确帧 |

## 参数与素材限制

- 模型使用 grok-imagine-video-1.5，所有模式都需要非空 prompt。

- reference_images、last_frame 和 keyframes 模式最高支持 720p；不要在这些模式下请求 1080p。

- 示例中的 example.com 图片只是请求模板，使用时替换为真实且公开可访问的图片。图片对象使用 url 字段，不使用 file_id。

- 关键帧时间位于 (0, duration) 内，最多 4 个，且各自占用不同的 1/3 秒时间槽。

## 参数

| 参数 | 位置 | 类型 | 必填 | 说明 | 可选值 | 示例 |
| --- | --- | --- | --- | --- | --- | --- |
| model | body | string | 是 | 使用 grok-imagine-video-1.5；API Key 需具有该模型的调用权限。 | grok-imagine-video-1.5 | grok-imagine-video-1.5 |
| prompt | body | string | 是 | 非空的视频生成提示词。所有模式均必填，包括图生视频、尾帧、关键帧和参考图模式。 |  | A paper boat floats on a calm lake. Locked camera, soft daylight. |
| duration | body | integer | 否 | 视频时长，单位秒，范围 1–15，默认 8。 |  | 3 |
| seconds | body | integer | 否 | duration 的兼容别名。优先使用 duration，不要同时传入相互冲突的值。 |  | 3 |
| resolution | body | string | 否 | 480p（默认）、720p 或 1080p。使用 reference_images、last_frame 或 keyframes 时，分辨率最高为 720p。 | 480p, 720p, 1080p | 480p |
| aspect_ratio | body | string | 否 | 视频宽高比：1:1、16:9、9:16、4:3、3:4、3:2、2:3、21:9 或 5:2。 | 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 21:9, 5:2 | 16:9 |
| generate_audio | body | boolean | 否 | 传入 false 关闭音频生成；不传时使用上游默认行为。 |  | false |
| image | body | object | 否 | 首帧对象，例如 {"url":"https://..."}。支持公网 HTTP(S) 图片地址或完整图片 data URL，不支持 file_id。 |  | {"url":"https://example.com/start.jpg"} |
| last_frame | body | object | 否 | 尾帧对象，例如 {"url":"https://..."}。可单独使用，也可与 image 一起锁定首尾帧；支持公网图片地址或完整图片 data URL。 |  | {"url":"https://example.com/end.jpg"} |
| keyframes | body | array | 否 | 1–4 个关键帧，每项为 {"image":{"url":"..."},"timestamp_s":1}。时间戳必须严格位于 0 与 duration 之间，且不能占用同一个 1/3 秒时间槽。 |  | [{"image":{"url":"https://example.com/middle.jpg"},"timestamp_s":1}] |
| reference_images | body | array | 否 | 1–14 个 {"url":"https://..."} 对象，用于角色、风格等视觉参考，不用于精确锁定帧。 |  | [{"url":"https://example.com/character.jpg"},{"url":"https://example.com/style.jpg"}] |

## 文生视频

```json
{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1/videos' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/videos", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "grok-imagine-video-1.5",
    "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
    "duration": 3,
    "resolution": "480p",
    "aspect_ratio": "16:9",
    "generate_audio": false
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1/videos",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"model\": \"grok-imagine-video-1.5\",\n  \"prompt\": \"A paper boat floats on a calm lake. Locked camera, soft daylight.\",\n  \"duration\": 3,\n  \"resolution\": \"480p\",\n  \"aspect_ratio\": \"16:9\",\n  \"generate_audio\": false\n}")
)
response.raise_for_status()
print(response.json())
```

## 图生视频

```json
{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false,
  "image": {
    "url": "https://example.com/start.jpg"
  }
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1/videos' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false,
  "image": {
    "url": "https://example.com/start.jpg"
  }
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/videos", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "grok-imagine-video-1.5",
    "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
    "duration": 3,
    "resolution": "480p",
    "aspect_ratio": "16:9",
    "generate_audio": false,
    "image": {
      "url": "https://example.com/start.jpg"
    }
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1/videos",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"model\": \"grok-imagine-video-1.5\",\n  \"prompt\": \"A paper boat floats on a calm lake. Locked camera, soft daylight.\",\n  \"duration\": 3,\n  \"resolution\": \"480p\",\n  \"aspect_ratio\": \"16:9\",\n  \"generate_audio\": false,\n  \"image\": {\n    \"url\": \"https://example.com/start.jpg\"\n  }\n}")
)
response.raise_for_status()
print(response.json())
```

## 尾帧

```json
{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false,
  "last_frame": {
    "url": "https://example.com/end.jpg"
  }
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1/videos' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false,
  "last_frame": {
    "url": "https://example.com/end.jpg"
  }
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/videos", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "grok-imagine-video-1.5",
    "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
    "duration": 3,
    "resolution": "480p",
    "aspect_ratio": "16:9",
    "generate_audio": false,
    "last_frame": {
      "url": "https://example.com/end.jpg"
    }
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1/videos",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"model\": \"grok-imagine-video-1.5\",\n  \"prompt\": \"A paper boat floats on a calm lake. Locked camera, soft daylight.\",\n  \"duration\": 3,\n  \"resolution\": \"480p\",\n  \"aspect_ratio\": \"16:9\",\n  \"generate_audio\": false,\n  \"last_frame\": {\n    \"url\": \"https://example.com/end.jpg\"\n  }\n}")
)
response.raise_for_status()
print(response.json())
```

## 首尾帧

```json
{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false,
  "image": {
    "url": "https://example.com/start.jpg"
  },
  "last_frame": {
    "url": "https://example.com/end.jpg"
  }
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1/videos' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false,
  "image": {
    "url": "https://example.com/start.jpg"
  },
  "last_frame": {
    "url": "https://example.com/end.jpg"
  }
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/videos", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "grok-imagine-video-1.5",
    "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
    "duration": 3,
    "resolution": "480p",
    "aspect_ratio": "16:9",
    "generate_audio": false,
    "image": {
      "url": "https://example.com/start.jpg"
    },
    "last_frame": {
      "url": "https://example.com/end.jpg"
    }
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1/videos",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"model\": \"grok-imagine-video-1.5\",\n  \"prompt\": \"A paper boat floats on a calm lake. Locked camera, soft daylight.\",\n  \"duration\": 3,\n  \"resolution\": \"480p\",\n  \"aspect_ratio\": \"16:9\",\n  \"generate_audio\": false,\n  \"image\": {\n    \"url\": \"https://example.com/start.jpg\"\n  },\n  \"last_frame\": {\n    \"url\": \"https://example.com/end.jpg\"\n  }\n}")
)
response.raise_for_status()
print(response.json())
```

## 关键帧

```json
{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false,
  "image": {
    "url": "https://example.com/start.jpg"
  },
  "keyframes": [
    {
      "image": {
        "url": "https://example.com/middle.jpg"
      },
      "timestamp_s": 1
    }
  ],
  "last_frame": {
    "url": "https://example.com/end.jpg"
  }
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1/videos' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false,
  "image": {
    "url": "https://example.com/start.jpg"
  },
  "keyframes": [
    {
      "image": {
        "url": "https://example.com/middle.jpg"
      },
      "timestamp_s": 1
    }
  ],
  "last_frame": {
    "url": "https://example.com/end.jpg"
  }
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/videos", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "grok-imagine-video-1.5",
    "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
    "duration": 3,
    "resolution": "480p",
    "aspect_ratio": "16:9",
    "generate_audio": false,
    "image": {
      "url": "https://example.com/start.jpg"
    },
    "keyframes": [
      {
        "image": {
          "url": "https://example.com/middle.jpg"
        },
        "timestamp_s": 1
      }
    ],
    "last_frame": {
      "url": "https://example.com/end.jpg"
    }
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1/videos",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"model\": \"grok-imagine-video-1.5\",\n  \"prompt\": \"A paper boat floats on a calm lake. Locked camera, soft daylight.\",\n  \"duration\": 3,\n  \"resolution\": \"480p\",\n  \"aspect_ratio\": \"16:9\",\n  \"generate_audio\": false,\n  \"image\": {\n    \"url\": \"https://example.com/start.jpg\"\n  },\n  \"keyframes\": [\n    {\n      \"image\": {\n        \"url\": \"https://example.com/middle.jpg\"\n      },\n      \"timestamp_s\": 1\n    }\n  ],\n  \"last_frame\": {\n    \"url\": \"https://example.com/end.jpg\"\n  }\n}")
)
response.raise_for_status()
print(response.json())
```

## 参考图生视频

```json
{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false,
  "reference_images": [
    {
      "url": "https://example.com/character.jpg"
    },
    {
      "url": "https://example.com/style.jpg"
    }
  ]
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1/videos' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "grok-imagine-video-1.5",
  "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
  "duration": 3,
  "resolution": "480p",
  "aspect_ratio": "16:9",
  "generate_audio": false,
  "reference_images": [
    {
      "url": "https://example.com/character.jpg"
    },
    {
      "url": "https://example.com/style.jpg"
    }
  ]
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/videos", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "grok-imagine-video-1.5",
    "prompt": "A paper boat floats on a calm lake. Locked camera, soft daylight.",
    "duration": 3,
    "resolution": "480p",
    "aspect_ratio": "16:9",
    "generate_audio": false,
    "reference_images": [
      {
        "url": "https://example.com/character.jpg"
      },
      {
        "url": "https://example.com/style.jpg"
      }
    ]
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1/videos",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"model\": \"grok-imagine-video-1.5\",\n  \"prompt\": \"A paper boat floats on a calm lake. Locked camera, soft daylight.\",\n  \"duration\": 3,\n  \"resolution\": \"480p\",\n  \"aspect_ratio\": \"16:9\",\n  \"generate_audio\": false,\n  \"reference_images\": [\n    {\n      \"url\": \"https://example.com/character.jpg\"\n    },\n    {\n      \"url\": \"https://example.com/style.jpg\"\n    }\n  ]\n}")
)
response.raise_for_status()
print(response.json())
```

## 响应示例

### 任务已排队 — HTTP 200

```json
{
  "id": "task_example",
  "object": "video",
  "model": "grok-imagine-video-1.5",
  "status": "queued",
  "progress": 0
}
```

## 使用说明

- 此渠道支持 Grok 1.5 视频生成，不支持视频编辑、延长、音频参考、storage_options 或自定义输出上传。

- 保存创建响应中的 id 原值，使用查询接口检查状态，不要重复提交创建请求。

## 相关接口

- [获取 Grok 视频](https://www.unifyllm.com/zh/docs/api-reference/get-grok-video/)
- [下载 Grok 视频](https://www.unifyllm.com/zh/docs/api-reference/download-grok-video/)
