> ## 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.

# Kling 2.5 Turbo Pro API：快速生成高質量影片

> 透過文字轉影片、圖生影片和尾影格控制快速生成高品質影片

## 概覽

若要結束特定構圖的拍攝，請選擇 `image-to-video`，並將開頭影像放在第一位，所需的最終影格放在第二位於 `image_urls`。對於僅有起始影格的動畫，發送一個 URL。將剪輯長度設定為 `5` 或 `10` 秒，在 [圖生影片的請求](#image-to-video) 中。

| 功能 | 值 |
| - | - |
| 模型 ID | `kling-2-5-turbo-pro` |
| 模式 | `text-to-video`, `image-to-video` |
| 提示詞長度 | 1 至 2500 個字元 |
| 長度 | `5` 或 `10` 秒 |
| 參考圖片 | 1-2 個 `image-to-video` 的 URL |
| 尾影格控制 | `image_urls` 的第二項用作最終影格 |
| 縱橫比 | `16:9`、`9:16`、`1:1` 對應 `text-to-video` |
| 負面提示 | 最多 2500 個字元 |
| CFG 刻度 | `0` 至 `1`，步長 `0.1` |
| 輸出 | MP4 影片網址位於 `resultJson.resultUrls` |

## 端點與身分驗證

API 基底網址：

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

| 方法 | 端點 | 用途 |
| - | - | - |
| `POST` | `/generateTask/kling-2-5-turbo-pro` | 送出生成任務 |
| `GET` | `/statusTask/kling-2-5-turbo-pro?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/kling-2-5-turbo-pro" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-video",
      "prompt": "a cinematic drone shot over snowy mountains at sunrise",
      "duration": 5,
      "aspect_ratio": "16:9"
    }
  }'
```

成功回應：

```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/kling-2-5-turbo-pro?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": 1767965652317,
    "costTime": 41388
  }
}
```

任務失敗時的回應範例：

```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 drone shot over snowy mountains at sunrise",
    "duration": 10,
    "aspect_ratio": "16:9",
    "negative_prompt": "low quality, jitter, blur",
    "cfg_scale": 0.6
  }
}
```

### 圖生影片

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-video",
    "prompt": "smooth camera transition from the first frame to the final frame",
    "duration": 5,
    "image_urls": [
      "https://example.com/start.jpg",
      "https://example.com/end.jpg"
    ],
    "negative_prompt": "distortion, low quality",
    "cfg_scale": 0.4
  }
}
```

## 參數

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

取得結果的方式。選擇 `async` 時，透過 `statusTask` 輪詢結果；選擇 `callback` 時，透過 Webhook 接收結果。

**callback\_url** `string`

當 `request_type` 為 `callback` 時必填。請提供可從網際網路存取的 HTTPS 網址，以接收任務的最終結果。詳見 [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)。

**input** `object` *required*

Kling 2.5 Turbo Pro 的輸入參數。

**屬性**

**mode** `string` *required*

生成模式。可用值為 `text-to-video`、`image-to-video`。

**prompt** `string` *required*

描述影片的文字提示。修剪後必須非空且長度不能超過 2500 個字元

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

輸出持續時間（以秒為單位）。支援的值：`5`、`10`。也接受 `"5"` 等數字字串

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

`image-to-video` 所需。支援 1-2 公用影像 URL。第一個影像是起始畫面；第二張圖片（如果有提供）是尾框。每張影像必須為 JPG、JPEG 或 PNG，不大於 10 MB，每邊至少 300 個像素，且寬高比為 0.4 到 2.5

**aspect\_ratio** `string` (default: 16:9)

`text-to-video` 的輸出縱橫比。支援的值：`16:9`、`9:16`、`1:1`。不會為 `image-to-video` 轉送此欄位

**negative\_prompt** `string`

描述要避免的內容的負面提示。最多支援 2500 個字元。空白值將被忽略

**cfg\_scale** `number | string`

提示指導尺度。支援的值為 `0` 到 `1`，步長為 `0.1`，例如 `0`、`0.4`、`0.7` 或 `1`。接受數字字串

## 回應格式

### 送出任務時的回應

任務受理後，`POST /generateTask/kling-2-5-turbo-pro` 會傳回任務 ID：

**code** `integer`

API 狀態碼。`200` 表示任務已受理。

**message** `string`

狀態說明。

**data.taskId** `string`

任務的唯一 ID，用於查詢任務狀態。

### 狀態回應欄位

**taskId** `string`

任務的唯一識別碼。

**state** `string`

目前的任務狀態，可能的值為 `pending`、`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/kling-2-5-turbo-pro" \
  -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": "image-to-video",
      "prompt": "make the subject turn toward camera with smooth natural motion",
      "duration": 5,
      "image_urls": [
        "https://example.com/start.jpg"
      ],
      "cfg_scale": 0.5
    }
  }'
