> ## Documentation Index
> Fetch the complete documentation index at: https://apixo.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Grok Imagine Video 1.5 API：将静态图像生成为动画

> 使用 Grok Imagine Video 1.5 生成包含参考图像、第一帧和最后一帧、定时关键帧和循环图像的短视频

## 概览

Grok Imagine Video 1.5 从参考图像、第一帧和最后一帧、定时中间关键帧或循环图像生成短视频。使用文本提示来指导动作、摄像机移动和场景变化。

| 功能 | 值 |
| - | - |
| 模型 ID | `grok-imagine-video-1-5` |
| 模式 | `image-to-video` |
| 提示词长度 | 1 至 5000 个字符 |
| 参考图片 | 可选；最多 7 帧，分辨率支持 `480p` 或 `720p`，最多 1 帧支持 `1080p` |
| 帧控制 | 可选的第一帧、最后一帧、循环图像和最多 4 个定时中间关键帧 |
| 时长 | 从 `1` 到 `15` 秒的整数或整数字符串 |
| 可选分辨率 | `480p`、`720p`、`1080p`；对 `1080p` 使用单个第一帧，并推荐使用 `720p` 作为组合帧控制的首选分辨率 |
| 纵横比 | `auto`, `1:1`, `16:9`, `9:16`, `3:2`, `2:3` |
| 输出 | MP4 视频 URL 数组位于 `resultJson.resultUrls` 字段中 |

## 选择 Grok 视频端点

