Kling Videos Generation API Integration Guide

This article introduces how to integrate with the Kling Videos Generation API, which can generate official Kling videos by entering custom parameters.

Application Process

To use the Kling Videos Generation API, first obtain your API Token from the Ace Data Cloud Console and keep it for later use.

If you have not logged in or registered, you will be automatically redirected to the login page to register and log in, and then automatically returned to the current page.

API Keys for general-purpose applications can be used for services enabled for the account; Keys for dedicated applications are used according to the service scope of that application. Please check the Key's permissions, validity period, and limits, and confirm that the application balance is sufficient to pay for this request. Available trial credits are subject to what is displayed in your account. If the balance is insufficient, click the "Recharge" button.

📘 Full documentation: Kling Videos Generation API →

Basic Usage

First, let's look at the basic usage: enter the prompt prompt, generation action action, first-frame reference image start_image_url, and model model to obtain the processed result. First, you need to pass an action field with the value text2video. It mainly includes three actions: text-to-video (text2video), image-to-video (image2video), and video extension (extend). Then, you also need to enter the model model. The main models currently available are kling-v1, kling-v1-6, kling-v2-master, kling-v2-1-master, kling-v2-5-turbo, kling-v2-6, kling-v3, kling-v3-omni, and kling-o1. The details are as follows:

You can see that we have set the Request Headers here, including:

  • accept: The format in which you want to receive the response. Here it is set to application/json, meaning JSON format.
  • authorization: The key used to call the API. After applying for it, you can select it directly from the dropdown.

We have also set the Request Body, including:

  • model: The model used to generate the video. The main models are kling-v1, kling-v1-6, kling-v2-master, kling-v2-1-master, kling-v2-5-turbo, kling-v2-6, kling-v3, kling-v3-omni, and kling-o1.
  • mode: The mode used to generate the video. The available values are standard mode std, fast mode pro, and native 4K mode 4k. The 4k mode only supports kling-v3 and kling-v3-omni and is incompatible with camera_control (camera movement control).
  • action: The action for this video generation task. There are mainly three actions: text-to-video (text2video), image-to-video (image2video), and video extension (extend).
  • start_image_url: The link to the first-frame reference image that must be uploaded when the image-to-video action image2video is selected.
  • end_image_url: Optional for image-to-video, specifies the final frame.
  • duration: The video duration, in seconds. kling-v3 and kling-v3-omni support integer durations of 3–15 seconds; kling-o1 only supports 5 seconds; other models support 5 or 10 seconds.
  • generate_audio: Whether to generate audio simultaneously, optional, Boolean. Supported by kling-v3, kling-v3-omni, and kling-v2-6 (pro mode only). Defaults to false.
  • aspect_ratio: The video aspect ratio, optional. Supports 16:9, 9:16, and 1:1, with 16:9 as the default.
  • cfg_scale: The relevance strength, ranging from [0,1]. The higher the value, the more closely the result follows the prompt.
  • camera_control: Optional, an object parameter that controls camera movement. Supports type/simple presets and configurations such as horizontal, vertical, pan, tilt, roll, and zoom.
  • negative_prompt: Optional, a negative prompt specifying what you do not want to appear, up to 200 characters.
  • image_list: The Omni reference image list, applicable to the kling-o1 and kling-v3-omni models. See "Omni All-in-One Reference" below for usage.
  • video_list: The Omni reference video list (supports video editing), applicable to the kling-o1 and kling-v3-omni models. See "Omni All-in-One Reference" below for usage.
  • prompt: The prompt.
  • callback_url: The URL to which the result should be sent.
  • async: Optional. When set to true, the API immediately returns a task_id without requiring a callback_url. The result can then be obtained by polling the corresponding task query API.

After making the selections, you can see that the corresponding code has also been generated on the right, as shown below:

Click the "Try" button to test it. As shown above, we obtained the following result:

{
  "success": true,
  "video_id": "900798310464749610",
  "video_url": "https://cdn.acedata.cloud/assets/examples/kling/6c68c267-065b-4423-b66b-a0e4c59ee0d5-6a664a591a53.mp4",
  "duration": "5.041",
  "state": "succeed",
  "task_id": "6c68c267-065b-4423-b66b-a0e4c59ee0d5"
}

The returned result contains several fields, described as follows:

  • success, the status of the video generation task.
  • task_id, the ID of the video generation task.
  • video_id, the video ID of the video generation task.
  • video_url, the video link for the video generation task.
  • duration, the video duration of the video generation task.
  • state, the status of the video generation task.

