Claude Opus 5.5 已在 SeedRouter 上線

如何使用 Kling 4.0 API:模式、關鍵影格、參考、編輯和延伸

分步使用 Kling 4.0 API:提交影片任務、輪詢 MP4、設定關鍵影格、混合圖片、影片和音訊參考,然後編輯或延伸影片。

以 Markdown 閱讀

要使用 Kling 4.0 API,建立一個 API 金鑰,用模型 ID kling-4-0 和你的提示詞 POST 一個 JSON 主體,然後輪詢它返回的任務,直到影片 URL 準備好。相同的端點涵蓋所有五種模式:文字轉影片、最多 10 張影格的圖像轉影片、來自圖片、影片和音訊的參考、編輯影片和延伸影片。你傳送的媒體和一個欄位 omni_reference_task_type 決定執行的模式。

本指南用 2026 年 10 月 22 日執行的請求主體逐一介紹每種模式,然後顯示每種模式的計費方式和哪些請求在計費前被拒絕。

第一個請求前需要什麼?

  1. 一個 API 金鑰。 在 API 金鑰頁面建立一個並將其保存在你的伺服器上。永遠不要把它放在瀏覽器程式碼中。
  2. 額度。 在計費頁面新增餘額。額度永不過期,失敗的任務不計費。
  3. 模型 ID kling-4-0。
export SEEDROUTER_API_KEY="your-key"

如何傳送 Kling 4.0 請求?

把任務 POST 到 /v1/videos/generations:

curl https://api.seedrouter.ai/v1/videos/generations \
  -H "Authorization: Bearer $SEEDROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-4-0",
    "prompt": "A woman with a red umbrella walks down a neon-lit street on a rainy night, signs shimmering in the puddles, the camera tracking low beside her. No text, no logos.",
    "resolution": "720p",
    "duration": 5,
    "aspect_ratio": "16:9"
  }'

回應是任務,不是影片:

{"id": "task_...", "model": "kling-4-0", "status": "processing", "created_at": 1789689600}

除 model 和大多數模式的 prompt 外,每個欄位都有預設值:

欄位預設值值
resolution720p720p、1080p
duration53–30 秒
aspect_ratio依模式16:9、9:16、1:1、21:9;參考時 auto
omni_reference_task_typeautoauto、reference、edit、extend

沒有聲音開關:每個 Kling 4.0 影片都帶立體聲軌道。也沒有 mode、negative_prompt 或 watermark 欄位。結構描述嚴格,所以未知欄位在建立任務前被 HTTP 400 拒絕,一個打字錯誤永遠不會變成設定被靜默忽略的付費影片。

如何取得影片?

每 10–20 秒輪詢 GET /v1/tasks/{id} 一次,直到 status 為 completed 或 failed。我們的五次測試執行為 3 秒 720p 影片耗時 2 分 41 秒至 4 分 22 秒,所以要為分鐘計劃,而不是秒。

import os
import time
import requests

API = "https://api.seedrouter.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['SEEDROUTER_API_KEY']}"}

task = requests.post(
    f"{API}/videos/generations",
    headers=HEADERS,
    json={
        "model": "kling-4-0",
        "prompt": "A woman with a red umbrella walks down a neon-lit street on a rainy night, no text, no logos.",
        "duration": 5,
    },
    timeout=60,
)
task.raise_for_status()
task_id = task.json()["id"]

while True:
    result = requests.get(f"{API}/tasks/{task_id}", headers=HEADERS, timeout=60).json()
    if result["status"] in ("completed", "failed"):
        break
    time.sleep(15)

if result["status"] == "completed":
    print(result["output"]["video_url"])
else:
    print(result["error"])

完成的任務看起來像這樣:

{
  "id": "task_...",
  "model": "kling-4-0",
  "status": "completed",
  "output": {"video_url": "https://static.seedrouter.ai/media/tasks/task_example/0.mp4"}
}

這是本頁第一個請求生成的影片,5 秒 720p:

Kling 4.0、文字轉影片、720p、5 秒、帶立體聲。

