Kling 4 API 现在能用吗?
本站尚未接入可调用的 Kling 4.0 API
本站在线生成器当前使用 Kling 3.0 与 Kling 3.0 Turbo。Kling 4.0 的官方演示和已公布能力不能作为本站接口已开放的证据。接入后,我们会按实际模型更新这里的参数、费用和示例。
| 使用方式 | 密钥与费用 | 当前用途 |
|---|---|---|
| Kling 官方平台 | 官方账户与密钥 | 查看官方版本、开放权限和 API 文档 |
| KIE API | 自有 KIE 密钥及供应商余额 | 下方示例直接调用 Kling 3.0 |
| kling4.io | 本站账户与积分 | 在线生成;尚无经过验证的 Kling 公共开发者接口 |
快速开始:当前 Kling 3.0 API
以下示例直接请求 KIE,需要你自己的 KIE API Key,费用从供应商余额扣除。它们不请求 kling4.io,也不使用本站积分。仅在服务器端保存密钥。
- 1.准备 KIE 密钥与余额
- 2.提交一次,保存 taskId
- 3.每约 5 秒查询,成功后下载
# KIE provider API: use your own KIE key, not a kling4.io key.
# Submitting a generation consumes provider credits.
curl --fail-with-body https://api.kie.ai/api/v1/jobs/createTask \
-H "Authorization: Bearer $KIE_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "kling-3.0/video",
"input": {
"prompt": "One continuous shot of a ceramic cup on a wooden table. Soft morning light from the left. A slow camera push-in as a thin ribbon of steam rises. Quiet room tone, no speech or text.",
"mode": "std",
"duration": "5",
"sound": true,
"multi_shots": false,
"aspect_ratio": "16:9"
}
}'
# Copy data.taskId from the response; poll about every 5 seconds.
curl --fail-with-body \
'https://api.kie.ai/api/v1/jobs/recordInfo?taskId=YOUR_TASK_ID' \
-H "Authorization: Bearer $KIE_API_KEY"
# When data.state is success, parse data.resultJson (a JSON string).
# Download the URL in resultUrls[0] before the provider link expires.
curl --fail --location 'VIDEO_URL_FROM_RESULT' --output kling-video.mp4// Node.js 18+. Set KIE_API_KEY in your server environment.
// This calls KIE directly and consumes KIE credits.
const apiKey = process.env.KIE_API_KEY;
if (!apiKey) throw new Error("Set KIE_API_KEY first");
const base = "https://api.kie.ai/api/v1/jobs";
const headers = {
Authorization: "Bearer " + apiKey,
"Content-Type": "application/json",
};
async function request(url, options = {}) {
const response = await fetch(url, {
...options, headers, signal: AbortSignal.timeout(30000),
});
const json = await response.json();
if (!response.ok || json.code !== 200) {
throw new Error(json.msg || "Provider request failed");
}
return json.data;
}
// Submit once. An unknown POST outcome may already have created a paid job.
const created = await request(base + "/createTask", {
method: "POST", body: JSON.stringify({
"model": "kling-3.0/video",
"input": {
"prompt": "One continuous shot of a ceramic cup on a wooden table. Soft morning light from the left. A slow camera push-in as a thin ribbon of steam rises. Quiet room tone, no speech or text.",
"mode": "std",
"duration": "5",
"sound": true,
"multi_shots": false,
"aspect_ratio": "16:9"
}
}),
});
if (!created.taskId) throw new Error("Missing taskId");
console.log("Save this task ID:", created.taskId);
let videoUrl;
for (let attempt = 0; attempt < 180; attempt++) {
await new Promise(resolve => setTimeout(resolve, 5000));
const task = await request(base + "/recordInfo?taskId=" +
encodeURIComponent(created.taskId));
if (task.state === "fail") throw new Error(task.failMsg || "Generation failed");
if (task.state === "success") {
videoUrl = JSON.parse(task.resultJson || "{}").resultUrls?.[0];
if (!videoUrl) throw new Error("Missing result URL");
break;
}
}
if (!videoUrl) throw new Error("Still processing. Resume polling the saved task ID.");
console.log(videoUrl);# Python 3.9+. Uses only the standard library.
# Calls KIE directly and consumes provider credits.
import json, os, time, urllib.request
key = os.environ["KIE_API_KEY"]
base = "https://api.kie.ai/api/v1/jobs"
def request(path, body=None):
data = json.dumps(body).encode() if body is not None else None
req = urllib.request.Request(base + path, data=data, headers={
"Authorization": "Bearer " + key,
"Content-Type": "application/json",
})
with urllib.request.urlopen(req, timeout=30) as response:
result = json.load(response)
if result.get("code") != 200:
raise RuntimeError(result.get("msg", "Provider request failed"))
return result["data"]
# Submit once; do not blindly retry a timed-out creation request.
payload = json.loads(r'''{
"model": "kling-3.0/video",
"input": {
"prompt": "One continuous shot of a ceramic cup on a wooden table. Soft morning light from the left. A slow camera push-in as a thin ribbon of steam rises. Quiet room tone, no speech or text.",
"mode": "std",
"duration": "5",
"sound": true,
"multi_shots": false,
"aspect_ratio": "16:9"
}
}''')
created = request("/createTask", payload)
task_id = created["taskId"]
print("Save this task ID:", task_id)
for attempt in range(180):
time.sleep(5)
task = request("/recordInfo?taskId=" + task_id)
if task["state"] == "fail":
raise RuntimeError(task.get("failMsg") or "Generation failed")
if task["state"] == "success":
urls = json.loads(task.get("resultJson") or "{}").get("resultUrls", [])
if not urls:
raise RuntimeError("Missing result URL")
print(urls[0])
break
else:
raise TimeoutError("Resume polling the saved task ID; do not resubmit")文档依据:KIE Kling 3.0 · 任务查询
模型和请求参数
这张表对应上方 Kling 3.0 示例。不要将模型 ID 换成猜测的 kling-4 字符串;新版接口需要重新核对完整请求结构。
| 参数 | 值 / 类型 | 说明 |
|---|---|---|
| model | kling-3.0/video | 当前示例使用 Kling 3.0,不代表 Kling 4.0。 |
| input.prompt | string | 描述主体、动作、镜头和声音;此集成限制为 2,500 字符。 |
| input.duration | "3" … "15" | 以字符串传入秒数,例如 "5"。 |
| input.mode | std / pro | std 对应 720p,pro 对应 1080p。 |
| input.aspect_ratio | 16:9 / 9:16 / 1:1 | 文生视频使用;图生视频由输入图片决定画幅,省略此字段。 |
| input.image_urls | HTTPS URL[] | 图生视频传首帧,可选第二张尾帧;示例未附加图片。 |
| input.sound | true / false | Kling 3.0 的音频开关;Turbo 始终有声,不使用这个字段。 |
| input.multi_shots | false | 此示例关闭多镜头模式;本站生成器同样使用此设置。 |
Turbo 文生视频使用 kling/v3-turbo-text-to-video,图生视频使用 kling/v3-turbo-image-to-video。Turbo 使用 resolution,始终带音频;图生视频只接受首帧。 查看 Turbo 文档
任务状态与结果
创建成功后读取 data.taskId。查询接口的 HTTP 成功不等于视频已经完成,需要检查 data.state。
- waiting / queuing / generating
- 尚未完成,保存任务 ID 并继续查询。
- success
- 解析 data.resultJson 这个 JSON 字符串,读取 resultUrls,再及时下载。
- fail
- 读取 failMsg,按供应商失败和计费规则处理。
价格、时长和使用限制
本站积分套餐只适用于本站在线生成。直接调用供应商时,按供应商当时的模型、画质、音频和时长计费。本站尚无经过核验的 Kling 4.0 API 价格。
- 当前集成支持 3–15 秒、720p / 1080p;不要把官方公布的 4.0 上限套入此接口。
- 先确认模型能力,再设计重试、并发和成本上限。
- 供应商生成失败的收费与退款规则以其文档为准。
API 常见问题与排错
鉴权失败
检查是否使用供应商自己的密钥。Kling 官方密钥、KIE 密钥和本站账户凭据不能互换。
参数被拒绝
检查模型 ID、duration 的字符串类型和 std/pro。图生视频不要附加 aspect_ratio。
请求超时
创建请求可能已经成功,先检查供应商任务记录。查询超时可继续查询同一任务 ID。
生成失败
读取 failMsg,检查素材可访问性和内容限制。供应商扣费或退款按供应商规则处理。
一直处于处理中
保存 taskId,稍后继续轮询,不因等待较久而再次提交付费任务。
从一个清晰的提示词开始
先在在线生成器调整画面和节奏,再把确认过的创作流程接入应用。