Kling API: How to Call Kling 4.0

By Kerox · Published Nov 29, 2026 · Updated Nov 29, 2026

Made with Kling 4.0

Kling 4.0 is Kuaishou's video model for clips of 3 to 30 seconds at 720p, 1080p, or 4K. Kuaishou presents it as a production model: stable motion, picture and sound together, and coverage of tracking shots, orbits, and close-ups. That description is from kling.ai and Kuaishou's Kling 4 note on cinematic motion, read on 29 November 2026. The Kling 4.0 API reference says a generation can take up to 10 images. Kerox follows that cap.

The call is the same task API as every other model. The ID is kuaishou/kling-4.0. Five seconds at 720p is $0.7065. Five seconds at 4K is $2.4705. Parameter reference: Kling 4.0 API docs. Editing or extending an existing video is not available on this model yet. If that is the job, Seedance 2.5 has edit and extend.

What one request can do

prompt is required in every mode, including image to video.

  • Text to video. Prompt, duration, resolution, and an explicit aspect_ratio (16:9, 9:16, 1:1, or 21:9). auto is not valid here.
  • First frame, or first and last frame. first_frame is an image URL. last_frame is optional and requires the first. Do not also send images, videos, or audios. The ratio is explicit, not auto.
  • References. Up to 10 images, 5 videos, and 3 audio clips. This is the only mode where aspect_ratio may be auto. keep_original_sound keeps the reference video's audio in the result when you set it to true.

Kling 4.0 Flash (kuaishou/kling-4.0-flash) is the smaller sibling: 720p only, 3 to 20 seconds, reference images and video, no audio input. Kling Image 4.0 (kuaishou/kling-image-4.0) is a still model: one image at 2K, 4K, or 8K, with up to 10 reference images. It is not a video call. A 2K still is $0.0567.

Create a key

Sign in at API keys, create a key, and fund the wallet. The minimum top-up is $5. Put the secret in KEROX_API_KEY. Send Authorization: Bearer <your-api-key> from your server. Limits and rotation: Authentication. The shared loop, with a different model, is the quickstart.

Submit, poll, and save the MP4

POST https://api.kerox.ai/v1/tasks returns HTTP 201. Poll GET /v1/tasks/{id} every 3 seconds until succeeded or failed, for up to 10 minutes in these scripts, then download outputs[0].url. A task still processing at the deadline can be polled later with the same ID. Files expire after 7 days. Tasks.

# Needs curl and jq. KEROX_API_KEY is your key.
set -euo pipefail
API=https://api.kerox.ai/v1
AUTH="Authorization: Bearer $KEROX_API_KEY"
BODY='{
  "model": "kuaishou/kling-4.0",
  "input": {
    "prompt": "Track a red paper sailboat as it drifts across a dark pool. Warm copper lights switch on along the edge.",
    "duration": 5,
    "resolution": "720p",
    "aspect_ratio": "16:9"
  }
}'

TASK_ID=$(curl -sS --fail-with-body -X POST "$API/tasks" \
  -H "$AUTH" -H "Content-Type: application/json" -d "$BODY" | jq -r .id)
echo "Submitted $TASK_ID"

DEADLINE=$(( $(date +%s) + 600 ))
STATUS=processing
while [ "$STATUS" = "processing" ] && [ "$(date +%s)" -lt "$DEADLINE" ]; do
  sleep 3
  TASK=$(curl -sS --fail-with-body "$API/tasks/$TASK_ID" -H "$AUTH")
  STATUS=$(echo "$TASK" | jq -r .status)
done

if [ "$STATUS" != "succeeded" ]; then
  echo "Task $TASK_ID is $STATUS: $(echo "$TASK" | jq -c .error)"
  exit 1
fi
curl -sS --fail-with-body -o result.mp4 "$(echo "$TASK" | jq -r '.outputs[0].url')"
echo "Saved result.mp4"
# pip install requests
import os
import time
import requests

API = "https://api.kerox.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['KEROX_API_KEY']}"}

