> ## 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 API：xAI 文生视频与图生视频

> 使用 Grok Imagine Video API 生成 6-30 秒的视频。比较文本和图像输入、基于分辨率的图像限制、请求示例以及按秒计费。

## 概览

模型 ID 仍为 `grok-video`。请使用以下首选的 REST URL。旧的 `/generateTask/grok-video` 和 `/statusTask/grok-video` URL 仍受支持，参数和计费方式保持不变。

Grok Imagine Video 是 xAI 的视频模型，可根据文字或图片生成视频。在 APIXO Playground 试用后，可以按本页示例调用 API。

| 功能 | 值 |
| - | - |
| 模型 ID | `grok-video` |
| 模式 | `text-to-video`, `image-to-video` |
| 提示词长度 | 1 至 5000 个字符 |
| 时长 | 6-30 秒 |
| 可选分辨率 | `480p`, `720p`, `1080p` |
| 纵横比 | `1:1`, `3:2`, `2:3`, `16:9`, `9:16` |
| 图生视频源 | 最多 7 个图像 URL（`1080p` 支持 1 个），或已完成的 `grok-image` 任务，包含 `task_id` 和 `index` |
| 输出 | 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](https://apixo.ai/docs/zh/models/video/grok-imagine-video-1-5.md)。Grok Imagine Video 不提供这些帧级控制功能。多个 `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` | 提交生成任务 |
| `GET` | `/statusTask/grok-imagine-video?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" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-video",
      "prompt": "a peaceful lakeside at sunset with gentle waves",
      "duration": 6,
      "resolution": "480p",
      "aspect_ratio": "3:2",
      "style": "normal"
    }
  }'
```

成功响应：

```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?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/xxx.mp4\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965655929,
    "costTime": 45000
  }
}
```

任务失败时的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "SensitiveContent",
    "failMsg": "Content was rejected by safety checks, please adjust the prompt",
    "createTime": 1767965610929,
    "completeTime": 1767965620132
  }
}
```

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

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

## 请求体

### 文生视频

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "text-to-video",
    "prompt": "a cinematic city street after rain, soft reflections, slow camera push",
    "duration": 6,
    "resolution": "480p",
    "aspect_ratio": "3:2",
    "style": "normal"
  }
}
```

### 图像到视频（基于图像 URL）

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-video",
    "prompt": "make this scene into a short cinematic pan",
    "image_urls": [
      "https://example.com/ref.jpg"
    ],
    "duration": 10,
    "resolution": "720p",
    "aspect_ratio": "16:9",
    "style": "fun"
  }
}
```

### 由 Grok Imagine Image 任务生成的图生视频

使用成功完成的 [Grok Imagine Image](https://apixo.ai/docs/zh/models/image/grok-imagine-image.md) 任务，并选择带有 `index`（`0` 至 `5`）的可用结果。该操作将静止图像动画化为新视频，不会扩展已有视频。请勿在同一个请求中包含 `image_urls`。

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-video",
    "prompt": "turn this character into a walking animation",
    "task_id": "task_previous_grok_image",
    "index": 0,
    "duration": 10,
    "resolution": "720p",
    "aspect_ratio": "16:9",
    "style": "spicy"
  }
}
```

## 参数

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

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

**callback\_url** `string`

当 `request_type` 为 `callback` 时必需。请提供一个可接收最终任务负载的公开 HTTPS URL。详情请参阅 [Webhooks](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

**input** `object` *required*

Grok Imagine Video 的输入参数。

**属性**

**mode** `string` *required*

生成模式。可选值为 `text-to-video`、`image-to-video`。

**prompt** `string` *required*

用文字描述要生成的视频。长度须为 1 至 5000 个字符。提示词为空时，请求会被拒绝。

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

Output持续时间（以秒为单位）。支持从 `6` 到 `30` 的整数。诸如 `"10"` 之类的数字字符串在计费前会被接受并标准化。

**resolution** `string` *required*

输出分辨率。支持的值：`480p`、`720p`、`1080p`。值会被修剪并转换为小写。

**aspect\_ratio** `string`

输出纵横比。支持的值：`1:1`、`3:2`、`2:3`、`16:9`、`9:16`。若未指定，`text-to-video` 使用 `3:2`，`image-to-video` 使用 `16:9`。

**style** `string` (default: normal)

运动风格。支持的值：`fun`、`normal`、`spicy`。`spicy` 适用于任务延续或重新创建类工作流。

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

直接 `image-to-video` 方法的参考图像 URL。支持 1-7 个公共、非空的 URL（适用于 `480p` 和 `720p`）；`1080p` 支持 1 个 URL。不得与 `task_id` + `index` 方法同时使用。

**task\_id** `string`

来自成功完成的 `grok-image` 任务的 APIXO 任务 ID。与 `index` 结合使用，可将该任务中的某张图像结果动画化为新视频。此功能并非视频扩展。不得与 `image_urls` 同时使用。

**index** `integer`

已完成 `grok-image` 任务的结果索引。需与 `task_id` 一起使用，支持范围为 `0` 至 `5`。

## 响应格式

### 提交任务时的响应

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

**code** `integer`

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

**message** `string`

状态说明。

**data.taskId** `string`

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

### 状态响应字段

**taskId** `string`

任务的唯一标识符。

**state** `string`

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

**resultJson** `string`

JSON 字符串，包含 `resultUrls` 中生成的视频 URL。当 `state` 为 `success` 时存在。

**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" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "text-to-video",
      "prompt": "a clean product reveal video with a slow camera push-in",
      "duration": 6,
      "resolution": "480p",
      "aspect_ratio": "3:2",
      "style": "normal"
    }
  }'