| APIXO 端点 | 模式 | 时长 | 直接图像输入 |
| - | - | - | - |
| [Grok Imagine Video](https://apixo.ai/docs/zh/models/video/grok-imagine-video.md) | 文本转视频和图像转视频 | 6-30整秒 | 1-7在`480p`或`720p`处；1在`1080p` |
| [Grok Imagine Video 1.5](https://apixo.ai/docs/zh/models/video/grok-imagine-video-1-5.md) | 仅图生视频 | 1-15整秒 | 最多 7 在 `480p` 或 `720p`；1 在 `1080p`；还提供专用帧控件 |

这些端点生成新的剪辑；两者都不公开视频输入编辑或本机视频扩展。Grok Imagine Video 1.5 支持专用的第一帧/最后一帧、定时关键帧和循环图像，如下所述。多个 `image_urls` 条目仍然是参考图像，而不是第一帧/最后一帧对。xAI 的原生扩展功能是一个单独的 API 功能；不要将其参数发送到这些 APIXO 端点。

对于由单独剪辑组合而成的较长序列，请参阅 [Grok 较长视频工作流程](https://apixo.ai/blog/grok-video-longer-clips-workflow)。它解释了剪辑规划和编辑，并将此工作流程与本机视频扩展区分开来。

## 接口与身份验证

API 基础地址：

```text theme={null}
https://api.apixo.ai/api/v1
```

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/grok-imagine-video-1-5` | 提交视频生成任务 |
| `GET` | `/statusTask/grok-imagine-video-1-5?taskId={taskId}` | 查询任务状态并获取结果 |

每个请求都必须携带 APIXO API 密钥：

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

提交任务时，还需要设置以下请求头：

```http theme={null}
Content-Type: application/json
```

## 异步请求示例

此最小请求提交图生视频任务并返回 `taskId`。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/grok-imagine-video-1-5" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "prompt": "turn this product photo into a smooth rotating studio shot",
      "image_urls": [
        "https://example.com/product.png"
      ],
      "resolution": "480p",
      "duration": 5
    }
  }'
```

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

保存 `taskId`，后续轮询结果时需要用到它。

## 轮询结果

```bash theme={null}
curl -X GET "https://api.apixo.ai/api/v1/statusTask/grok-imagine-video-1-5?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

任务处理中的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "processing",
    "createTime": 1767965610929
  }
}
```

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/video.mp4\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

任务失败时的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "CONTENT_VIOLATION",
    "failMsg": "Content does not meet safety guidelines",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

等 `state` 变为 `success` 后，再解析 `resultJson`：

```javascript theme={null}
const payload = JSON.parse(data.resultJson);
const videoUrls = payload.resultUrls;
```

## 请求体

### 图生视频

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-video",
    "prompt": "make this portrait move with a subtle cinematic camera push",
    "image_urls": [
      "https://example.com/ref.jpg"
    ],
    "aspect_ratio": "16:9",
    "resolution": "720p",
    "duration": "8"
  }
}
```

`mode` 字段在此端点上是可选的。如果省略，APIXO 使用 `image-to-video`。

### 第一帧、最后一帧和定时中间帧

```json theme={null}
{
  "request_type": "async",
  "input": {
    "prompt": "The character raises a hand, then turns around and sits down.",
    "first_frame_url": "https://example.com/start.jpg",
    "last_frame_url": "https://example.com/end.jpg",
    "keyframes": [
      { "url": "https://example.com/raise-hand.jpg", "timestamp_s": 2.5 },
      { "url": "https://example.com/turn-around.jpg", "timestamp_s": 5 }
    ],
    "resolution": "720p",
    "duration": 8
  }
}
```

### 循环视频

```json theme={null}
{
  "input": {
    "prompt": "Gentle continuous motion, returning smoothly to the opening pose.",
    "loop_url": "https://example.com/loop.jpg",
    "resolution": "720p",
    "duration": 8
  }
}
```

### 1080p单个第一帧

```json theme={null}
{
  "input": {
    "prompt": "A gentle camera push toward the landscape.",
    "first_frame_url": "https://example.com/landscape.jpg",
    "resolution": "1080p",
    "duration": 5
  }
}
```

> [!WARNING]
>
> 对于 `1080p`，使用单个第一帧图像。`1080p` 目前不支持将第一帧和最后一帧与定时中间关键帧结合；建议使用 `720p` 以获得更佳的帧控制体验。单参考图像限制并不意味着所有帧控制组合均支持 `1080p`。任务接受不等于生成成功：需轮询直至 `state` 状态为 `success` 或 `failed`，若生成失败则读取 `failMsg` 字段。

## 参数

**request\_type** `string` (default: async)

指定如何获取结果。省略此字段或设为 `async` 时，可通过 `statusTask` 轮询；设为 `callback` 时，通过 Webhook 接收。

**callback\_url** `string`

当 `request_type` 为 `callback` 时必填。请提供公网可访问的 HTTPS 地址，用于接收任务的最终结果。详见 [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

**input** `object` *required*

Grok Imagine Video 1.5 输入参数。通过非空 image\_urls 数组、first\_frame\_url、last\_frame\_url、loop\_url 或非空 keyframes 数组提供至少一个图像输入。使用单个首帧，分辨率为 1080p；对于组合帧控制，优先使用 720p。

**属性**

**mode** `string` (default: image-to-video)

可选的生成模式。该端点仅支持 `image-to-video`。

**prompt** `string` *required*

文本提示用于描述期望的运动、摄像机移动和场景变化。支持 1-5000 个字符，空提示将被拒绝。

**image\_urls** `string[]`

可选的公开 HTTP(S) 参考图像 URL：最多 7 张，分辨率 480p 或 720p，最多 1 张 1080p。这些是参考图像，而非有序的第一帧/最后一帧对。当提供其他图像输入时，可省略或为空。空字符串和非字符串数组项将被拒绝。该数量仅适用于该数组，不包括第一帧/最后一帧或关键帧。

**first\_frame\_url** `string`

可选的非空公开 HTTP(S) 第一帧图像 URL。可单独使用，也可与支持分辨率的参考图像、最后一帧和定时关键帧一起使用。当提供 loop\_url 时将被忽略，即使其值在其他情况下无效。对于 1080p，使用单张第一帧图像。

**last\_frame\_url** `string`

可选的非空公开 HTTP(S) 最后一帧图像 URL。可单独使用，也可与支持分辨率的其他图像输入一起使用。当提供 loop\_url 时将被忽略，即使其值在其他情况下无效。在组合帧控制场景中，推荐使用 720p。

**loop\_url** `string`

可选的非空公开 HTTP(S) 图像 URL，用于开始和结束帧。优先于 first\_frame\_url 和 last\_frame\_url：当提供 loop\_url 时，这两个字段将被忽略。仍可包含参考图像和定时关键帧。在循环工作流中推荐使用 720p。

**keyframes** `object[]`

最多 4 个定时中间帧的可选数组。每个对象需提供 url（一个非空的公开 HTTP(S) 图像 URL）和 timestamp\_s（以秒为单位的有限 JSON 数值）。支持小数时间，不支持数字字符串。每次时间必须大于 0 且小于持续时间，任意两次时间间隔至少为 1/3 秒。指定的时间将被保留，不会自动分配。可单独使用，也可与支持分辨率的其他图像输入结合使用。对于组合帧控制，推荐使用 720p 分辨率。

**resolution** `string` *required*

输出分辨率等级。支持的值：`480p`、`720p`、`1080p`。值不区分大小写。对于 1080p，需使用单个首帧图像；目前不支持将首帧和末帧与定时中间关键帧组合使用。对于组合帧控制，推荐使用 720p。通过轮询最终任务状态来判断生成是否成功。

**duration** `integer|string` *required*

输出持续时间（单位：秒）。支持 JSON 整数或范围在 `1` 到 `15` 之间的整数字符串。小数和负数均无效。

**aspect\_ratio** `string` (default: auto)

输出画面的宽高比。可选值为 `auto`、`1:1`、`16:9`、`9:16`、`3:2`、`2:3`。

> [!TIP]
>
> 使用公开且可直接访问的图像 URL。建议选择主体清晰、画面中无遮挡的源图像，以获得更可预测的运动效果。

## 响应格式

### 提交任务时的响应

任务受理后，`POST /generateTask/grok-imagine-video-1-5` 会返回任务 ID：

**code** `integer`

API 状态码。`200` 表示任务已受理。

**message** `string`

状态说明。

**data.taskId** `string`

任务的唯一 ID，用于查询任务状态。

### 状态响应字段

**taskId** `string`

任务的唯一标识符。

**state** `string`

当前任务状态，可能的值为 `processing`、`success`、`failed`。

**resultJson** `string`

当 `state` 为 `success` 时返回。解析此 JSON 字符串后，可从 `resultUrls` 读取生成的视频链接。

**failCode** `string`

供程序处理的错误码，仅在 `state` 为 `failed` 时返回。

**failMsg** `string`

失败原因说明，仅在 `state` 为 `failed` 时返回。

**createTime** `integer`

任务创建时的 Unix 时间戳，单位为毫秒。

**completeTime** `integer`

任务完成时的 Unix 时间戳，单位为毫秒。任务完成后返回。

**costTime** `integer`

处理耗时，以毫秒为单位。有计时数据时返回。

## Webhook 回调模式

如果希望服务端自动收到最终结果，可以使用回调模式，无需轮询。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/grok-imagine-video-1-5" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "prompt": "make this character smile and look toward the camera",
      "image_urls": [
        "https://example.com/character.jpg"
      ],
      "resolution": "720p",
      "duration": 10
    }
  }'
```

回调数据与轮询响应具有相同的顶层字段：`code`、`message` 和 `data`。任务成功时，回调还会包含最终的 `state` 和 `resultJson`。接收要求与重试规则见 [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

## 计费

新提交的非 LLM 请求按 **1 积分 = `$0.001`** 计费。先按用量和附加项目计算总额，再应用账号折扣，最后将请求总额向上取整到整数积分。如果约定了固定单价，则按该单价的原始精度计算，不再使用标准价或另行打折；最终积分仍向上取整。详见[积分换算与取整](https://apixo.ai/docs/zh/pricing.md#credit-conversion-and-rounding)。

Grok Imagine Video 1.5 按秒计费。所选的`resolution`决定每秒单价，提交的`duration`决定计费秒数。

| 分辨率 | APIXO 价格 | 最低有效请求成本 | 市场参考价 |
| - | - | - | - |
| `480p` | `$0.024 / second` | `$0.024` 持续 1 秒 | `$0.080 / second` |
| `720p` | `$0.045 / second` | `$0.045` 持续 1 秒 | `$0.140 / second` |
| `1080p` | `$0.080 / second` | `$0.080` 持续 1 秒 | `$0.200 / second` |

市场参考价为比较值，而非实际收费金额。在账号折扣前，10秒请求的费用为 `$0.240`、`$0.450` 或 `$0.800`，分别对应 `480p`、`720p` 和 `1080p`。

公式：

```text theme={null}
total cost = duration * resolution unit price
```

参考图像计数、第一帧和最后一帧、定时关键帧和循环图像不会增加费用。具有相同分辨率和持续时间的请求使用相同的定价。

以上是以美元计价的 API 使用费。Studio 的包月积分不能用于抵扣 API 调用费用。

最新的美元费率见 [API 价目表](https://apixo.ai/pricing/api)。

## 延迟与轮询

Grok Imagine Video 1.5 任务是异步的。实际延迟可能因提示复杂性、图像可访问性、持续时间、分辨率和生成队列负载而异。

| 工作量 | 通常生成耗时 | 建议首次查询时间 | 轮询间隔 |
| - | - | - | - |
| 图生视频，1-15 秒 | 因提示、图像数量、分辨率和持续时间而异 | 任务创建 30 秒后 | 5s |

> [!TIP]
>
> 生产环境建议使用回调，避免在视频生成期间频繁轮询。

结果链接有时效。任务完成后，请尽快下载并保存重要文件。

速率限制和并发性可能因账户和 API 密钥而异。若收到 `429`，请减慢请求并使用退避重试。有关账户级别的详细信息，请参阅 [系统 API](https://apixo.ai/docs/zh/api-reference/system.md)。

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | 请求体无效、缺少 `input`、不受支持的 `mode`、缺少 `prompt`、无图像输入、无效 `resolution`、无效 `duration` 或无效的帧参数 | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `403` | 密钥或路由无权访问该模型 | 检查权限和路由策略 |
| `404` | 轮询时未找到任务 | 检查`taskId` |
| `429` | 已达到速率或并发限制 | 按指数退避策略重试 |
| `500` | 服务器错误或未知任务失败 | 逐步延长间隔后重试 |
| `502` | 服务错误 | 逐步延长间隔后重试 |
| `504` | 服务超时 | 稍后重试或对长时间运行的作业使用回调模式 |

### 验证说明

| 条件 | 后端行为 |
| - | - |
| 缺少 `input` | 请求会被拒绝，系统不会创建任务。 |
| 缺少 `mode` | APIXO 使用 `image-to-video`。 |
| 不支持的 `mode` 值 | 请求在任务创建前失败。该端点仅支持 `image-to-video`。 |
| 缺少 `prompt` | 请求会被拒绝，系统不会创建任务。 |
| `prompt` 为空或超过 5000 个字符 | 请求会被拒绝，系统不会创建任务。 |
| `image_urls`、`first_frame_url`、`last_frame_url`、`loop_url` 或 `keyframes` 中没有输入非空图像 | 请求会被拒绝，系统不会创建任务。 |
| `image_urls` 不是数组、包含空字符串或包含非字符串项 | 请求会被拒绝，系统不会创建任务。 |
| 分辨率为 `480p` 或 `720p` 时，`image_urls` 超过 7 个；为 `1080p` 时超过 1 个 | 请求会被拒绝，系统不会创建任务。 |
| `loop_url` 与 `first_frame_url` 或 `last_frame_url` 一起提供 | 第一帧/最后一帧字段被忽略；参考图像和关键帧仍然可用 |
| 超过 4 个关键帧、缺少关键帧字段、无效时间或间隔时间少于 1/3 秒 | 请求会被拒绝，系统不会创建任务。 |
| `1080p` 具有第一帧/最后一帧和定时中间关键帧 | 目前不可用。使用 `720p`；已接受的任务仍可以以 `state=failed` 完成 |
| 缺少 `resolution` | 请求会被拒绝，系统不会创建任务。 |
| 不支持的 `resolution` 值 | 请求会被拒绝，任务不会创建。可选值为 `480p`、`720p`、`1080p`。 |
| 缺少 `duration` | 请求会被拒绝，系统不会创建任务。 |
| `duration` 超出 `1` 到 `15` 范围，支持小数或负数 | 请求会被拒绝，系统不会创建任务。 |
| 缺少 `aspect_ratio` | 默认值为 `auto`。 |
| 不支持的 `aspect_ratio` 值 | 任务创建之前请求失败。请使用 `auto`、`1:1`、`16:9`、`9:16`、`3:2` 或 `2:3`。 |

### 任务失败错误码

`failCode` 表示任务失败的原因，常见值如下。

| 错误码 | 含义 | 处理方式 |
| - | - | - |
| `SensitiveContent` | 提示或输入/输出内容被安全检查拒绝 | 更改提示或参考图像 |
| `PromptInvalid` | 提示词无效或被拒绝 | 修改提示词后重试 |
| `ImageFormatIncorrect` | 无法处理参考图像格式 | 提供公开可访问的图片直链，并使用常见图片格式 |
| `RateLimited` | 请求频率达到上限 | 按指数退避策略重试 |
| `Timeout` | 任务超时 | 稍后重试或使用回调模式 |
| `Unknown error` | 任务因未知原因失败 | 逐步延长间隔后重试，或联系支持团队并提供 `taskId` |

完整列表见[错误码](https://apixo.ai/docs/zh/api-reference/errors.md)。

## MCP 集成

[完整模型架构](https://apixo.ai/docs/models/schemas/video/grok-imagine-video-1-5.json) 在 `mcp.result` 中声明结果解码，并在 `mcp.attachments` 中声明支持的文件绑定。这些是客户端集成元数据，而非生成输入参数。附件路径：`image_urls`、`first_frame_url`、`last_frame_url`、`loop_url`、`keyframes[].url`。需保留用户的文件顺序。对于包含 `[]` 的路径，在 `input` 中提供父数组项及其元数据，然后将文件绑定到显式项索引，例如 `[0]`。模型参数验证仍由 API 负责。

## 相关链接

* [生成 API 概览](https://apixo.ai/docs/zh/models.md)
* [视频模型](https://apixo.ai/docs/zh/models/video)
* [提交生成任务](https://apixo.ai/docs/zh/api-reference/generate-task.md)
* [查询任务状态](https://apixo.ai/docs/zh/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)
* [错误码](https://apixo.ai/docs/zh/api-reference/errors.md)
* [参数规范](https://apixo.ai/docs/zh/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh/concepts/routing-strategies.md)
* [在 APIXO Playground 试用 Grok Imagine Video 1.5](https://apixo.ai/models/grok-imagine-video-1-5)
* [API定价](https://apixo.ai/pricing/api)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.