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

# Grok Imagine Video 視頻延長 (官方通道)

> 通過官方渠道延長已生成的 Grok Imagine 視頻

<Note>
  **中國大陸用戶請注意：** 中國大陸用戶請使用 `https://toapis.cn` 作為接口地址（Base URL）。文檔示例中的 `https://toapis.com` 請替換為 `https://toapis.cn`。
</Note>

* 官方渠道 Grok Imagine 視頻延長能力
* 將已有視頻延長 2-10 秒
* 異步任務管理，通過任務 ID 查詢結果

## Path Parameters

<ParamField path="video_id" type="string" required>
  原視頻任務 ID

  即此前視頻生成請求返回的任務 ID，該任務完成的視頻將作爲延長源。

  如需對任意視頻 URL 延長而不關聯源任務，使用 `POST /v1/videos/extend`，並在請求體中傳 `video_urls` 代替路徑參數。
</ParamField>

## Authorizations

<ParamField header="Authorization" type="string" required>
  所有接口均需要使用 Bearer Token 進行認證

  獲取 API Key：訪問 [API Key 管理頁面](https://toapis.com/console/token) 獲取您的 API Key

  使用時在請求頭中添加：

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Body

<ParamField body="model" type="string" default="grok-imagine-video-official" required>
  視頻延長模型名稱

  示例：`"grok-imagine-video-official"`
</ParamField>

<ParamField body="prompt" type="string" required>
  視頻延長的文本描述
</ParamField>

<ParamField body="duration" type="integer" default="6">
  延長時長（秒）

  支持範圍：`2`–`10` 秒
</ParamField>

<ParamField body="video_urls" type="string[]">
  源視頻 URL 列表。使用 `POST /v1/videos/extend` 且無任務 ID 時必填；路徑中已帶 `video_id` 時可選。

  支持公網 `http://`/`https://` URL 或平台 `asset://` 引用。
</ParamField>

<Note>
  **計費說明**：延長計費 = 生成的延長秒數 + **輸入源視頻時長** 按秒計費。源視頻時長由平台自動確定，請求中無需聲明。
</Note>

## Response

<ResponseField name="id" type="string">
  唯一任務標識，用於查詢任務狀態
</ResponseField>

<ResponseField name="object" type="string">
  對象類型，始終爲 `generation.task`
</ResponseField>

<ResponseField name="model" type="string">
  使用的模型名稱
</ResponseField>

<ResponseField name="status" type="string">
  任務狀態

  * `queued` - 排隊等待處理
  * `in_progress` - 處理中
  * `completed` - 已完成
  * `failed` - 失敗
</ResponseField>

<ResponseField name="progress" type="integer">
  任務進度百分比（0-100）
</ResponseField>

<ResponseField name="created_at" type="integer">
  任務創建時間戳（Unix 時間戳）
</ResponseField>

<ResponseField name="metadata" type="object">
  任務元數據
</ResponseField>

<RequestExample>
  ```bash cURL (按任務延長) theme={null}
  curl --request POST \
    --url https://toapis.com/v1/videos/tsk_vid_01M59KNFZA2N4QFP0TMGACYH98/extend \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "grok-imagine-video-official",
      "prompt": "繼續場景，讓狗跑向遠方",
      "duration": 6
    }'
  ```

  ```bash cURL (按 URL 延長) theme={null}
  curl --request POST \
    --url https://toapis.com/v1/videos/extend \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "grok-imagine-video-official",
      "prompt": "繼續場景，讓狗跑向遠方",
      "duration": 6,
      "video_urls": ["https://example.com/source-video.mp4"]
    }'
  ```

  ```python Python theme={null}
  import requests

  video_id = "tsk_vid_01M59KNFZA2N4QFP0TMGACYH98"

  response = requests.post(
      f"https://toapis.com/v1/videos/{video_id}/extend",
      headers={
          "Authorization": "Bearer your-ToAPIs-key",
          "Content-Type": "application/json"
      },
      json={
          "model": "grok-imagine-video-official",
          "prompt": "繼續場景，讓狗跑向遠方",
          "duration": 6
      }
  )

  task = response.json()
  print(f"Task ID: {task['id']}")
  print(f"Status: {task['status']}")
  ```

  ```javascript JavaScript theme={null}
  const videoId = 'tsk_vid_01M59KNFZA2N4QFP0TMGACYH98';

  const response = await fetch(`https://toapis.com/v1/videos/${videoId}/extend`, {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer your-ToAPIs-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      model: 'grok-imagine-video-official',
      prompt: '繼續場景，讓狗跑向遠方',
      duration: 6
    })
  });

  const task = await response.json();
  console.log(`Task ID: ${task.id}`);
  console.log(`Status: ${task.status}`);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "tsk_vid_01M59KTYQS81W0QENN56SEJ85S",
    "object": "generation.task",
    "model": "grok-imagine-video-official",
    "status": "queued",
    "progress": 0,
    "created_at": 1768380224,
    "metadata": {}
  }
  ```
</ResponseExample>


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