You can see that we have obtained satisfactory video information. We only need to use the video link in data in the result to obtain the generated Kling video.

Additionally, if you want to generate the corresponding integration code, you can copy the generated code directly. For example, the CURL code is as follows:

curl -X POST 'https://api.acedata.cloud/kling/videos' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "action": "text2video",
  "model": "kling-v3",
  "prompt": "White ceramic coffee mug on glossy marble countertop with morning window light. Camera slowly rotates 360 degrees around the mug, pausing briefly at the handle."
}'

Model Capability Matrix

O1 and Omni Reference Video Pricing

kling-o1 is billed according to the mode and whether video_list is provided. The following are the prices for a 5-second finished video:

Mode No reference video With reference video
std 4.005 Credits 6.010 Credits
pro 5.340 Credits 8.010 Credits
Successful requests to kling-o1 and kling-v3-omni with reference videos are charged by billed seconds: std is 1.202 Credits/second, and pro is 1.602 Credits/second. For example, generating 5 seconds in std mode costs 6.010 Credits. Omitting video_list does not trigger the reference video rate; image_list, first-frame images, and last-frame images are not reference videos either. Reference videos cannot be used with generate_audio=true.

Video editing with refer_type=base (the default) may follow the length of the reference video, with the final charge based on the actual output video length rounded to the nearest whole second: for example, 5.708 seconds is billed as 6 seconds, and 5.041 seconds as 5 seconds. refer_type=feature uses the requested duration. usage.reference_video_seconds in the response gives the final billed seconds; the estimated price at the time of the request may differ from the final charge.

Parameter support varies significantly between models. The following matrix is compiled from the official Kling video models documentation. Before making a request, check whether the current model / mode / duration combination supports the features you need; otherwise, errors such as model/mode/duration(...) is not supported with image_tail will be returned.

Model Mode end_image_url (first and last frames) generate_audio (audio) camera_control (camera movement) Notes
kling-v1 std / pro ✅ Only duration=5 ❌ ✅ Only duration=5 extend does not support negative_prompt or cfg_scale
kling-v1-6 std ❌ ❌ ❌ Multi-image-to-video and extend available in all modes
kling-v1-6 pro ✅ ❌ ❌
kling-v2-master — ❌ ❌ ❌ Single mode, only duration=5/10
kling-v2-1-master — ❌ ❌ ❌ Single mode, only duration=5/10
kling-v2-5-turbo std ❌ ❌ ❌
kling-v2-5-turbo pro ✅ ❌ ❌
kling-v2-6 std ❌ ❌ ❌
kling-v2-6 pro ✅ ✅ ❌ The only non-v3 model that also supports audio
kling-v3 std / pro ✅ ✅ ✅ duration range: 3–15 seconds
kling-v3 4k ✅ ✅ ❌ 4K mode is incompatible with camera movement
kling-v3-omni std / pro / 4k ✅ ✅ ❌
kling-o1 std / pro ✅ ❌ ❌ Only supports duration=5

Notes:

  • mode=4k is supported only by kling-v3 and kling-v3-omni, and is mutually exclusive with camera_control (camera movement).
  • end_image_url can only be used with start_image_url when action=image2video. Sending only end_image_url (without start_image_url) will be rejected.
  • kling-v3 / kling-v3-omni accept any integer duration from 3–15 seconds; kling-o1 only accepts 5; the remaining models only accept 5 or 10.
  • generate_audio defaults to false. Only kling-v3, kling-v3-omni, and kling-v2-6 (pro mode) support it.

Video Extension Feature

If you want to continue generating an already generated Kling video, you can set the action parameter to extend and enter the ID of the video to be continued. The video ID is obtained according to the basic usage instructions, as shown below:

You can then see that the video ID is:

"video_id": "030bb06d-98d4-4044-9042-0aa0822e8c8c"

Note that video_id here is the ID of the generated video. If you do not know how to generate a video, you can refer to the basic usage instructions above to generate one.

Next, we must fill in the prompt for the next extension step to customize the generated video, and can specify the following:

  • model: The model used to generate the video, mainly kling-v1, kling-v1-5, and kling-v1-6.
  • mode: The mode used to generate the video. Available values are standard mode std, fast mode pro, and native 4K mode 4k (supported only by kling-v3 and kling-v3-omni, and incompatible with camera movement control).
  • duration: The video duration for this generation task, mainly 5s and 10s.
  • start_image_url: The first-frame reference image URL that must be uploaded when selecting the image-to-video action image2video.
  • prompt: The prompt.

