Kling 4.0 API
Kling 4.0 视频生成、编辑、延长与计费说明
生成、编辑和延长 3–30 秒视频,720p/1080p,始终包含立体声。
提供方
Kling AI模型 ID
kling-v4请求端点
POST /api-platform/v1/generations鉴权与请求地址
API 地址为 https://aihub-admin.aimix.pro。创建和查询任务均须传入 Authorization: Bearer <PIXMIND_API_KEY>;提交 JSON 时还须设置 Content-Type: application/json。请将密钥保存在服务端环境变量中。
模型说明
- 支持文生、图生、多模态参考、编辑与延长五种模式;使用返回的 PixMind taskId 通过 GET /api-platform/v1/tasks/{taskId} 查询。
- 编辑或参考视频:按输出秒数 + max(输出秒数, 输入秒数) 计费。输入时长检测后合计向上取整、最高按 30 秒;编辑省略 duration 时跟随输入。延长仅计新增片段;失败全额退款。
- 图生需恰好一张首帧,最多一张尾帧和八张中间帧,合计不超过十张。参考模式最多十张图片、五段视频(总计 30 秒)、三段音频(每段 5–30 秒),合计最多十五个素材,均使用公开 HTTP(S) URL。
- 不支持 mode=std/pro/4k、negative_prompt、watermark=true、audio=false;延长不支持 aspect_ratio 和 audio_setting。API 按所提供官方美元原价收费,钱包积分按整次请求向上取整。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 稳定的 PixMind 模型 ID,请使用 `kling-v4`。 可选值: |
prompt | string | 否 | 图生视频可省略,其余模式必填。 |
resolution | string | 否 | 输出视频分辨率。 可选值: 默认值: |
duration | integer | 否 | 期望生成的视频时长,单位为秒。 可选值: 默认值: |
aspectRatio | string | 否 | 期望输出画面比例。 可选值: 默认值: |
imageUrl | string (URI) | 否 | 图生视频使用的起始图片。 |
first_frame_image | string | 否 | 首帧 URL,不要与其他图片输入形式混用。 |
last_frame_image | string | 否 | 尾帧或视频延长的目标尾帧 URL。 |
omni_reference_task_type | string | 否 | auto(默认)、reference、edit 或 extend;站内 mode 同样支持后三种模式。 |
image_urls | string[] | 否 | 首尾帧图片;显式 reference/edit 模式时为参考图片。 |
image_with_roles | object[] | 否 | 每项含 url、role:first_frame、last_frame、keyframe、middle_frame、reference_image。不要同时混用多种图片输入形式。 |
video_urls | string[] | 否 | 参考视频;edit/extend 需恰好一个输入视频,也接受 video_url。 |
audio_urls | string[] | 否 | 最多三段参考音频,每段 5–30 秒。 |
audio_setting | string | 否 | origin 或 auto,仅供编辑或带参考视频的参考模式使用。 |
请求示例
curl --request POST 'https://aihub-admin.aimix.pro/api-platform/v1/generations' \
-H "Authorization: Bearer $PIXMIND_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kling-v4",
"prompt": "A paper boat drifts through rainwater; stereo rainfall and soft footsteps",
"duration": 5,
"resolution": "720p",
"aspect_ratio": "9:16"
}'// Node.js 20+. Keep the API key on your server.
const apiKey = process.env.PIXMIND_API_KEY;
if (!apiKey) throw new Error("PIXMIND_API_KEY is required");
const response = await fetch("https://aihub-admin.aimix.pro/api-platform/v1/generations", {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"model": "kling-v4",
"prompt": "A paper boat drifts through rainwater; stereo rainfall and soft footsteps",
"duration": 5,
"resolution": "720p",
"aspect_ratio": "9:16"
}),
signal: AbortSignal.timeout(30_000)
});
const task = await response.json();
if (!response.ok || task.code !== 1000) {
throw new Error(task.message ?? task.error?.message ?? `HTTP ${response.status}`);
}
console.log(task);任务受理响应
生成任务为异步处理。请保存 taskId,并轮询 GET /api-platform/v1/tasks/{taskId},直到状态为 ready 或 failed。
{
"code": 1000,
"data": {
"id": "vid_44160",
"taskId": 44160,
"type": "video",
"model": "kling-v4",
"status": "processing"
}
}查询任务与获取结果
将示例中的 44160 替换为受理响应中的 data.taskId,并使用同一用户所属的 Key 查询。pending、processing 为进行中状态;ready、failed 为终态。ready 时读取图片的 images 或视频的 videoUrl,failed 时读取 errorMessage。示例最多查询 60 次;超时后请保留 taskId 稍后继续查询,避免重复创建任务。结果 URL 仅为示意。
curl 'https://aihub-admin.aimix.pro/api-platform/v1/tasks/44160' \
-H "Authorization: Bearer $PIXMIND_API_KEY"// Continue after the request example above.
const taskId = task.data?.taskId;
if (!Number.isInteger(taskId)) throw new Error("Missing numeric taskId");
async function waitForTask(taskId) {
for (let attempt = 0; attempt < 60; attempt++) {
await new Promise(resolve => setTimeout(resolve, Math.min(2000 * 1.5 ** attempt, 10000)));
const response = await fetch(`https://aihub-admin.aimix.pro/api-platform/v1/tasks/${taskId}`, {
headers: { Authorization: `Bearer ${apiKey}` },
signal: AbortSignal.timeout(30_000)
});
const result = await response.json();
if (!response.ok || result.code !== 1000) {
throw new Error(result.message ?? `HTTP ${response.status}`);
}
const data = result.data;
if (data.status === "ready") return data;
if (data.status === "failed") {
throw new Error(data.errorMessage ?? "Generation failed");
}
if (!["pending", "processing"].includes(data.status)) {
throw new Error(`Unexpected task status: ${data.status}`);
}
}
throw new Error(`Polling timed out; save taskId ${taskId} to query again later`);
}
const result = await waitForTask(taskId);
console.log(result.videoUrl);{
"code": 1000,
"data": {
"taskId": 44160,
"type": "video",
"model": "kling-v4",
"status": "ready",
"progress": 100,
"videoUrl": "https://example.com/result.mp4"
}
}