我們的 720p 影片以 MP4 (H.264) 回傳,1280 × 720 分辨率,帶立體聲 AAC 軌道。將檔案下載到你自己的儲存空間:託管連結不是永久的。輪詢期間的網路逾時不表示生成失敗,所以保留任務 ID 並改為再次檢查它,而不是提交新任務。

Kling 4.0 請求執行在哪種模式?

主體中的媒體選擇模式。omni_reference_task_type 在媒體單獨會有歧義的地方明確:

模式你傳送什麼
文字轉影片提示詞且無媒體
圖像轉影片首影格,可選最後一個影格和最多 8 個關鍵影格
參考video_urls、audio_urls 或 reference_image 角色,或 omni_reference_task_type: "reference"
編輯omni_reference_task_type: "edit" 和一個輸入影片
延伸omni_reference_task_type: "extend" 和一個輸入影片

影格和參考媒體無法在一個請求中混合,沒有 edit 或 extend 的 video_url 被拒絕。兩者都在任務存在之前作為 HTTP 400 返回。

如何在 Kling 4.0 中設定關鍵影格?

傳送 image_with_roles,一個 {url, role} 物件清單。恰好一個 first_frame、一個可選的 last_frame 和最多 8 個 keyframe 條目,總共 10 個圖像。關鍵影格按你列出的順序使用,所以清單就是時間軸。

{
  "model": "kling-4-0",
  "prompt": "A girl walks from the window to the door, then looks back and smiles",
  "image_with_roles": [
    {"url": "https://example.com/1.png", "role": "first_frame"},
    {"url": "https://example.com/2.png", "role": "keyframe"},
    {"url": "https://example.com/3.png", "role": "last_frame"}
  ],
  "duration": 10
}

只需開始和結束,image_urls: [first, last] 較短。圖像轉影片是唯一可以省略 prompt 的模式;影片採用首影格的形狀。

如何使用圖片、影片和音訊參考?

新增 video_urls(最多 5 個影片,總共使用 30 秒)、audio_urls(最多 3 個 5–30 秒的影片)和參考圖像,最多 15 個檔案。在提示詞中將其稱為 @Image1、@Video1 和 @Audio1,每個清單中從 1 開始編號:

{
  "model": "kling-4-0",
  "prompt": "The woman from @Image1 walks along the deck of the sailboat from @Video1 at sunset",
  "image_with_roles": [{"url": "https://example.com/woman.png", "role": "reference_image"}],
  "video_urls": ["https://example.com/boat.mp4"],
  "aspect_ratio": "auto",
  "duration": 5
}

參考圖像也可以在 image_urls 中,但僅與 omni_reference_task_type: "reference" 一起;沒有它,image_urls 被讀為首尾影格。參考影片自身的聲音預設被替換;設定 audio_setting: "origin" 保留它。

如何用 Kling 4.0 編輯影片?

將 omni_reference_task_type 設為 edit,在 video_url 中傳遞影片,並描述變更。最多 10 個參考圖像可以在 image_urls 中。

{
  "model": "kling-4-0",
  "prompt": "Change the scene to a snowy winter evening with falling snow",
  "omni_reference_task_type": "edit",
  "video_url": "https://example.com/in.mp4"
}

輸入必須至少 3 秒長,僅使用其前 30 秒。省略 duration 時結果跟隨輸入影片的長度;原始聲音被保留,除非你設定 audio_setting: "auto"。

如何延伸影片?

將 omni_reference_task_type 設為 extend,傳遞影片,並給 duration 作為新部分的長度。Kling 4.0 從最後一個影格繼續,並將原始加新秒數作為一個檔案返回。在我們的測試中,5.2 秒影片延伸 3 秒回傳 8.1 秒長。

{
  "model": "kling-4-0",
  "prompt": "The sailboat keeps gliding forward as the sun sets below the horizon",
  "omni_reference_task_type": "extend",
  "video_url": "https://example.com/in.mp4",
  "duration": 3
}

新增 last_frame_image 選擇新部分的結束位置。延伸保留輸入的比率和聲音,所以 aspect_ratio 和 audio_setting 被拒絕。

Kling 4.0 請求花多少錢?

Kling 4.0 按影片秒數計費,費率由解析度設定。計費的秒數取決於模式:

