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

# Kling 4.0

> Kling 4.0 影片生成，支援 3-30 秒輸出、多關鍵影格和 Omni 參考。

Kling 4.0 支援文字生成影片、關鍵影格圖片生成影片及 Omni 參考生成／編輯。API 目前提供 720p、1080p，不提供 4k。Kling 4.0 Flash 是另一項產品能力，不能由此模型 ID 推斷支援。

使用 MixRoute Bearer Key 認證。kling-4.0 放在介面路徑，不放在請求主體的 model 欄位；保留原生 prompt/contents、settings、options 結構，不包裹 metadata。這些介面不代表 Kling 4.0 已支援 motion-control。

## 模型規格

| 欄位 | 說明 |
| - | - |
| `ID` | kling-4.0 |
| `POST` | [文字生成影片](https://mixroute.ai/docs/zh-Hant/api-reference/endpoint/kling-text-to-video.md) / [圖片生成影片](https://mixroute.ai/docs/zh-Hant/api-reference/endpoint/kling-image-to-video.md) / [Omni 參考與編輯](https://mixroute.ai/docs/zh-Hant/api-reference/endpoint/kling-omni-video.md) |

## 共用設定與選項

| 欄位 | 說明 |
| - | - |
| `settings.resolution` | 720p 或 1080p。廠商預設 1080p；在 MixRoute 請求中應明確指定，不沿用舊閘道預設值。 |
| `settings.duration` | 3-30 的整數秒。廠商優先採用明確設定，其次為提示詞中指定的時長，否則為 10 秒。Omni 編輯在回退到 10 秒前，會採用四捨五入後的 base\_video 時長。明確指定可避免歧義。 |
| `options` | 通用選項仍為 options.callback\_url、options.external\_task\_id、options.watermark\_info.enabled。自訂任務 ID 不是 MixRoute 輪詢 ID，也不代表請求具備冪等性。 |

純英文最多 26,000 字元，純非英文最多 11,000 字元；混合輸入須滿足 `E / 26000 + N / 11000 <= 1`。在提示詞中描述動作順序和鏡頭變化，不要照搬舊版 multi\_shot 開關。 E 為英文字元數，N 為非英文字元數。

> [!NOTE]
>
> 4.0 文生／圖生介面沒有 audio、multi\_shot 開關。省略 settings.audio 和 settings.multi\_shot，不要傳舊版 audio=off 設定。

## 文字生成影片

| 欄位 | 說明 |
| - | - |
| `prompt` | 必填的頂層 prompt。文字生成影片介面不接收媒體輸入。 |
| `settings.aspect_ratio` | 21:9、16:9、9:16、1:1，廠商預設 16:9；文字生成影片介面不要傳 adaptive。 |

設定 MIXROUTE\_API\_KEY，並將 example.com 圖片網址替換為可存取的素材。僅提交一次；逾時不代表任務未建立。

```bash theme={null}
curl --request POST "https://api.mixroute.ai/kling/text-to-video/kling-4.0" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "prompt": "A red ceramic mug slowly rotates on a white tabletop. Static camera, soft studio lighting.",
  "settings": {
    "resolution": "720p",
    "duration": 3,
    "aspect_ratio": "16:9"
  }
}'
```

## 圖片生成影片

使用 prompt 項目和 first\_frame、middle\_frame、last\_frame 圖片項目。圖片使用 url；可選的唯一 id 可在提示詞中以 @id 引用。圖片與提示詞引用依時間順序排列；此協定不要求額外 timestamp 欄位。

最多 10 張圖片；JPG/JPEG/PNG，每張不超過 30 MB，寬高均至少 300 px，長寬比 2:5 至 5:2。使用公開 URL 或 Base64。圖生介面沒有 settings.aspect\_ratio；影片、Element 和音色參考使用 Omni。

```bash theme={null}
curl --request POST "https://api.mixroute.ai/kling/image-to-video/kling-4.0" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "contents": [
    {
      "type": "prompt",
      "text": "The scene moves smoothly from @start through @middle to @end."
    },
    {
      "type": "first_frame",
      "id": "start",
      "url": "https://example.com/first-frame.png"
    },
    {
      "type": "middle_frame",
      "id": "middle",
      "url": "https://example.com/middle-frame.png"
    },
    {
      "type": "last_frame",
      "id": "end",
      "url": "https://example.com/last-frame.png"
    }
  ],
  "settings": {
    "resolution": "720p",
    "duration": 5
  }
}'
```

## Omni 參考與編輯

必須包含 prompt 項目。支援 first\_frame、middle\_frame、last\_frame、refer\_image、feature\_video、base\_video、element、voice。圖片／影片使用 url，Element 使用 element\_id，音色使用 voice\_id。設定唯一 id 並以 @id 引用；素材 ID 須能由路由所使用的上游帳戶存取。

element 和 voice 項除了 element\_id 或 voice\_id，還必須填寫 id。

Omni 中有多個 middle\_frame 或 refer\_image 時，圖片 id 必填。first\_frame、last\_frame、refer\_image 混用時，首影格應是第一張圖片，尾影格是最後一張。

| 欄位 | 說明 |
| - | - |
| `settings.aspect_ratio` | 21:9、16:9、9:16、1:1 或 adaptive（廠商預設）。明確指定的畫幅優先；adaptive 依提示詞、base\_video、關鍵影格、feature\_video 的順序取值，多參考影片或無適用來源時回退至 16:9。 |
| `settings.audio` | native（廠商預設）或 original。original 要求 base\_video 或 feature\_video，且不能帶 voice 參考；優先保留 base\_video 音訊，否則取第一個 feature\_video。off 和 multi\_shot 不是 4.0 參數。 |

### 媒體限制

圖片、影片、Element、音色合計最多 15 項。圖片最多 10 張；參考影片最多 5 個，影片角色 Element 同時占用此上限。Element 最多 7 個，其中影片角色最多 3 個；音色最多 3 個；base\_video 最多 1 個。

JPG/JPEG/PNG，每張不超過 30 MB，寬高均至少 300 px，寬高比 2:5 至 5:2。使用公開 URL 或 Base64。

MP4/MOV，每個不超過 300 MB；單個影片和影片總時長均為 3-30 秒，總時長包含影片角色 Element。寬高 700-4553 px，總像素不超過 8,294,400，長寬比 2:5 至 5:2；輸入 24-60 fps，輸出 24 fps。

```bash theme={null}
curl --request POST "https://api.mixroute.ai/kling/omni-video/kling-4.0" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "contents": [
    {
      "type": "prompt",
      "text": "A slow camera move around the ceramic mug in @mug on a white tabletop."
    },
    {
      "type": "refer_image",
      "id": "mug",
      "url": "https://example.com/mug.png"
    }
  ],
  "settings": {
    "resolution": "720p",
    "duration": 5,
    "aspect_ratio": "adaptive",
    "audio": "native"
  }
}'
```

## 任務結果

檢查 HTTP 狀態及 code=0，保存提交回應的 data.id，使用此 MixRoute 任務 ID 單獨查詢。succeeded 後從 data\[0].outputs 的 type=video 項目讀取 URL；不要將 API Key 傳給結果 CDN。

```bash theme={null}
curl --get "https://api.mixroute.ai/kling/tasks" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --data-urlencode "task_ids=$KLING_TASK_ID"
```

[任務結果](https://mixroute.ai/docs/zh-Hant/api-reference/endpoint/kling-tasks.md)

Kling 4.0 上游計費區分 input\_duration 與 output\_duration，輸入時長包含參考影片和影片角色 Element。閘道 usage 可能缺少或為空，不能只用 outputs\[].duration 推算 MixRoute 最終費用，也不要套用舊型號費率；以模型廣場與帳單為準。


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