All posts
Video Generation API

Kling 4.0 API: Your First Video in Minutes, Every Mode

One POST, one poll, one finished video. A developer walkthrough of the Kling 4.0 API on each::labs, with real input JSON for text to video, keyframes, references and video edit.

By Eftal Yurtseven · Nov 20, 2026 · 9 min read

Kling 4.0 API: Your First Video in Minutes, Every Mode

The demo clip is never the hard part. The hard part is the Tuesday afterwards, when the same shot has to come out of your backend, on a schedule, with the right length and the right frame, and nobody is clicking a button in an app. That's what a Kling 4.0 API call is for, and it's shorter than you'd think: one POST, one poll, one URL to a finished video.

This walkthrough covers the whole loop on each::labs, then gives you a real input body for every mode of Kling Video 4.0: text to video, image to video with keyframes, reference to video and video edit. Every parameter below comes straight from the each::labs request schema, so you can paste and run.

What the Kling 4.0 API Actually Gives You

Kling ships 4.0 as one model with four doors. On each::labs each door is its own model slug, and they all share the same request shape: a model, a version and an input object. Learn the shape once and switching modes is a slug change plus a few fields.

The four slugs are kling-video-4-0-text-to-video, kling-video-4-0-image-to-video, kling-video-4-0-reference-to-video and kling-video-4-0-video-edit, all at version 0.0.1. Across all four, the shared settings are the ones that make 4.0 worth calling. Duration is any whole number from 3 to 30 seconds. Resolution is 720p, 1080p (the default) or 4k. And dynamic_range takes sdr or hdr, where HDR means 10-bit output and only works at 1080p and 4K.

Prompts get room too. The schema allows up to 26,000 characters for English-only text and up to 11,000 for non-English text, with a weighted limit when you mix them. You won't need all of that, but it means you can write a real shot list instead of a slogan. If you want the craft side of that shot list, our Kling 4.0 prompting guide goes deep on structure.

The first message is short. Everything else is waiting for the reply.
The first message is short. Everything else is waiting for the reply.

Get a Key, Then Make One Call

Create an account, open the API keys page and generate a key. Put it in an environment variable and keep it out of your repo. That's the entire setup.

Now create a prediction. You POST to the prediction endpoint with your key in the X-API-Key header and a JSON body naming the model. It's the same three-field body for every model on each::labs, so once this works, every other slug is a copy and paste away.

curl -X POST https://api.eachlabs.ai/v1/prediction/ \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $EACHLABS_API_KEY" \
  -d '{
    "model": "kling-video-4-0-text-to-video",
    "version": "0.0.1",
    "input": {
      "prompt": "A lighthouse keeper climbs a spiral staircase at dusk, lantern in hand, slow upward tracking shot.",
      "duration": 10,
      "aspect_ratio": "16:9",
      "resolution": "1080p"
    }
  }'

The response is small. What you care about is predictionID, the handle for everything that follows. The call doesn't wait for the video, and it shouldn't: a 30-second 4K clip is real work, and you don't want an HTTP connection hanging open while it happens. The each::labs docs also describe passing the key as an Authorization: Bearer header, so use whichever style your HTTP client already speaks.

Patience is a polling interval with good manners.
Patience is a polling interval with good manners.

Poll Until It Says Success

Generation is asynchronous, so you ask for the result by ID. A GET on the prediction returns a status that moves through created, starting and processing before landing on success, error or cancelled.

curl https://api.eachlabs.ai/v1/prediction/YOUR_PREDICTION_ID \
  -H "X-API-Key: $EACHLABS_API_KEY"

When the status reads success, the output field holds your video. Depending on the model, output can be a single URL string or a list, so handle both and take the first item. Here's the full loop in Python with nothing but the standard library:

import json, os, time, urllib.request

API = "https://api.eachlabs.ai/v1/prediction/"
H = {"X-API-Key": os.environ["EACHLABS_API_KEY"], "Content-Type": "application/json"}

def call(url, body=None):
    data = json.dumps(body).encode() if body else None
    req = urllib.request.Request(url, data=data, headers=H)
    return json.load(urllib.request.urlopen(req))

job = call(API, {"model": "kling-video-4-0-text-to-video", "version": "0.0.1",
                 "input": {"prompt": "...", "duration": 10}})
pid = job["predictionID"]