An example is filled in as follows:

After filling it in, the code is automatically generated as follows:

The corresponding Python code:

import requests

url = "https://api.acedata.cloud/kling/videos"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "action": "extend",
    "model": "kling-v1",
    "video_id": "030bb06d-98d4-4044-9042-0aa0822e8c8c",
    "prompt": "White ceramic coffee mug on glossy marble countertop with morning window light. Camera slowly rotates 360 degrees around the mug, pausing briefly at the handle.",
    "duration": 10
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)

Click Run, and you will get a result as follows:

{
  "success": true,
  "video_id": "bbc3b105-ac72-4de2-8390-0cb37dc7d41e",
  "video_url": "https://cdn.acedata.cloud/assets/examples/gemini/04a043bd-6b23-4b4e-945c-ce48158c3eee-3a89912507c7.mp4",
  "duration": "9.6",
  "state": "succeed",
  "task_id": "3ece87e6-3ee3-4f5e-bd70-5ae5eca89a23"
}

As can be seen, the result is consistent with the content above, which achieves the video extension functionality.

Omni All-in-One Reference (Video Editing / Reference Video / Multi-Image Reference)

kling-o1 and kling-v3-omni are two independent models, both of which support the “all-in-one reference” capability. In addition to text-to-video generation (action=text2video), reference images or videos can be supplied to enable multi-image reference, reference video, and direct editing of existing videos.

Core convention: Reference materials must be referenced in prompt as <<<image_1>>> or <<<video_1>>> (with numbering starting at 1), corresponding to their positions in image_list / video_list, for the model to apply them. If materials are supplied without being referenced in the prompt, they will be ignored.

Security note: The current API does not expose element_list. Kling Element Library IDs are not tenant-isolated. Until a tenant-isolated Element Management API is available, use image_list to provide subject reference images.

Omni requests do not support negative_prompt, cfg_scale, or camera_control, and cannot use mode=4k. When a reference video is included, generate_audio must be false.

Reference Video and Video Editing (video_list)

video_list is used to provide reference videos and is the most common use case for this capability. The array element fields are as follows:

  • video_url: Reference video URL; cannot be empty. A maximum of 1 MP4/MOV video, with a file size ≤200MB and a frame rate of 24–60fps. kling-o1 requires a duration of 3–10 seconds and a width and height of 700–2160px each; kling-v3-omni requires a duration of 3–15.5 seconds, a width and height of 700–4553px each, a total pixel count ≤8,294,400, and an aspect ratio of 0.4–2.
  • refer_type: Reference type; either base (default, base video to be edited, meaning “edit the video directly”; elements can be added, removed, or modified, and the composition, style, colors, weather, etc. can be changed) or feature (feature reference, referencing its style / camera movement / continuation into the next shot).
  • keep_original_sound: Whether to retain the original video audio; either yes (retain) or no (remove).

Note: When a reference video is present, generate_audio must be false. A video with refer_type=base cannot also have a first frame / last frame specified.

A CURL example for editing an existing video (changing the video to an anime style) is as follows:

curl -X POST 'https://api.acedata.cloud/kling/videos' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "action": "text2video",
  "model": "kling-o1",
  "mode": "std",
  "duration": 5,
  "prompt": "把 <<<video_1>>> 改成电影级动漫风格,保留原有的运动和构图",
  "video_list": [
    {
      "video_url": "https://cdn.acedata.cloud/your-reference-video.mp4",
      "refer_type": "base",
      "keep_original_sound": "no"
    }
  ]
}'

Multi-Image Reference (image_list)

image_list is used to provide reference images (elements / scenes / styles, etc.). The array element fields are as follows:

  • image_url: Reference image URL; cannot be empty. Requirements: .jpg/.jpeg/.png format; file size ≤10MB; shortest side ≥300px; aspect ratio 1:2.5 to 2.5:1.
  • type: Optional. If omitted, the image is treated as a reference image only; if first_frame / end_frame is supplied, it is used as the first frame / last frame respectively (equivalent to start_image_url / end_image_url).

When using them, reference them in prompt as <<<image_1>>>, <<<image_2>>>. Quantity limits: reference images ≤ 7 when no reference video is present; reference images ≤ 4 when a reference video is present. When supplying only a first / last frame, start_image_url / end_image_url can also be used directly, but the last frame must be used together with the first frame.

