Kling (可灵) 视频生成 API
AI 视频生成,支持文生视频、图生视频、音频生成和音色定制。
快速开始
认证方式
在所有请求中添加 Bearer Token 认证头:
Authorization: Bearer YOUR_API_KEY
可用模型
| 模型 | API 名称 | 特性 | 价格 |
|---|---|---|---|
| Kling V2.6 | kling-v2-6 | 5s/10s, 文生/图生视频, 音频+音色 | $0.22 起 |
| Kling V3 | kling-v3 | 3-15s, 文生/图生视频, 音频, 按秒计费 | $0.12/秒起 |
| Kling Motion Control | kling-motion-control | 动作控制, 720p/1080p, 最长30秒 | $0.06/s 起 |
多模态的 Omni 模型 Kling Video-O1 与 Kling V3 Omni(文本 / 图片 / 视频 / 主体输入,可做视频编辑),见 Kling Omni-Video 文档。
详细定价
Kling V2.6(可灵官方价)
| 模式 | 时长 | 音频 | 音色 | $ |
|---|---|---|---|---|
| std | 5s | - | - | $0.22 |
| std | 10s | - | - | $0.44 |
| pro | 5s | - | - | $0.36 |
| pro | 10s | - | - | $0.73 |
| pro | 5s | on | - | $0.73 |
| pro | 10s | on | - | $1.47 |
| pro | 5s | on | on | $0.88 |
| pro | 10s | on | on | $1.76 |
Kling V3
| 模式 | 时长 | 音频 | $/秒 |
|---|---|---|---|
| std | 3-15s | - | $0.12/s |
| std | 3-15s | on | $0.18/s |
| pro | 3-15s | - | $0.16/s |
| pro | 3-15s | on | $0.24/s |
Kling Motion Control (7折)
| 分辨率 | 时长 | $ |
|---|---|---|
| Kling 2.6 · 720p | Up to 30s | $0.06/s |
| Kling 2.6 · 1080p | Up to 30s | $0.10/s |
| Kling 3.0 · 720p | Up to 30s | $0.10/s |
| Kling 3.0 · 1080p | Up to 30s | $0.15/s |
接口端点
/api/v1/video/generations创建可灵视频生成任务。根据是否提供 image 参数自动选择文生视频或图生视频。
/api/v1/video/generations?task_id=xxx查询任务状态并获取视频链接
请求参数
基本参数
高级参数
Kling Motion Control 说明
使用 "kling-motion-control" 模型时,需提供 image(角色参考图)和 motion_video(动作源视频),生成角色执行指定动作的视频。支持最长 30 秒,720p/1080p 分辨率。
代码示例
curl -X POST https://api.apimodels.app/v1/video/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kling-v2-6",
"prompt": "A girl dancing on the beach at sunset, cinematic lighting",
"mode": "std",
"duration": "5",
"aspect_ratio": "16:9"
}'响应格式
创建任务响应
{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"state": "pending",
"model": "kling-video/kling-v2-6"
}
}成功响应
{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"state": "completed",
"model": "kling-video/kling-v2-6",
"resultUrls": ["https://...video.mp4"],
"createTime": 1705123450000,
"completeTime": 1705123500000
}
}失败响应
{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"state": "failed",
"model": "kling-video/kling-v2-6",
"failMsg": "Content policy violation"
}
}回调通知 (callback_url)
在创建请求中传入 callback_url 后,任务进入 completed 或 failed 终态时,我们会向该地址发起一次 HTTP POST。请求头仅包含 Content-Type: application/json,无签名头。失败会自动重试 3 次(指数退避 1s/2s/4s,单次超时 10s);如果仍未成功,后台会在 30 分钟内继续补偿重发,直到接收端返回 2xx。
Payload 结构
POST {your callback_url}
Content-Type: application/json
{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"model": "kling-video/kling-v2-6",
"state": "completed" | "failed",
"param": "<JSON string>", // request params, JSON.parse once
"resultJson": "<JSON string> | null", // result object, JSON.parse once
"failCode": null | "CONTENT_MODERATION | INVALID_INPUT | INSUFFICIENT_BALANCE | UPSTREAM_BUSY | UPSTREAM_FAILED | TIMEOUT | INTERNAL_ERROR | OTHER",
"failMsg": null | "string",
"retryable": true | false, // present when state=failed: safe to retry/fallback
"costTime": 12345, // duration in ms
"completeTime": 1705123500000, // ms epoch
"createTime": 1705123450000 // ms epoch
}
}注意:data.param 与 data.resultJson 都是 JSON 字符串,使用前必须 JSON.parse 一次。
视频任务:JSON.parse(data.resultJson) 后的结构
{
"resultUrls": ["https://r2.apimodels.app/videos/xxx.mp4"],
"videoDuration": 5, // optional, seconds
"thumbnailUrl": "https://...jpg", // optional
"videoSize": "1280x720", // optional
"videoModel": "kling-v2-6" // optional
}resultUrls 始终存在,长度通常为 1(失败时为空数组)。其它字段可选,按上游不同会缺失,请按需读取。state=failed 时 resultJson 通常为 null 或 {"resultUrls":[]}。
Node.js 接收示例
app.post('/webhook/kling-video', express.json(), (req, res) => {
const { taskId, state, resultJson, failMsg } = req.body.data
if (state === 'completed') {
const r = JSON.parse(resultJson)
console.log('video ready', taskId, r.resultUrls[0], r.videoDuration)
} else {
console.warn('video failed', taskId, failMsg)
}
res.status(200).end() // must be 2xx, otherwise we retry
})注意事项
- -每个任务只在送达 2xx 后停止重发,已送达后不会重复推送。
- -当前不附带签名头。建议在 callback_url 路径中放置一段随机 token,由你在收到回调时自行校验来源。
- -Kling 视频任务通常耗时 30 秒到几分钟,强烈建议使用 callback_url 而不是轮询。
- -回调地址建议使用公网 HTTPS 端点,并能在 10 秒内返回响应(单次超时为 10s)。
任务状态
pending任务已排队,等待处理processing视频生成中completed视频生成成功failed视频生成失败错误码
400请求错误 - 参数缺失或无效401未授权 - API 密钥无效402余额不足 - 积分不够404未找到 - 任务 ID 不存在500服务器内部错误注意事项
- *视频文件保存 30 天,请及时下载
- *提供 image 参数时自动使用图生视频模式
- *V3 支持 3-15 秒灵活时长,按秒计费
- *V2.6(仅专业档)和 V3 支持音频生成(设置 sound: "on")
- *音色定制需要 V2.6+ 并设置 sound: "on" 和 voice_list
- *建议每 5-10 秒轮询一次状态
- *Kling Motion Control 需同时提供 image(角色参考图)和 motion_video(动作源视频)参数
常见问题
怎么用 Kling 从文字或图片生成视频?
调 POST /api/v1/video/generations,选 Kling 模型 + prompt(图生视频加 first_frame_url),再 GET ?task_id= 轮询。一把 Key 通用 Kling 及所有视频模型。
Kling 视频怎么计费?
按输出秒数、按模型和分辨率计,仅成功扣费。注册送 $0.1。