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