resp = requests.post(
    f"{API}/tasks",
    headers=HEADERS,
    json={
        "model": "kuaishou/kling-4.0",
        "input": {
            "prompt": "Track a red paper sailboat as it drifts across a dark pool. Warm copper lights switch on along the edge.",
            "duration": 5,
            "resolution": "720p",
            "aspect_ratio": "16:9",
        },
    },
    timeout=60,
)
if resp.status_code != 201:
    raise SystemExit(f"HTTP {resp.status_code}: {resp.json()['error']}")
task = resp.json()
print("Submitted", task["id"])

deadline = time.time() + 600
while task["status"] == "processing" and time.time() < deadline:
    time.sleep(3)
    task = requests.get(
        f"{API}/tasks/{task['id']}", headers=HEADERS, timeout=30
    ).json()

if task["status"] != "succeeded":
    raise SystemExit(f"Task {task['id']} is {task['status']}: {task.get('error')}")
file = requests.get(task["outputs"][0]["url"], timeout=120)
file.raise_for_status()
open("result.mp4", "wb").write(file.content)
print("Saved result.mp4")
// Node.js 18 or later. Save as generate.mjs and run: node generate.mjs
import fs from 'node:fs/promises';

const API = 'https://api.kerox.ai/v1';
const headers = { Authorization: `Bearer ${process.env.KEROX_API_KEY}` };

const res = await fetch(`${API}/tasks`, {
  method: 'POST',
  headers: { ...headers, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    model: 'kuaishou/kling-4.0',
    input: {
      prompt:
        'Track a red paper sailboat as it drifts across a dark pool. Warm copper lights switch on along the edge.',
      duration: 5,
      resolution: '720p',
      aspect_ratio: '16:9',
    },
  }),
});
let task = await res.json();
if (res.status !== 201)
  throw new Error(`HTTP ${res.status}: ${task.error.message}`);
console.log('Submitted', task.id);

const deadline = Date.now() + 10 * 60 * 1000;
while (task.status === 'processing' && Date.now() < deadline) {
  await new Promise((resolve) => setTimeout(resolve, 3000));
  const poll = await fetch(`${API}/tasks/${task.id}`, { headers });
  if (!poll.ok) throw new Error(`HTTP ${poll.status}`);
  task = await poll.json();
}
if (task.status !== 'succeeded') {
  throw new Error(
    `Task ${task.id} is ${task.status}: ${JSON.stringify(task.error)}`
  );
}
const file = await fetch(task.outputs[0].url);
if (!file.ok) throw new Error(`Download failed: HTTP ${file.status}`);
await fs.writeFile('result.mp4', Buffer.from(await file.arrayBuffer()));
console.log('Saved result.mp4');

Image to video uses a frame URL instead of a ratio of auto. This sample file is already public:

{
  "model": "kuaishou/kling-4.0",
  "input": {
    "prompt": "Track the red paper sailboat as it drifts across the pool",
    "first_frame": "https://cdn.kerox.ai/assets/samples/kling-4.0/paper-sail-frame.jpg",
    "duration": 5,
    "resolution": "1080p",
    "aspect_ratio": "16:9"
  },
  "webhook_url": "https://example.com/webhooks/kerox"
}

webhook_url replaces the poll. When the task reaches succeeded or failed, Kerox creates one notification and delivers it to a public https:// URL. A failed delivery is retried, up to 12 attempts. Deduplicate on the webhook-id header. The signing secret is in the console, not the URL. If the callback is late, poll with the task ID. Webhooks. Upload your own frames with Files; Kling image and video URLs on this model are https, not inline base64.

Idempotency-Key on the submit deduplicates a retry for 24 hours when the body is unchanged. Idempotency.

Parameters

FieldWhat to send
promptRequired in every mode.
durationInteger 3–30. Default 5. Flash: 3–20.
resolution720p (default), 1080p, or 4K. Flash: 720p only.
aspect_ratio16:9, 9:16, 1:1, 21:9, or auto. auto only with reference images, video, or audio.
first_frame, last_frameHTTPS image URLs. Exclusive with references.
imagesOne URL or up to 10.
videosOne URL or up to 5.
audiosOne URL or up to 3. Not on Flash.
keep_original_soundBoolean. Use it when a reference video should keep its audio.

