AI 视频生成,支持文生视频、图生视频、音频生成和音色定制。
在所有请求中添加 Bearer Token 认证头:
Authorization: Bearer YOUR_API_KEY
| 模型 | API 名称 | 特性 | 价格 (8.5折) |
|---|---|---|---|
| Kling V2.6 | kling-v2-6 | 5s/10s, 文生/图生视频, 音频+音色 | $0.0159起 |
| Kling V3 | kling-v3 | 3-15s, 文生/图生视频, 音频, 按秒计费 | $0.0064/秒起 |
| Kling Motion Control | kling-motion-control | 动作控制, 720p/1080p, 最长30秒 | $0.06/s 起 |
| 模式 | 时长 | 音频 | 音色 | $ |
|---|---|---|---|---|
| std | 5s | - | - | $0.0159 |
| std | 10s | - | - | $0.0320 |
| pro | 5s | - | - | $0.0267 |
| pro | 10s | - | - | $0.0531 |
| pro | 5s | on | - | $0.0531 |
| pro | 10s | on | - | $0.1064 |
| pro | 5s | on | on | $0.0639 |
| pro | 10s | on | on | $0.1275 |
| 模式 | 时长 | 音频 | $/秒 |
|---|---|---|---|
| std | 3-15s | - | $0.0633 |
| std | 3-15s | on | $0.0956 |
| pro | 3-15s | - | $0.0853 |
| pro | 3-15s | on | $0.1280 |
| 分辨率 | 时长 | $ |
|---|---|---|
| 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.12/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" 模型时,需提供 image(角色参考图)和 motion_video(动作源视频),生成角色执行指定动作的视频。支持最长 30 秒,720p/1080p 分辨率。
curl -X POST https://apimodels.app/api/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 后,任务进入 completed 或 failed 终态时,我们会向该地址发起一次 HTTP POST。请求头仅包含 Content-Type: application/json,无签名头。失败会自动重试 3 次(指数退避 1s/2s/4s,单次超时 10s);如果仍未成功,后台会在 30 分钟内继续补偿重发,直到接收端返回 2xx。
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 | "string",
"failMsg": null | "string",
"costTime": 12345, // duration in ms
"completeTime": 1705123500000, // ms epoch
"createTime": 1705123450000 // ms epoch
}
}注意:data.param 与 data.resultJson 都是 JSON 字符串,使用前必须 JSON.parse 一次。
{
"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":[]}。
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
})pending任务已排队,等待处理processing视频生成中completed视频生成成功failed视频生成失败400请求错误 - 参数缺失或无效401未授权 - API 密钥无效402余额不足 - 积分不够404未找到 - 任务 ID 不存在500服务器内部错误