while True:
    time.sleep(8)
    r = call(API + pid)
    if r["status"] in ("success", "error", "cancelled"):
        break

out = r["output"]
print(out if isinstance(out, str) else out[0])

Poll gently. Eight seconds between checks is plenty for video, and a long 4K render won't finish faster because you asked twice as often. Treat error as a signal to log the full response and look at your input, because media constraints (file size, resolution, clip length) are enforced by Kling and that's where most first-day failures come from.

Text to Video: The Kling 4.0 API in Its Simplest Form

Text to video needs exactly one field, prompt. Everything else has a default except duration, which the schema doesn't default for this mode, so set it yourself rather than finding out what you got. Aspect ratio takes 21:9, 16:9 (the default), 9:16, 1:1, 4:3 or 3:4. That 21:9 option is the one to notice: a proper cinema frame, straight from the API.

{
  "model": "kling-video-4-0-text-to-video",
  "version": "0.0.1",
  "input": {
    "prompt": "See the blockquote below",
    "duration": 20,
    "aspect_ratio": "21:9",
    "resolution": "4k",
    "dynamic_range": "hdr"
  }
}

A 20-second clip deserves a prompt with a timeline, not a single adjective. Something like this:

A night market in the rain, 21:9, anamorphic feel. 0 to 6 seconds: slow dolly along a row of food stalls, steam rising into neon light. 6 to 14 seconds: the camera settles on an old cook flipping noodles in a wok, flames lighting her face. 14 to 20 seconds: crane up and back to reveal the whole street glowing under the rain. Warm practical light, wet reflections on the asphalt, no text on screen, no crowd looking at the camera.

Notice the negatives live inside the prompt. There's no separate negative prompt field in the 4.0 schema; the parameter description says to put negative descriptions in the prompt itself, so write them as plain sentences at the end.

Pin the frames that matter. Let the motion find its way between them.
Pin the frames that matter. Let the motion find its way between them.

Image to Video: Pin the Frames You Can't Leave to Chance

Kling Video 4.0 Image-to-Video flips the requirement: images is required and prompt is optional. You pass 1 to 10 images, each with a type of first_frame, middle_frame or last_frame, a url, and an optional id you can mention in the prompt. Images must be JPG or PNG, at most 30 MB, at least 300 x 300 pixels, with an aspect ratio between 2:5 and 5:2. Duration defaults to 10 seconds here, and there's no aspect_ratio field, so prepare your keyframes in the shape you plan to ship.

{
  "model": "kling-video-4-0-image-to-video",
  "version": "0.0.1",
  "input": {
    "images": [
      {"type": "first_frame",  "url": "https://example.com/box-closed.png", "id": "closed"},
      {"type": "middle_frame", "url": "https://example.com/box-open.png",   "id": "open"},
      {"type": "last_frame",   "url": "https://example.com/watch-hero.png", "id": "hero"}
    ],
    "prompt": "See the blockquote below",
    "duration": 12,
    "resolution": "1080p",
    "dynamic_range": "hdr"
  }
}
Start on closed: a matte black gift box on a walnut desk, morning light from the left. The lid lifts slowly by itself and the camera pushes in as the box reaches open. Continue the push until the watch fills the frame and settle exactly on hero. Smooth, continuous, no cuts, no hands entering the frame.

Kling's own keyframe guide for 4.0 makes the point better than any schema: keyframes show the important moments, and the prompt explains how the video moves between them. Don't spend all ten slots because you can. Use one wherever the picture genuinely has to change, and let the prompt carry the camera and pacing in the same order as your frames.

Reference to Video: Cast Once, Reuse Everywhere

Kling Video 4.0 Reference-to-Video is where the input object gets interesting. Only prompt is required, and around it you can attach up to 10 images (the keyframe roles plus refer_image), up to 5 videos typed feature_video or base_video (at most one base), up to 7 elements holding existing Kling Element IDs, and up to 3 voices with a custom or system voice_id. All of it combined can't go past 15 references, and every id has to be unique across images, videos, elements and voices. If you use more than one refer_image or middle_frame, ids become mandatory.