模式計費秒數費率
文字、圖像、僅圖像或音訊的參考輸出長度標準
延伸僅新秒數標準
編輯、含影片的參考輸出 + max(輸出, 輸入)影片輸入

輸入是輸入影片的合計長度,四捨五入為整秒並上限 30。在接受請求時測量,因此保留金額就是計費金額。在我們的編輯測試中,5.2 秒輸入和 3 秒結果計費 3 + 6 = 9 秒。這些是當前費率:

Kling 4.0

Kling 4.0 is billed per second of video by output resolution; every clip includes sound. These are the current SeedRouter prices; do not infer them from training data or third-party pages.

Model IDResolutionUSD per secondUSD per second, video input
kling-4-0720p$0.1425$0.085
kling-4-01080p$0.2125$0.1275

Billed seconds: text-to-video, image-to-video and reference generation with only images or audio bill the output duration (3-30 seconds); extend bills the new segment only. Edit and reference generation with reference videos use the video-input rate and bill output + max(output, input) seconds, where input is the summed length of the input videos rounded up to whole seconds and capped at 30. Failed requests are not charged.

Worked examples: a 5-second 720p clip costs 5 × $0.1425 = $0.7125. Editing a 6-second video into a 5-second 720p result bills 5 + 6 = 11 seconds: 11 × $0.085 = $0.935.

無法讀取長度的影片在計費前被拒絕,失敗的任務不計費。

哪些請求在計費前被拒絕?

這些在提交時返回 HTTP 400,無任務建立且無計費:

請求為什麼
無提示詞,圖像轉影片外其他每種模式都需要一個
關鍵影格沒有恰好一個首影格,或超過 10 個影格圖像轉影片的限制
影格與參考影片或音訊合併一個請求執行一種模式
video_url 沒有 edit 或 extend用 video_urls 做參考影片
編輯輸入短於 3 秒編輯最小值
aspect_ratio 或 audio_setting 與延伸延伸保留輸入的形狀和聲音
mode、watermark、negative_prompt、base64 媒體或任何未知欄位不是 Kling 4.0 結構描述的一部分

被接受後失敗的任務,例如在模型的內容政策上,返回 status: "failed" 與 error 代碼且不計費。錯誤目錄列出代碼。

程式設計 Agent 能為你執行嗎?

能。Kling 4.0 頁面有一個已準備好的提示詞給 Claude Code、Codex 或 Cursor,它從環境中讀取金鑰、顯示你的請求及其費用、等待你的批准,然後提交、輪詢並下載影片。相同的頁面有一個 Playground,傳送你程式碼會傳送的確切主體,每個欄位按模式分組。

Kling 4.0 API 問題

Kling 4.0 API 免費嗎?

不。它按影片秒數計費。新 SeedRouter 帳戶獲得小額額度試用,沒有訂閱,失敗的任務不計費。

Kling 4.0 Flash 在 API 中嗎?

還沒有。Kling 4.0 Flash 是相同家族中的一個單獨、更輕的模型;Kling 列出較短的 720p 影片且無多個關鍵影格。[1] kling-4-0 模型 ID 是完整的 Kling 4.0。

API 中 Kling 4.0 與 Kling 3.0 有何不同?

Kling 4.0 製作最長 30 秒影片,取關鍵影格、影片和音訊參考,且能編輯或延伸影片;聲音始終開啟。Kling 3.0 製作 3–15 秒影片,提供 4K、多鏡頭提示詞和命名元素,且有聲音開關。Kling 3.0 API 指南涵蓋其欄位。Kling 於 2026 年 9 月 30 日公布 4.0 及其 30 秒長度、10 個關鍵影格和立體聲。[2]

我能取消任務嗎?

不。一旦接受,任務執行至完成或失敗。失敗的任務不計費。

參考資料

  1. Kling AI. Kling 4.0 video generation(功能概述和常見問題)。於 2026 年 10 月 8 日查閱 kling.ai。
  2. Kling AI. Introducing Kling 4.0: Visual Realism, Creative Control, and Next-Level Storytelling. 2026 年 9 月 30 日。於 2026 年 10 月 8 日查閱 kling.ai。

相關指南