```

回调传递使用与状态响应相同的最终有效负载形状。详情请参阅 [Webhooks](https://apixo.ai/docs/zh/api-reference/webhooks.md) 了解交付要求和重试行为。

## 计费

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

以上价格与主要 [API Pricing](https://apixo.ai/pricing/api) 目录的公共基础价格表（2026 年 10 月 30 日更新）一致。在预算前，请确认该页面的最新费率及账户折扣。

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

| 分辨率 | APIXO 价格 | 市场参考价 | 最低有效请求成本 |
| - | - | - | - |
| `480p` | `$0.024 / second` | `$0.060 / second` | `$0.144` 持续 6 秒 |
| `720p` | `$0.045 / second` | `$0.080 / second` | `$0.270` 持续 6 秒 |
| `1080p` | `$0.080 / second` | `$0.120 / second` | `$0.480` 持续 6 秒 |

市场参考价单独设定，仅供比较，不影响实际收费。

公式：

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

在任何账号折扣之前，10 秒的请求费用为 `$0.240`、`480p`、`$0.450`、`720p` 或 `$0.800`、`1080p`。这些总数适用于两种支持的模式。

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

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

## 延迟与轮询

用户手册列出了典型的 Grok Imagine Video 生成时间，约为 40 秒至 60 秒。实际延迟可能因提示复杂性、持续时间、分辨率、队列负载和存储传输时间而异。

| 工作量 | 通常生成耗时 | 建议首次查询时间 | 轮询间隔 |
| - | - | - | - |
| `480p`、`720p` 或 `1080p`、6-30 秒 | 约40s-60s | 任务创建 30 秒后 | 5s |

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

结果 URL 的有效期为 15 天。请及时下载并存储重要输出。

> 对于图生视频，仅使用一种源方法：`image_urls` 或 `task_id` 和 `index`。可公开访问的图像 URL 应直接指向 JPG、PNG 或 WebP 文件，并且应可由 APIXO 访问。

> 提示可以用英文或中文书写。更具体的相机运动、场景定时、主体动作、灯光和风格细节通常会产生更好的效果。

请求频率和并发上限因账号、API 密钥和路由而异。收到 `429` 时，请降低请求频率，逐步延长重试间隔。账号级限制见[系统 API](https://apixo.ai/docs/zh/api-reference/system.md)。

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | >请求体无效、缺少 `mode`、缺少 `prompt`、无效 `duration`、无效 `resolution`、图像输入格式错误或无效 `task_id`/`index` | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `404` | 轮询时未找到任务 | 检查`taskId` |
| `429` | 已达到速率或并发限制 | 按指数退避策略重试 |
| `500` | 内部错误或未知任务失败 | 重试后退或联系支持人员（如果问题仍然存在） |
| `502` | 服务或网络错误 | 逐步延长间隔后重试 |
| `503` | 服务暂时不可用 | 稍后重试 |
| `504` | 服务超时 | 稍后重试或对长时间运行的作业使用回调模式 |

### 验证说明

| 参数 | 后端行为 |
| - | - |
| `input.mode` | >路由所需。必须是`text-to-video`或`image-to-video`。 |
| `input.prompt` | 必需的字符串。不能为空且不能超过 5000 个字符。 |
| `input.duration` | >必需的。接受整数或整数字符串。必须解析为 `6` 到 `30` 之间的值。 |
| `input.resolution` | >必需的字符串。`480p`、`720p` 和 `1080p` 在修剪和小写后被接受。 |
| `input.aspect_ratio` | >可选的。必须是其中之一 `1:1`、`3:2`、`2:3`、`16:9`、`9:16` 当提供时。默认值为 `3:2`（用于 `text-to-video`）和 `16:9`（用于 `image-to-video`）。 |
| `input.image_urls` | 对于直接 `image-to-video`，一种可接受的源方法。必须是非空字符串数组。`480p` 和 `720p` 最多支持 7 个 URL；`1080p` 支持 1 个 URL。 |
| `input.task_id` | 对于 `image-to-video`，备用源方法。必须是现有已完成的 APIXO `grok-image` 任务。 |
| `input.index` | 需与 `task_id` 一起使用。必须是 `0` 到 `5` 之间的整数。 |
| `input.style` | 可选。必须是 `fun`、`normal` 或 `spicy`；省略时默认为 `normal`。 |

### 任务失败错误码

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

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

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

## MCP 集成

[完整模型 Schema](https://apixo.ai/docs/models/schemas/video/grok-imagine-video.json) 中的 `mcp.result` 指定了结果的解析方式，`mcp.attachments` 列出支持绑定文件的字段。这些元数据供客户端集成使用，无需作为生成参数提交。附件字段为 `image_urls`。请保留用户指定的文件顺序。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](https://apixo.ai/models/grok-video)
* [API定价](https://apixo.ai/pricing/api)


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