Kling 4.0 Text to Video API
kwaivgi/kling-v4.0/text-to-videoKling 4.0 Text to Video 将提示词或多镜头分镜转化为一条 3–30 秒、720p 或 1080p 的视频,带立体声音轨并提供五种画幅。它在长镜头和镜头切换中保持场景连贯,同时遵循你描述的运镜、对白与声音。
切换到 JSON 可使用 multi_prompt 编写多镜头分镜。
REST API
快速开始
三步完成第一次 Kling 4.0 Text to Video 调用。示例请求一段 10 秒带对白的长镜头,并返回 task_id。
连接 Vidgo API
创建 API Key,将它安全保存在服务端,并通过 Authorization 请求头以 Bearer Token 发送。
- 接口地址
- POST
https://api.vidgo.ai/api/generate/submit - 认证方式
- Authorization: Bearer VIDGO_API_KEY
提交一个生成任务
运行短示例,只需提供 prompt;duration、resolution 与 aspect_ratio 均有默认值。
curl --request POST \
--url "https://api.vidgo.ai/api/generate/submit" \
--header "Authorization: Bearer $VIDGO_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "kwaivgi/kling-v4.0/text-to-video",
"input": {
"prompt": "A single unbroken 10-second shot in a night market after rain. A street cook in a grey apron tosses noodles in a flaming wok, then slides them onto a plate and pushes it across the counter toward the camera. Camera: slow handheld push from the crowd to the counter, keeping the cook's face and hands in focus. Lighting: warm bulbs reflected in wet pavement, drifting steam. Audio: sizzling wok, clattering ladle, low crowd chatter; the cook says in English, \"Careful, it's hot.\" No text, no logos, no watermark.",
"duration": 10,
"resolution": "720p",
"aspect_ratio": "16:9"
}
}'等待并获取结果
使用返回的 task_id 查询同一个任务,直到状态变为 finished 或 failed;成功后读取 data.files[].file_url。
查询状态
GET https://api.vidgo.ai/api/generate/status/{task_id}当状态为 not_started 或 running 时,建议每隔数秒查询一次;到达 finished 或 failed 后停止。成功时从 data.files[].file_url 读取视频地址;生成较长视频时可逐步拉长间隔,也可在提交请求根层添加 callback_url 异步接收结果。
not_startedrunningfinishedfailed{
"code": 200,
"data": {
"task_id": "FYVDHUJZQ3J0SH2O",
"status": "not_started",
"created_time": "2026-11-05T07:04:47"
}
}{
"code": 200,
"data": {
"task_id": "FYVDHUJZQ3J0SH2O",
"status": "finished",
"files": [
{
"file_url": "https://cdn.vidgo.ai/apis/models/kwaivgi/kling-v4.0/text-to-video/v2/01/output-01.mp4",
"file_type": "video"
}
],
"created_time": "2026-11-05T07:04:47",
"error_message": null,
"progress": 100
}
}完整可运行示例
理解上面的三步流程后再展开。这里把提交、轮询、终态处理和结果读取合并在一个脚本中。
set -euo pipefail
: "${VIDGO_API_KEY:?Set VIDGO_API_KEY in your environment}"
REQUEST_BODY=$(cat <<'JSON'
{
"model": "kwaivgi/kling-v4.0/text-to-video",
"input": {
"prompt": "A single unbroken 10-second shot in a night market after rain. A street cook in a grey apron tosses noodles in a flaming wok, then slides them onto a plate and pushes it across the counter toward the camera. Camera: slow handheld push from the crowd to the counter, keeping the cook's face and hands in focus. Lighting: warm bulbs reflected in wet pavement, drifting steam. Audio: sizzling wok, clattering ladle, low crowd chatter; the cook says in English, \"Careful, it's hot.\" No text, no logos, no watermark.",
"duration": 10,
"resolution": "720p",
"aspect_ratio": "16:9"
}
}
JSON
)
SUBMIT_RESPONSE=$(curl --silent --show-error --fail-with-body \
--request POST \
--url "https://api.vidgo.ai/api/generate/submit" \
--header "Authorization: Bearer $VIDGO_API_KEY" \
--header "Content-Type: application/json" \
--data "$REQUEST_BODY")
TASK_ID=$(printf '%s' "$SUBMIT_RESPONSE" | jq -r '.data.task_id // .task_id // empty')
if [ -z "$TASK_ID" ]; then
printf 'Submit response did not include task_id:
%s
' "$SUBMIT_RESPONSE" >&2
exit 1
fi
while true; do
STATUS_RESPONSE=$(curl --silent --show-error --fail-with-body \
--url "https://api.vidgo.ai/api/generate/status/$TASK_ID" \
--header "Authorization: Bearer $VIDGO_API_KEY")
STATUS=$(printf '%s' "$STATUS_RESPONSE" | jq -r '.data.status // .status // empty')
case "$STATUS" in
finished)
printf '%s' "$STATUS_RESPONSE" | jq -r '(.data.files // .files // [])[]?.file_url'
break
;;
failed)
printf '%s' "$STATUS_RESPONSE" | jq -r '.data.error_message // .error_message // "Generation failed"' >&2
exit 1
;;
not_started|running)
sleep 2
;;
*)
printf 'Unexpected task status: %s
' "$STATUS" >&2
exit 1
;;
esac
done请求参数
model 和 callback_url 位于请求根层;生成参数位于 input。
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| model | string | 是 | — | 固定为 kwaivgi/kling-v4.0/text-to-video。 |
| callback_url | string (URL) | 否 | — | 用于接收任务结果的公开 HTTP(S) 地址,任务结束时推送。 |
| input | object | 是 | — | 生成参数:prompt 或 multi_prompt,以及可选的 duration、resolution 与 aspect_ratio。 |
| input.prompt | string | 否 | — | 单条提示词,1–26,000 个字符;与 multi_prompt 二选一。 |
| input.multi_prompt | object[] | 否 | — | 分镜 {prompt, duration?},合计 3–30 秒;同时发送 duration 时须等于合计值。 |
| input.duration | integer | 否 | 5 | 3–30 秒。 |
| input.resolution | string | 否 | 720p | 720p 或 1080p。 |
| input.aspect_ratio | string | 否 | auto | auto、16:9、9:16、1:1、21:9。 |
响应字段
提交响应会立即返回任务标识;随着任务推进,状态响应会补充进度、输出文件或失败信息。
| 字段 | 类型 | 说明 |
|---|---|---|
| code | integer | 应用层结果码,成功响应使用 0 或 200。 |
| message | string | 存在时返回便于阅读的响应或错误信息。 |
| data.task_id | string | 任务标识,用于拼接状态查询地址。 |
| data.status | string | 当前状态:not_started、running、finished 或 failed。 |
| data.created_time | string | 任务创建时间,采用日期时间格式。 |
| data.progress | number | 上游提供进度时返回的完成百分比。 |
| data.files[] | array | 任务成功后返回的生成文件列表。 |
| data.files[].file_url | string | 生成视频的公开访问地址。 |
| data.files[].file_type | string | 生成文件类型,例如 video。 |
| data.files[].watermark_url | string | null | 存在水印版本时返回对应地址。 |
| data.error_message | string | null | status 为 failed 时的失败详情。 |
任务生命周期
not_started 与 running 属于非终态;finished 与 failed 是两种终态,收到任意终态后都应停止轮询。
not_started任务已被接受,正在等待排队开始。
running视频正在生成中,请保持轮询查询。
finished任务完成,从 data.files[].file_url 读取视频地址。
failed生成失败,读取 data.error_message 了解原因并停止轮询。
轮询与错误处理
- 认证失败401 表示 Bearer API Key 缺失或无效,请在控制台确认密钥后重试。
- 参数校验400 表示请求字段不合法或属于其他端点,请检查prompt 与 multi_prompt 是否只发送了一个。
- 轮询间隔任务运行期间建议每隔数秒查询一次;生成较长视频时可逐步拉长间隔。
- 终态处理仅在 not_started 或 running 时继续轮询;收到 finished 或 failed 即停止。
- 回调方式在请求根层添加 callback_url,即可在任务结束时接收结果推送,无需持续轮询。
模型规格
| 规格 | 取值 | 说明 |
|---|---|---|
| 模型 | kwaivgi/kling-v4.0/text-to-video | 异步文生视频的模型标识。 |
| 时长 | 3–30 | 整数秒,默认 5 秒。 |
| 分辨率 | 720p | 1080p | 默认 720p。 |
| 画幅比例 | auto | 16:9 | 9:16 | 1:1 | 21:9 | 默认 auto。 |
| 价格 | 28.5 / 42.5 credits/s | 对应 720p / 1080p,按输出秒数计费。 |
相关模型
Kling 4.0 Text to Video API 常见问题
Kling 4.0 Text to Video API 是什么?
Kling 4.0 Text to Video 是快手用于文本生成视频的模型,由可灵 AI 于 2026 年 10 月 15 日发布。它将一条提示词或多镜头分镜转化为 3–30 秒、720p 或 1080p 的视频,并带立体声音轨。单次最长 30 秒的生成让角色、场景与运镜在长镜头和镜头切换中保持连贯。你可以通过 API 进行程序化调用,也可以在上方体验区直接在线试用。
Kling 4.0 Text to Video 的多镜头分镜怎么写?
用 multi_prompt 代替 prompt:一个分镜列表,每个镜头包含不超过 512 个字符的 prompt 和 1–30 秒的 duration(默认 5 秒)。分镜时长合计须为 3–30 秒,合计值即为视频总时长。
Kling 4.0 Text to Video 最长能生成多少秒?
可生成 3–30 秒之间任意整数秒的视频,单次完成,默认 5 秒。
Kling 4.0 Text to Video 能生成对白和声音吗?
每条视频都带立体声音轨。把台词写在引号中并注明语言,同时描述音效与环境声;可灵列出的对白语言包括英语、中文、日语、韩语、西班牙语等。
Kling 4.0 Text to Video 如何计费?
720p 每输出秒 28.5 点数($0.1425),1080p 每秒 42.5 点数($0.2125)。10 秒 1080p 视频为 425 点数。
Kling 4.0 Text to Video 提供哪些画幅?
auto、16:9、9:16、1:1 与 21:9。交付到竖版信息流等固定格式时,请明确设置比例。
Kling 4.0 Text to Video 与 Kling 3.0 Turbo 相比如何?
Kling 4.0 把单条时长提升到 30 秒,多镜头分镜总长可达 30 秒,并同时提供 720p 与 1080p。Kling 3.0 Turbo Pro 仍是 15 秒以内、速度更快、成本更低的 1080p 选择。















