> ## 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-hant/models/video/grok-imagine-video.md) | 文字轉影片和影像轉影片 | 6-30 整秒 | 1-7 在 `480p` 或 `720p`；1 在 `1080p` |
| [Grok Imagine Video 1.5](https://apixo.ai/docs/zh-hant/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-hant/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-hant/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-hant/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*

輸出持續時間（以秒為單位）。支援從 `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`

APIXO 任務 ID 來自成功完成的 `grok-image` 任務。與 `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-hant/api-reference/webhooks.md) 以了解傳送要求與重試行為。

## 計費

新提交的非 LLM 請求按 **1 點 = `$0.001`** 計費。先依用量和加購項目計算總額，再套用帳戶折扣，最後將請求總額無條件進位至整數點數。若已約定固定單價，則保留該單價的精度，不再使用標準價或另行打折；最終點數仍須進位。詳見[積分換算與進位](https://apixo.ai/docs/zh-hant/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 產生時間，約為 40s-60s。實際延遲可能會因提示複雜性、持續時間、解析度、佇列負載和儲存傳輸時間而異。

| 工作量 | 一般生成時間 | 建議首次查詢時間 | 輪詢間隔 |
| - | - | - | - |
| `480p`、`720p` 或 `1080p`，6-30 秒 | 約40秒至60秒 | 任務建立 30 秒後 | 5s |

> [!TIP]
>
> 正式環境建議使用回呼，以免在影片生成期間頻繁輪詢。

結果 URL 的有效期限為 15 天。及時下載並儲存重要輸出。

> 對於圖生影片，僅使用一種來源方法：`image_urls` 或 `task_id` 和 `index`。公用影像 URL 應直接指向 JPG、PNG 或 WebP 文件，並且應可由 APIXO 存取。

> 提示可以用英文或中文書寫。更具體的相機運動、場景定時、主體動作、燈光和風格細節通常會產生更好的效果。

請求頻率與並行數上限會依帳戶、API 金鑰和路由而異。收到 `429` 時，請降低請求頻率，並逐步拉長重試間隔。帳戶層級的限制請見[系統 API](https://apixo.ai/docs/zh-hant/api-reference/system.md)。

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | >請求主體無效、缺少 `mode`、缺少 `prompt`、無效 `duration`、無效 `resolution`、影像輸入格式錯誤或無效 `task_id`/`index` | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `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-hant/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-hant/models.md)
* [影片模型](https://apixo.ai/docs/zh-hant/models/video)
* [送出生成任務](https://apixo.ai/docs/zh-hant/api-reference/generate-task.md)
* [查詢任務狀態](https://apixo.ai/docs/zh-hant/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)
* [錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)
* [參數規範](https://apixo.ai/docs/zh-hant/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh-hant/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.