Kling 4.0 API
Kling 4.0 的全部输入字段、字段之间的规则、价格,以及完整的请求和响应示例。
"model": "kling-4-0"Generates or edits video from a prompt, images and reference videos. Send either prompt or contents.
What it does
Kling 4.0 makes a video of 3 to 30 seconds from a prompt, keyframe images, reference images or reference videos, and edits an existing video. A request has one of two shapes. A prompt alone goes in input.prompt. Anything with media goes in input.contents: one prompt item plus image and video items, each named by its type. Settings go in input.settings. The items you send choose the mode:
| Mode | Input | Other fields to set |
|---|---|---|
| [Text to video](#text-to-video) | prompt | settings.aspect_ratio (default 16:9) |
| [First frame](#first-frame) | contents: a prompt item and one first_frame | — |
| [Keyframes](#keyframes) | contents: a prompt item, first_frame, any middle_frame items, last_frame | id on each middle_frame when there are several |
| [Reference images](#reference-images) | contents: a prompt item and 1 to 10 refer_image items | id on each, cited in the prompt as @id |
| [Reference video](#reference-video) | contents: a prompt item, 1 to 5 feature_video items, optional images | id on each video when there are several |
| [Edit a video](#edit-a-video) | contents: a prompt item and one base_video | — |
Every example below is a complete body for POST /v1/generations. Send the same body to POST /v1/estimates first: it is free, creates no task, holds no Credits, and refuses an invalid body with the same 422 as a create. The https://media.vizoapi.com/... files are public samples, so the examples run as they are; replace them with your own file or an uploaded ast_... asset ID.
Modes
Text to video
Send only prompt at the top of input, never together with contents (rule prompt_or_contents). settings.aspect_ratio is 16:9, 9:16, 1:1 or 21:9, and 16:9 when you leave it out; adaptive is refused here (rule value_not_allowed), because there is no image to follow. settings.duration is 3 to 30 seconds; leave it out to let the model choose (see [Output](#output)).
{
"model": "kling-4-0",
"input": {
"prompt": "A paper boat drifts across a still pond at dawn, mist on the water, slow push-in, soft natural light",
"settings": {
"resolution": "720p",
"duration": 5,
"aspect_ratio": "16:9"
}
}
}First frame
The video starts on your image. contents holds exactly one prompt item (rule prompt_count) and one first_frame. Leave aspect_ratio out to keep the image's shape. The prompt describes what happens next.
{
"model": "kling-4-0",
"input": {
"contents": [
{ "type": "prompt", "text": "The hominids step back as the sun rises behind the monolith, slow push-in" },
{ "type": "first_frame", "url": "https://media.vizoapi.com/samples/seedance-2-5/odyssey-v1/keyframes/monolith.jpg" }
],
"settings": {
"resolution": "720p",
"duration": 5
}
}
}Keyframes
The video passes through your images in order: one first_frame, any number of middle_frame items and one last_frame. A second first_frame or last_frame is refused (rule frame_repeated). When there are two or more middle_frame items, each needs a unique id (rules content_id_required, content_id_duplicate); name them in the prompt as @id. A first_frame and last_frame alone also work.
{
"model": "kling-4-0",
"input": {
"contents": [
{ "type": "prompt", "text": "The camera glides past the ring-shaped station, dives toward the black monolith at @monolith, then rises into the final wide shot" },
{ "type": "first_frame", "url": "https://media.vizoapi.com/samples/seedance-2-5/odyssey-v1/keyframes/station.jpg" },
{ "type": "middle_frame", "id": "monolith", "url": "https://media.vizoapi.com/samples/seedance-2-5/odyssey-v1/keyframes/monolith.jpg" },
{ "type": "last_frame", "url": "https://media.vizoapi.com/samples/seedance-2-5/odyssey-v1/keyframes/ending.jpg" }
],
"settings": {
"resolution": "720p",
"duration": 8
}
}
}Reference images
Up to 10 images with type refer_image give the model characters, objects, places or a style to reuse; they do not fix any frame. Give each a unique id and cite it in the prompt as @id. An id is required when there are two or more refer_image items (rule content_id_required). Set aspect_ratio to a fixed value, or adaptive to follow your images.
{
"model": "kling-4-0",
"input": {
"contents": [
{ "type": "prompt", "text": "Shot 1: @monolith stands on a savanna at dawn. Shot 2: match cut to @station tumbling slowly in black space." },
{ "type": "refer_image", "id": "monolith", "url": "https://media.vizoapi.com/samples/seedance-2-5/odyssey-v1/keyframes/monolith.jpg" },
{ "type": "refer_image", "id": "station", "url": "https://media.vizoapi.com/samples/seedance-2-5/odyssey-v1/keyframes/station.jpg" }
],
"settings": {
"resolution": "720p",
"duration": 8,
"aspect_ratio": "16:9"
}
}
}Reference video
A feature_video gives the model motion, camera movement or pacing to follow for a new video. Send up to 5 videos (rule too_many_videos), each 3 to 30 seconds and 30 seconds together; several feature_video items need unique ids (rule content_id_required). Images can be added. Any video item moves the task to the -video tier of its resolution, which bills the input video's seconds too (see [How it is billed](#how-it-is-billed)).
{
"model": "kling-4-0",
"input": {
"contents": [
{ "type": "prompt", "text": "Follow the camera movement and pacing of @motion, set on @station drifting past an amber planet" },
{ "type": "feature_video", "id": "motion", "url": "https://media.vizoapi.com/samples/seedance-2-5/odyssey-v1/1.mp4" },
{ "type": "refer_image", "id": "station", "url": "https://media.vizoapi.com/samples/seedance-2-5/odyssey-v1/keyframes/station.jpg" }
],
"settings": {
"resolution": "720p",
"duration": 5,
"aspect_ratio": "16:9"
}
}
}Edit a video
Changes the source video: replace an object, restyle a scene, change the sky. Send it as one base_video (a second one is refused, rule frame_repeated) and say the change in the prompt. Leave duration out and the model takes the length from the source; the hold then covers 30 output seconds. Reference images can be added to show what to put in. An edit uses the -video tier like a reference video.
{
"model": "kling-4-0",
"input": {
"contents": [
{ "type": "prompt", "text": "Replace the black monolith with a tall crystal obelisk; keep everything else unchanged" },
{ "type": "base_video", "url": "https://media.vizoapi.com/samples/seedance-2-5/odyssey-v1/1.mp4" }
],
"settings": {
"resolution": "720p"
}
}
}Input limits
| Limit | Value | Checked |
|---|---|---|
| Shape | prompt or contents, never both | At create, 422 invalid_input (prompt_or_contents) |
contents items | 1 to 16. Exactly one prompt item, at least one image or video, up to 10 images and 5 videos, at most one first_frame, last_frame and base_video | At create (too_many_items, too_few_items, prompt_count, contents_need_image, too_many_images, too_many_videos, frame_repeated) |
id | Up to 128 characters, unique in contents; required on repeated middle_frame, refer_image and feature_video items | At create (content_id_required, content_id_duplicate) |
| Prompt | One shared budget: ASCII characters ÷ 26,000 + other characters ÷ 11,000 must be at most 1. So up to 26,000 characters of plain English, 11,000 of Chinese or Japanese, or a mix in between. Accented letters such as é or ü count as other characters | At create (out_of_range) |
| Each video | 3 to 30 seconds | At create when the file's length can be read, 422 input_duration_out_of_range (media_length); otherwise when the task runs |
| All videos together | At most 30 seconds | Same, rule video_total_too_long |
| Image file | PNG or JPEG; up to 30 MB | At create when readable: 422 input_media_invalid (format) or input_media_too_large (size) |
| Video file | MP4 or MOV; up to 300 MB | Same |
| Uploaded asset | image/png, image/jpeg, video/mp4; up to 20,000,000 bytes. An upload may also be image/webp, but this model takes only PNG and JPEG images: a WebP asset passes the create and the task fails with generation_failed | Type and size when you request the upload, 422; WebP only when the task runs |
| Image pixel size and aspect ratio, video resolution and frame rate | Checked by the model only | When the task runs: the task fails with generation_failed and is not charged |
A media value is a public https URL (up to 4,000 characters) or an ast_... asset ID from your project. Plain http, private or local addresses, URLs with a user name or #fragment, and Base64 data are refused with 422 (rule bad_format). The model fetches a linked file itself, possibly some time after acceptance, so keep it reachable until the task closes. See Model inputs and media.
Output
| Setting | Values |
|---|---|
settings.resolution | 720p or 1080p (default) |
settings.aspect_ratio | 16:9, 9:16, 1:1, 21:9 or adaptive. A prompt alone is 16:9 when left out and refuses adaptive. With contents, leave it out to keep the shape of your frame images, or send adaptive to follow your input images |
settings.duration | 3 to 30 seconds. Leave it out to let the model choose: it reads the length from the prompt and, for an edit, from the source video |
There is no watermark, seed or audio setting. A succeeded task lists one MP4 in result.outputs: take its asset_id and get a download URL with download an asset. Outputs are kept for 7 days. See Get results.
How it is billed
The input selects the tier: settings.resolution (1080p when left out) alone, or resolution plus -video when contents has any feature_video or base_video. Images never change the tier or the price, and neither does aspect_ratio.
| Tier | Credits per second | Seconds billed |
|---|---|---|
720p, 1080p | 31.4, 47 | Output seconds |
720p-video, 1080p-video | 18, 27 | The larger of output + input seconds and 2 × output seconds |
Input seconds are the length of all input videos together, rounded up, at most 30. When a video's length cannot be read at create, the hold counts 30 input seconds. When duration is left out, the hold counts 30 output seconds. The sample video in the examples runs 12.06 seconds, so it holds 13 input seconds.
Holds at 720p:
| Request | Output | Input | Billed | Held (Credits) |
|---|---|---|---|---|
Text, frames or reference images, duration: 5 | 5 | — | 5 | 157.000 |
The same, duration left out | 30 | — | 30 | 942.000 |
Reference video of 12.06 s, duration: 5 | 5 | 13 | max(18, 10) = 18 | 324.000 |
| The same, video length not readable | 5 | 30 | max(35, 10) = 35 | 630.000 |
Reference video of 5 s, duration: 15 | 15 | 5 | max(20, 30) = 30 | 540.000 |
Edit of a 12.06 s video, duration left out | 30 | 13 | max(43, 60) = 60 | 1080.000 |
The hold is only the estimate. A succeeded task is charged for the length of the video delivered, to the millisecond, plus the measured input on a -video tier, raised to 2 × output where that is larger, at the tier's rate. So price.charged can be below the hold (the rest is released) or above it, with no cap. When the delivered length, or on a -video tier the input length, cannot be measured, the charge is the hold. Usage above the hold comes from your available balance; what it cannot cover is owed, and new creates get 402 balance_negative until a top-up. A failed or unresolved task is not charged. Send the body to POST /v1/estimates to see the exact hold and its basis (output_seconds, input_seconds, billed_seconds, auto). See Billing.
Errors and behaviors
| When | Response | What to do |
|---|---|---|
| A field the schema does not list, a wrong value or type | 422 invalid_input, errors[].rule such as field_not_allowed, value_not_allowed, out_of_range | Send only the fields in the reference below |
More than 16 contents items, or an empty list | 422 invalid_input, rule too_many_items or too_few_items | Send 1 to 16 items |
Both or neither of prompt and contents | 422 invalid_input, rule prompt_or_contents | Send one of them |
A contents rule is broken | 422 invalid_input with the rule: prompt_count, contents_need_image, too_many_images, too_many_videos, frame_repeated, content_id_required, content_id_duplicate | Fix the item at errors[].path |
aspect_ratio: "adaptive" with a prompt alone | 422 invalid_input, rule value_not_allowed | Pick a fixed ratio or leave it out |
| A measured video is too short or too long, alone or in total | 422 input_duration_out_of_range; errors[] names the item (/contents/N/url, rule media_length) or the total (/contents, rule video_total_too_long) | Trim the video |
| A linked file has the wrong format or is too large | 422 input_media_invalid or input_media_too_large | Convert or shrink it |
| The model refuses the request when the task runs: content safety, a file it cannot fetch or use, a setting it does not accept | Task fails with generation_failed | Check the prompt, media and URLs; nothing is charged |
This model reports no reason for a failed task, so every refusal, including content safety, closes as generation_failed, never input_moderated or output_moderated. Moderation is always on; no field turns it off. Each task has a deadline of 24 hours from acceptance. A task still unfinished then closes as unresolved, releases its hold and is not charged; if its result arrives later, it is added at no charge and late_result_available becomes true. See Errors and Get results.
Prompting tips
- Give every image and video an
idand cite it with@id: "keep the face of @hero", "follow the camera of @motion". The id is what links a word in the prompt to an item. - Write the shot, not just the subject: subject, action, setting, camera movement, light and style. For several shots, number them ("Shot 1: …, Shot 2: …").
- With keyframes, describe the motion between them; the images already fix where the video starts, passes and ends.
- For an edit, say exactly what changes and what stays ("keep everything else unchanged").
- If you leave
durationout, say the length you want in the prompt ("a 6-second shot"); the model reads it from there. - Set
durationwhen you know the length: it keeps the hold small, because a missing duration holds 30 seconds.
价格
输入决定价格档位。视频按输出秒数计费;含输入视频的档位同时计入输入秒数。
| 档位 | 选择条件 | 价格 | 时长 |
|---|---|---|---|
720p | resolution = 720p | 31.4 积分/秒 | 3–30 秒 |
1080p | resolution = 1080p | 47 积分/秒 | 3–30 秒 |
720p-video | resolution = 720p, 含输入视频 | 18 积分/秒 | 3–30 秒 |
1080p-video | resolution = 1080p, 含输入视频 | 27 积分/秒 | 3–30 秒 |
规则
- Send either
promptfor text-only generation orcontentsfor images and videos, never both. - Exactly one prompt, up to 10 images and 5 videos (at most one base_video). Videos must be MP4/MOV, at most 300 MB each, 3–30 seconds each and at most 30 seconds total. Repeated feature_video, refer_image or middle_frame items require unique ids.
- Repeated middle_frame, refer_image or feature_video entries require unique ids, cited in the prompt as @id.
aspect_ratioadaptivefollows your input images, so it needscontents; a text-only request withoutaspect_ratiois 16:9.
输入字段
在 input 中发送这些字段。表中没有的字段会被拒绝,返回 HTTP 422 invalid_input。
| 字段 | 说明 |
|---|---|
| 必填: Text-only generation. Up to 26000 Latin or 11000 other characters, counted together. 最多 26,000 个字符 |
| 必填: Exactly one prompt, up to 10 images and 5 videos (at most one base_video). Videos must be MP4/MOV, at most 300 MB each, 3–30 seconds each and at most 30 seconds total. Repeated feature_video, refer_image or middle_frame items require unique ids. 至少 1 项 · 最多 16 项 |
contents[]. | Item kind. 可选值 promptfirst_framemiddle_framelast_framerefer_imagefeature_videobase_video |
type 为 prompt 的项 | |
contents[]. | Prompt text. Up to 26000 Latin or 11000 other characters, counted together. 最多 26,000 个字符 |
type 为 first_frame, middle_frame, last_frame, refer_image, feature_video, base_video 的项 | |
contents[]. | An https URL or an uploaded asset id (ast_...). 最多 4000 个字符 · 格式 |
contents[]. | Name cited in the prompt as @id. Unique within contents. 最多 128 个字符 |
| |
settings. | Output resolution. Defaults to 1080p. 可选值 720p1080p默认值 |
settings. | Output seconds, 3 to 30. Omit for automatic length: holds 30 seconds and settles delivered duration. 最小 3 · 最大 30 |
settings. | Output aspect ratio. A prompt request is 16:9 when this is left out and does not accept adaptive. With contents, leave it out to keep the shape of your frame images, or send adaptive to match your input images. 可选值 21:916:99:161:1adaptive |
示例
完整的创建请求、202 响应,以及任务成功后的状态。
请求
cURL
curl https://api.vizoapi.com/v1/generations \
-H "Authorization: Bearer $VIZO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kling-4-0",
"input": {
"prompt": "A paper boat drifting on a pond at dawn, slow dolly in",
"settings": {
"resolution": "720p",
"duration": 5,
"aspect_ratio": "16:9"
}
},
"metadata": {
"client_reference": "my-unique-reference-1"
}
}'Python
import os, requests
# Send once: do not retry this request automatically.
task = requests.post(
"https://api.vizoapi.com/v1/generations",
headers={"Authorization": f"Bearer {os.environ['VIZO_API_KEY']}"},
json={
"model": "kling-4-0",
"input": {
"prompt": "A paper boat drifting on a pond at dawn, slow dolly in",
"settings": {
"resolution": "720p",
"duration": 5,
"aspect_ratio": "16:9"
}
},
"metadata": {
"client_reference": "my-unique-reference-1"
}
},
timeout=60,
).json()
print(task["id"], task["status"])Node.js
// Send once: do not retry this request automatically.
const res = await fetch("https://api.vizoapi.com/v1/generations", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.VIZO_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model": "kling-4-0",
"input": {
"prompt": "A paper boat drifting on a pond at dawn, slow dolly in",
"settings": {
"resolution": "720p",
"duration": 5,
"aspect_ratio": "16:9"
}
},
"metadata": {
"client_reference": "my-unique-reference-1"
}
}),
});
const task = await res.json();
console.log(task.id, task.status);此输入选择 720p 档位,每秒 31.4 积分。5 秒共冻结 157.000 积分。
响应
202 已受理
{
"id": "gen_01JD8Z5QW3XR",
"model": "kling-4-0",
"source": "api",
"created_at": "2026-11-08T09:00:00Z",
"customer_resolution_deadline": "2026-11-09T09:00:00Z",
"late_result_available": false,
"metadata": {
"client_reference": "my-unique-reference-1"
},
"status": "processing",
"execution_status": "processing",
"delivery_status": "pending",
"billing_status": "pending",
"version": 1,
"price": {
"unit": "credit",
"estimated": "157.000",
"reserved": "0.000",
"charged": "0.000",
"refunded": "0.000"
},
"allowed_actions": [],
"closed_at": null,
"error": null,
"result": null
}200 已成功
{
"id": "gen_01JD8Z5QW3XR",
"model": "kling-4-0",
"source": "api",
"created_at": "2026-11-08T09:00:00Z",
"customer_resolution_deadline": "2026-11-09T09:00:00Z",
"late_result_available": false,
"metadata": {
"client_reference": "my-unique-reference-1"
},
"status": "succeeded",
"execution_status": "succeeded",
"delivery_status": "ready",
"billing_status": "settled",
"version": 4,
"price": {
"unit": "credit",
"estimated": "157.000",
"reserved": "0.000",
"charged": "157.000",
"refunded": "0.000"
},
"allowed_actions": [],
"closed_at": "2026-11-08T09:01:31Z",
"error": null,
"result": {
"asset_id": "ast_01JD8Z9M2C4V",
"outputs": [
{
"index": 0,
"asset_id": "ast_01JD8Z9M2C4V",
"content_type": "video/mp4"
}
]
}
}