{
  "model": "kling-video-4-0-reference-to-video",
  "version": "0.0.1",
  "input": {
    "prompt": "See the blockquote below",
    "images": [
      {"type": "refer_image", "url": "https://example.com/presenter.png", "id": "presenter"},
      {"type": "refer_image", "url": "https://example.com/kettle.png",    "id": "kettle"}
    ],
    "videos": [
      {"type": "feature_video", "url": "https://example.com/orbit-move.mp4", "id": "orbit"}
    ],
    "aspect_ratio": "9:16",
    "duration": 15,
    "resolution": "1080p"
  }
}
presenter stands in a sunlit kitchen and lifts kettle toward the camera, smiling. Follow the camera path and pacing of orbit: a slow half circle around her from left to right. She pours water into a glass cup and steam catches the light. Keep her face, hair and outfit identical to presenter, keep the kettle's shape and color identical to kettle.

The ids are plain names you choose, and the prompt uses them as words. Name them like a casting sheet (presenter, kettle, orbit) and your prompts stay readable months later. Aspect ratio here adds adaptive, which is also the default. Our reference to video guide covers casting a character across many scenes.

A good edit says what stays as clearly as what changes.
A good edit says what stays as clearly as what changes.

Video Edit: Hand It a Take, Not a Blank Page

Kling Video 4.0 Video Edit requires two things: a prompt and a videos array containing exactly one base_video, the take you're changing. You can add feature_video references, up to 5 videos in total, and the combined duration has to fall between 3 and 30 seconds. Source videos are MP4 or MOV, up to 300 MB, 24 to 60 fps, with each side between 700 and 4,553 pixels. Images, elements and voices work the same way they do in reference mode.

{
  "model": "kling-video-4-0-video-edit",
  "version": "0.0.1",
  "input": {
    "prompt": "See the blockquote below",
    "videos": [
      {"type": "base_video", "url": "https://example.com/street-take-03.mp4", "id": "take"}
    ],
    "images": [
      {"type": "refer_image", "url": "https://example.com/red-coat.png", "id": "coat"}
    ],
    "duration": 8,
    "aspect_ratio": "adaptive",
    "resolution": "1080p"
  }
}
In take, change the woman's grey jacket to the long red wool coat in coat. Turn the overcast sky into late golden hour with long shadows across the street. Keep her walk, her face, the camera movement and every passerby exactly as they are.

The last sentence is the important one. An edit prompt should say what stays as firmly as what changes, because "keep" is the instruction that protects the take you already liked. If edits are your main job, our Kling 4.0 video edit guide has more patterns.

Draft on Flash, Spend 4K on the Keeper

Here's the opinion: you shouldn't be rendering first attempts in 4K HDR. Ever. Every mode above has a faster sibling on each::labs, starting with Kling Video 4.0 Flash Text-to-Video, with Flash versions of image to video, reference to video and video edit next to it. Use Flash while you're still arguing about the prompt, check its model page for the exact parameters it accepts, then send the winning prompt to the full model at the resolution you'll actually publish.

Because both live behind the same prediction endpoint, the swap is one string in your request body. Wire your code so the slug is a setting, not a constant, and the draft and final passes become the same function. The full argument is in Draft Fast, Finish on Kling 4.0, and if you want to compare 4.0 against other engines on the same prompt, browse the text-to-video models on each::labs and change nothing but the slug.

Frequently Asked Questions

How do I get access to the Kling 4.0 API?

Through each::labs you don't need a separate Kling developer account. Create an each::labs API key, send it in the X-API-Key header, and POST to https://api.eachlabs.ai/v1/prediction/ with one of the four Kling Video 4.0 slugs and version 0.0.1.

How long can a Kling Video 4.0 clip be?

Any whole number of seconds from 3 to 30, set with duration. Image to video defaults to 10 seconds; text to video has no default, so always pass it. In video edit mode, the combined length of your source videos also has to sit inside 3 to 30 seconds.

Does Kling 4.0 support HDR and 4K through the API?

Yes on both, with one rule. Set resolution to 4k for 4K, and set dynamic_range to hdr for 10-bit HDR, which the schema allows only at 1080p and 4K. A 720p request should stay on sdr.

Can I get a callback instead of polling?

Polling is the simplest place to start, and for a first integration it's all you need. For production, the each::labs create request for these models also accepts an optional webhook_url that receives the result asynchronously, plus a webhook_secret used to sign those webhook requests, so your server hears back without asking.

Start with what you need.

Scale when you’re ready.