```

Webhook 交付使用與狀態回應相同的最終任務負載形狀。請參閱 [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)。

Kling 2.5 Turbo Pro 按影片時長計費。公開 APIXO 定價頁面列出了此型號，起始 APIXO 價格為 `$0.06 / second`。

| 長度 | 起始 APIXO 價格 |
| - | - |
| `5`秒 | `$0.30 / video` |
| `10`秒 | `$0.60 / video` |

最新的美元費率請見 [API 價目表](https://apixo.ai/pricing/api)。

## 耗時與輪詢

實際延遲可能會因提示複雜性、輸入影像、所選路線和當前佇列負載而異。

| 長度 | 一般生成時間 | 建議首次查詢時間 | 輪詢間隔 |
| - | - | - | - |
| `5`秒 | 30s-45s | 任務建立 30 秒後 | 5s-10s |
| `10`秒 | 45s-60s | 任務建立 30 秒後 | 5s-10s |

> [!TIP]
>
> 對於生產影片工作負載，請使用回呼模式以避免頻繁輪詢。完成後立即下載並儲存重要的輸出 URL。

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

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 請求主體、模式、參數值或影像 URL 形狀無效 | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `403` | 鍵或路由無法存取模型，或內容被拒絕 | 檢查權限並調整輸入 |
| `404` | 未找到任務 ID 或路線 | 檢查模型端點和`taskId` |
| `429` | 已達到速率或並行限制 | 以指數退避方式重試 |
| `500` | 伺服器錯誤或未知任務失敗 | 逐步拉長間隔後重試 |
| `503` | 服務暫時無法使用 | 逐步拉長間隔後重試 |
| `504` | 服務超時 | 重新嘗試；耗時較長的任務可改用回呼模式 |

### 參數驗證

| 欄位 | 規則 |
| - | - |
| `input.mode` | 必填。必須使用下列其中一個值：`text-to-video`、`image-to-video`。 |
| `input.prompt` | 必填字串，修剪後非空，最多 2500 個字元。 |
| `input.duration` | 必需的。必須是`5`或`10`；接受整數和數字字串。 |
| `input.image_urls` | `image-to-video` 所需；必須是 1-2 字串陣列。 |
| `input.aspect_ratio` | `text-to-video` 可選；如果提供的話，必須是 `16:9`、`9:16` 或 `1:1`。 |
| `input.negative_prompt` | 可選字串，最多 2500 個字元。 |
| `input.cfg_scale` | 從 `0` 到 `1` 的可選數字或數字字串，步驟 `0.1`。 |

### 任務失敗代碼

| 錯誤碼 | 含義 | 處理方式 |
| - | - | - |
| `SensitiveContent` | 提示、輸入影像或產生的輸出違反內容安全要求 | 更改提示或影像 |
| `PromptInvalid` | 提示被拒絕或格式錯誤 | 用更清晰的安全內容重寫提示 |
| `PromptLengthExceeded` | 提示超出型號限制 | 縮短提示 |
| `ImageFormatIncorrect` | 無法處理輸入影像格式 | 使用公共 JPG、PNG 或 WebP URL |
| `Upload error` | 圖片上傳失敗或超出大小限制 | 壓縮影像並直接使用 URL 重試 |
| `RateLimited` | 請求頻率已達上限 | 稍後重試並退避 |
| `Timeout` | 任務逾時 | 重試、降低輸入複雜度或使用回呼模式 |
| `Unknown error` | 任務因不明原因失敗 | 重試並退避；如果問題仍然存在，請聯絡支援人員 |

完整列表見[錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)。

## MCP 整合

[完整模型 Schema](https://apixo.ai/docs/models/schemas/video/kling-2-5-turbo-pro.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)
* [嘗試 Kling 2.5 Turbo Pro 在 APIXO Playground](https://apixo.ai/models/kling-2-5-turbo-pro)
* [API定價](https://apixo.ai/pricing/api)


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