Kling 4.0 API
快手 Kling 4.0 影片生成模型的完整 API 參考文件。
模型版本
此 API 支援五種模型版本:
快速比較
支援的長寬比
文字生成影片、圖片生成影片、參考素材生成影片和影片編輯支援以下長寬比:
16:9, 9:16, 1:1, 21:9
預設為 16:9。影片延長不支援 aspect_ratio 參數;輸出沿用來源影片的長寬比。
解析度選項
全部五種模型都必須提供 resolution 和 duration。即使 resolution 的預設值為 720p,也必須明確傳入。duration 沒有預設值。
Kling 4.0 Text to Video
端點
POST /api/v1/video/task
請求參數
必填
可選
請求範例
const response = await fetch('https://api.flaq.ai/api/v1/video/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'kling-v4.0-text-to-video',
prompt: 'A drone flying over a mountain range at sunrise, smooth forward camera movement',
resolution: '720p',
duration: 5,
aspect_ratio: '16:9'
})
});
const { data } = await response.json();
const taskId = data.task_id;
Kling 4.0 Image to Video
請求參數
必填
可選
同時提供 image_url 和 image_end_url 時,key_frames 最多可包含 8 張圖片。中間幀依陣列順序使用;各幀出現的時間由模型決定。
請求範例
{
model_name: 'kling-v4.0-image-to-video',
prompt: 'Camera slowly pulls back from the character to reveal the surrounding mountain landscape',
image_url: 'https://example.com/start-frame.jpg',
image_end_url: 'https://example.com/end-frame.jpg',
key_frames: [
'https://example.com/middle-frame-1.jpg',
'https://example.com/middle-frame-2.jpg'
],
resolution: '720p',
duration: 8,
aspect_ratio: '16:9'
}
Kling 4.0 Reference to Video
請求參數
必填
可選
參考圖片、影片和音訊均為可選項。可以提供任一種媒體類型、組合多種媒體類型,或三種都不提供。
輸出的 duration 獨立設定為 3-30 秒,不計入參考影片的總時長限制。
請求範例
{
model_name: 'kling-v4.0-reference-to-video',
prompt: 'Use the character from the reference image, follow the camera movement in the reference video, and use the reference audio for voice guidance',
images: ['https://example.com/character-reference.jpg'],
videos: ['https://example.com/motion-reference.mp4'],
audios: ['https://example.com/voice-reference.mp3'],
keep_original_sound: false,
resolution: '720p',
duration: 8,
aspect_ratio: '16:9'
}
Kling 4.0 Video Edit
請求參數
必填
可選
請求範例
{
model_name: 'kling-v4.0-video-edit',
prompt: 'Replace the background with warm sunset colors while preserving the subject and camera movement',
video_url: 'https://example.com/source.mp4',
images: ['https://example.com/sunset-reference.jpg'],
keep_original_sound: true,
resolution: '720p',
duration: 8,
aspect_ratio: '16:9'
}
Kling 4.0 Video Extend
請求參數
必填
可選
請勿傳入 aspect_ratio;輸出沿用來源影片的長寬比。結果包含來源影片和延長片段組成的完整影片。其總時長為來源影片時長加上 duration。
請求範例
{
model_name: 'kling-v4.0-video-extend',
prompt: 'Continue the camera movement forward through the valley as the sun rises above the mountains',
video_url: 'https://example.com/source.mp4',
image_end_url: 'https://example.com/target-end-frame.jpg',
resolution: '720p',
duration: 5
}
計費規則
文字生成影片和圖片生成影片依輸出解析度與生成影片時長計費。影片延長依解析度和新增片段時長計費,而非依傳回的完整影片時長計費。
包含參考影片的參考素材生成影片請求,以及影片編輯請求,會依所選解析度將輸入和輸出影片時長均納入計費。輸入影片的最低計費時長為 3 秒,最高為 30 秒。有多個參考影片時,這些上下限適用於其總時長,而非分別適用於每部影片。計費時長上下限不代表上傳限制。
未提供參考影片時,參考素材生成影片採用與文字生成影片相同的計費規則,無論是否提供參考圖片或音訊。對於包含影片輸入的請求,支援的參考圖片、參考音訊和 keep_original_sound 均不另外收費。
回應格式
初始回應
所有模型都會傳回用於輪詢的 task_id:
{
"code": 0,
"message": "success",
"data": {
"task_id": "{task_id}",
"response_url": "https://api.flaq.ai/api/v1/video/{task_id}",
"task_status": "submitted"
}
}
使用 GET /api/v1/video/{task_id} 輪詢,以檢查狀態並取得生成的影片。
狀態值
submitted:任務已接受,等待處理
processing:正在生成影片
succeed:影片生成完成
failed:影片生成失敗
最佳實務
- 必填參數:務必提供
resolution 和 duration,包括使用預設的 720p 解析度時
- 幀數:首幀、尾幀和中間幀的總數應維持在 10 幀以內
- 參考媒體:參考媒體的數量和時長應符合文件規定
- 原音:僅在參考素材生成影片或影片編輯中使用
keep_original_sound
- 影片延長:將
duration 設為額外延長的時長,並省略 aspect_ratio