There is no seed, no negative_prompt, and no n. Sending them returns 400. There is no edit mode and no extend mode on Kling 4.0 here.

Practical adjustments:

  • Write the ratio down for text and frames. Leaving aspect_ratio out is not the same as auto, and auto without a reference file is rejected. Set 16:9 or 9:16 unless you attached references.
  • 4K is a different product decision than a different prompt. The per-second rate steps up at 1080p and again at 4K. Draft at 720p, then rerun the keeper.
  • Flash is not "Kling 4.0 with a flag". It is a different model ID, a shorter maximum, and no audio input. A body that worked on 4.0 can fail on Flash if it includes audios or resolution 1080p.
  • One still, not a contact sheet. Kling Image 4.0 returns one image. Resolutions are 2K, 4K, and 8K. Output is png, jpeg, or webp. Reference images are billed as well as the output; the model page shows that line, and POST /v1/estimate quotes a specific request.

Studio is the same schema with a form.

What it costs

The tables below quote Kling 4.0 and Flash with no reference video. Each second of output is priced at that resolution. The official column is Kuaishou's published per-second price as the catalog stores it. Those rates are in the Kling video price table, read on 30 November 2026. The Kling 4.0 API reference lists the parameters those rates apply to. Kerox applies the model's public discount. The hold is placed when you submit and settled when the video finishes. Failure and timeout refund the hold in full.

Attaching videos switches the output rate. The reference video is then billed for the longer of its own length and the output length. The tables below do not apply to that request. Send the same body to POST /v1/estimate before you submit.

OutputOfficial priceKeroxYou save
5 s · 720p$0.7850$0.706510%
5 s · 1080p$1.1750$1.057510%
5 s · 4K$2.7450$2.470510%
10 s · 4K$5.4900$4.941010%

Flash is 720p only, so it is not a column in that table. Do not send 1080p or 4K to kuaishou/kling-4.0-flash. A 5-second Flash clip:

OutputOfficial priceKeroxYou save
5 s · 720p$0.4700$0.423010%

A 10-second 4K Kling 4.0 clip is $4.9410. Billing rules: Pricing and billing.

Kling Image 4.0 is per image:

OutputOfficial priceKeroxYou save
1 image · 2K$0.0630$0.056710%
1 image · 4K$0.0940$0.084610%
1 image · 8K$0.1570$0.141310%

Which Kling call, and when to leave Kling

  • kuaishou/kling-4.0 for 1080p or 4K, for audio references, and for clips between 21 and 30 seconds.
  • kuaishou/kling-4.0-flash for 720p volume, up to 20 seconds, when you do not need to pass audio.
  • kuaishou/kling-image-4.0 when the output is a still, including an 8K still.

Same key, different family, when Kling is the wrong shape: Seedance 2.5 if you need edit, extend, or a 480p draft; GPT Image 2.6 if you need a poster or a transparent PNG rather than a clip. Do not reuse a Kling body on those IDs. Each page lists the fields it accepts. The model list is the full set.

Errors

You gotWhat to do
HTTP 400, param points at aspect_ratioYou sent auto without reference media, or you omitted a ratio the mode requires. Set 16:9, 9:16, 1:1, or 21:9.
HTTP 400 on first_frame together with imagesThose modes are exclusive. Drop one.
HTTP 400 on duration or resolution4.0 is 3–30 seconds and 720p / 1080p / 4K. Flash is 3–20 and 720p only.
HTTP 401API key missing or revoked.
HTTP 402Balance or the key's spend cap. A 4K hold is larger than a 720p hold for the same seconds.
HTTP 429Wait out retry-after, or wait until an in-progress task ends.
status: "failed"The charge was returned. Submit a new task if you want another attempt.

The full code list is Errors.

Kling 4.0, in one pass

Create the key, submit kuaishou/kling-4.0 with a prompt, a whole-second duration, a resolution, and an explicit aspect ratio, then poll or set webhook_url. Use references when you need auto framing or keep_original_sound. Draft at 720p before you spend the 4K rate. The model page has the sample clips, and the API docs have a body for each mode.