APIMODELSAPIMODELS
API 文档

apimodels.app

Docs/Kling (可灵) 视频生成 API
KV

Kling (可灵) 视频生成 API

AI 视频生成,支持文生视频、图生视频、音频生成和音色定制。

快速开始

1
从控制台获取 API 密钥
2
选择 Kling 视频模型 (kling-v2-6 或 kling-v3)
3
发送 POST 请求创建任务
4
轮询 GET 请求获取视频结果

认证方式

在所有请求中添加 Bearer Token 认证头:

Authorization: Bearer YOUR_API_KEY

可用模型

模型API 名称特性价格
Kling V2.6kling-v2-65s/10s, 文生/图生视频, 音频+音色$0.22 起
Kling V3kling-v33-15s, 文生/图生视频, 音频, 按秒计费$0.12/秒起
Kling Motion Controlkling-motion-control动作控制, 720p/1080p, 最长30秒$0.06/s 起

多模态的 Omni 模型 Kling Video-O1 与 Kling V3 Omni(文本 / 图片 / 视频 / 主体输入,可做视频编辑),见 Kling Omni-Video 文档。

详细定价

Kling V2.6(可灵官方价)

模式时长音频音色$
std5s--$0.22
std10s--$0.44
pro5s--$0.36
pro10s--$0.73
pro5son-$0.73
pro10son-$1.47
pro5sonon$0.88
pro10sonon$1.76

Kling V3

模式时长音频$/秒
std3-15s-$0.12/s
std3-15son$0.18/s
pro3-15s-$0.16/s
pro3-15son$0.24/s

Kling Motion Control (7折)

分辨率时长$
Kling 2.6 · 720pUp to 30s$0.06/s
Kling 2.6 · 1080pUp to 30s$0.10/s
Kling 3.0 · 720pUp to 30s$0.10/s
Kling 3.0 · 1080pUp to 30s$0.15/s

接口端点

POST/api/v1/video/generations

创建可灵视频生成任务。根据是否提供 image 参数自动选择文生视频或图生视频。

GET/api/v1/video/generations?task_id=xxx

查询任务状态并获取视频链接

请求参数

基本参数

model必填string
"kling-v2-6"、"kling-v3" 或 "kling-motion-control"
promptstring
正向文本提示词(不超过2500字符)。文生视频时必填。
imagestring
参考图像(base64 或 URL)。提供此参数则使用图生视频模式。
modestring
"std"(标准)或 "pro"(高品质)。默认:"std"
durationstring
V2.6:"5" 或 "10"。V3:"3" 到 "15"。默认:"5"
soundstring
"on" 或 "off"。是否生成音频。默认:"off"
negative_promptstring
负向文本提示词(不超过2500字符)
aspect_ratiostring
视频画面纵横比(宽:高)
cfg_scalenumber
自由度。值越大与提示词相关性越强。
callback_urlstring
完成后的回调 URL

高级参数

image_tailstring
尾帧参考图像(仅图生视频)
voice_listarray
音色 ID 列表(仅 V2.6+,最多2个)
camera_controlobject
摄像机运动控制(type + config)
multi_shotboolean
是否生成多镜头视频
watermark_infoobject
{ enabled: true/false } - 是否生成含水印版本
motion_videostring
动作参考视频 URL(仅 kling-motion-control)。提供动作源视频以驱动角色动画。

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。