Note: If start_image_url / end_image_url and image_list are supplied together, the first / last frame will be placed before image_list, which may affect the numbering correspondence of <<<image_N>>>. It is recommended to choose one approach: when a first / last frame is needed, specify it using type directly in image_list, and do not mix it with start_image_url / end_image_url.

A CURL example for generating a video with multi-image reference:

curl -X POST 'https://api.acedata.cloud/kling/videos' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "action": "text2video",
  "model": "kling-o1",
  "mode": "std",
  "duration": 5,
  "prompt": "让 <<<image_1>>> 里的人物站在 <<<image_2>>> 的场景中,电影感光线",
  "image_list": [
    { "image_url": "https://cdn.acedata.cloud/subject.png" },
    { "image_url": "https://cdn.acedata.cloud/scene.png" }
  ]
}'

Asynchronous Callback

Since the Kling Videos Generation API takes a relatively long time to generate a video, approximately 1–2 minutes, the HTTP request would remain connected if the API did not respond for a long time, resulting in additional system resource consumption. Therefore, this API also supports asynchronous callbacks.

The overall process is as follows: when the client initiates a request, it additionally specifies a callback_url field. After the client initiates the API request, the API immediately returns a result containing a task_id field, which represents the current task ID. When the task is complete, the generated video result is sent as POST JSON to the callback_url specified by the client, and it also includes the task_id field, so the task results can be associated by ID.

Below, we will use an example to understand how to do this.

First, a Webhook callback is a service that can receive HTTP requests, and developers should replace it with the URL of their own HTTP server. For convenience in this demonstration, we use a public Webhook sample site, https://webhook.site/. Open the site to obtain a Webhook URL, as shown:

Copy this URL to use it as a Webhook. The example here is https://webhook.site/624b2c78-6dbd-4618-9d2b-b32eade6d8c3.

Next, we can set the callback_url field to the Webhook URL above and fill in the corresponding parameters. The details are shown in the figure:

Click Run, and you will immediately receive a result as follows:

{
  "task_id": "20068983-0cc9-4c6a-aeb6-9c6a3c668be0"
}

Wait a moment, and we can observe the generated video result at https://webhook.site/624b2c78-6dbd-4618-9d2b-b32eade6d8c3, as shown below:

The content is as follows:

{
    "success": true,
    "video_id": "030bb06d-98d4-4044-9042-0aa0822e8c8c",
    "video_url": "https://cdn.acedata.cloud/assets/examples/gemini/04a043bd-6b23-4b4e-945c-ce48158c3eee-3a89912507c7.mp4",
    "duration": "5.1",
    "state": "succeed",
    "task_id": "20068983-0cc9-4c6a-aeb6-9c6a3c668be0"
}

As you can see, the result contains a task_id field, while the other fields are similar to those above. This field can be used to associate tasks.

Error Handling

When calling the API, if an error occurs, the API will return the corresponding error code and message. For example:

  • 400 token_mismatched: Bad request, possibly due to missing or invalid parameters.
  • 400 api_not_implemented: Bad request, possibly due to missing or invalid parameters.
  • 401 invalid_token: Unauthorized, invalid or missing authorization token.
  • 429 too_many_requests: Too many requests, you have exceeded the rate limit.
  • 500 api_error: Internal server error, something went wrong on the server.

Error Response Example

{
  "success": false,
  "error": {
    "code": "api_error",
    "message": "fetch failed"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}

Conclusion

Through this document, you have learned how to use the Kling Videos Generation API to generate videos by providing a text prompt and a first-frame reference image. We hope this document helps you better integrate and use the API. If you have any questions, please feel free to contact our technical support team.

Kling 3.0 Turbo

model="kling-v3-turbo" supports text-to-video and first-frame image-to-video generation, with an integer duration of 3–15 seconds. mode="std" outputs 720p, and mode="pro" outputs 1080p. This model has native audio and does not provide an option to turn it off; omit generate_audio or set it to true. This model does not support a final frame, camera movement objects, separate negative prompts, or cfg_scale. Describe what you want to include or avoid directly in prompt.

Multi-Shot Video

kling-v3 and kling-v3-omni support multi_shot=true. shot_type="intelligence" automatically creates shots based on prompt; shot_type="customize" provides 1–6 shots through multi_prompt, each containing an index that increments consecutively starting from 1, a prompt of up to 512 characters, and an integer duration of at least 1 second. The sum of all shot durations must equal the total duration. Customized shots do not use the global prompt. Multi-shot videos are billed based on the selected model, video quality, audio configuration, and total duration.