The Kling video generation model supports text-to-video, image-to-video from a first frame, image-to-video from first and last frames, reference-to-video, and video editing .
Activate the service
Go to the Alibaba Cloud Model Studio console, search for "kling", locate the Kling AI model card, click Activate Now, and then confirm activation and authorization in the pop-up window.
Scope
To ensure successful calls, make sure that the model, Endpoint URL, and API Key belong to the same region. Cross-region calls will fail.
- Select Model: Confirm the region of the model.
- Select URL: Select the Endpoint URL of the corresponding region. HTTP URLs are supported.
- Configure API Key: Select a region and obtain and configure an API Key, then configure the API Key in environment variables.
Model overview
| Model | Capabilities | Input Modality | Output video specifications |
|---|---|---|---|
| kling/kling-v3-turbo-video-generation | T2V; I2V based on first frame | Text, Image | Resolution modes: std (720P), pro (1080P); aspect ratios: 16:9, 9:16, 1:1; video duration: 3-15 s; video format: MP4 |
| kling/kling-v3-video-generation | T2V; I2V based on first frame; I2V based on first and last frames | Text, Image | Resolution modes: std (720P), pro (1080P); aspect ratios: 16:9, 9:16, 1:1; video duration: 3-15 s; video format: MP4 |
| kling/kling-v3-omni-video-generation | T2V; I2V based on first frame; I2V based on first and last frames; reference-to-video; Video Editing | Text, Image, Video | Resolution modes: std (720P), pro (1080P), 4k; aspect ratios: 16:9, 9:16, 1:1; video duration: 3-15 s; video format: MP4 |
| Model | Capabilities | Input Modality | Output video specifications |
|---|---|---|---|
| kling/kling-v4-video-generation | T2V, keyframe-to-video (first, intermediate, and last frames can be combined freely) | Text, frame images | std (720P), pro (1080P); 21:9, 16:9, 9:16, 1:1; 3-30 s; MP4 (H.264) |
| kling/kling-v4-omni-reference-video-generation | T2V, keyframe-to-video, reference-to-video, Video Editing | Text, frame images, reference images, videos, subjects | std (720P), pro (1080P); 21:9, 16:9, 9:16, 1:1; 3-30 s; MP4 (H.264) |
4k mode. For detailed limits on models and media assets, see the request parameters below.
HTTP invocation
Video generation tasks take a long time—typically 1 to 5 minutes—so the API uses asynchronous invocation. The process involves two main steps: Create a task → Poll for the result. The steps are as follows:
Step 1: Create a task and get the task ID
Beijing region: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
Replace {WorkspaceId} with your actual workspace ID.
- After the task is created, use the
task_idreturned by the API to query the result. task_id is valid for 24 hours. Do not create the task repeatedly; just use polling to obtain the result. - For a beginner's guide, see Postman.
Request parametersHeadersContent-Typestring (Required)The content type of the request. Must be application/json.Authorization string (Required)Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.X-DashScope-Async string (Required)Asynchronous processing configuration parameter. HTTP requests support asynchronous mode only and must be set to enable.Request Bodymodelstring (Required)The model name.Valid values:
object (Required)Basic input information, such as prompts and media assets.
Properties prompt string (Conditionally required)The text prompt describes the desired elements and visual features in the generated video.For 3.0 models, Chinese and English are supported. Each Chinese character or letter counts as one character. The maximum length is 2,500 characters. Exceeding the limit will result in an error. Rules:
prompt, including any shot-division requirements:
prompt:
string (Optional)For 3.0 models, the negative prompt describes what you do not want to appear in the result. Maximum 2,500 characters.
array (Optional)You do not need to specify this parameter for text-to-video tasks.A list of media assets used to specify image or video materials.Different models support different combinations of media assets:
Asset combination rules
kling/kling-v3-turbo-video-generation Only the following media asset combinations are supported. Invalid combinations will cause an error.
kling/kling-v3-video-generation Only the following media asset combinations are supported. Invalid combinations will cause an error.
kling/kling-v3-omni-video-generation Only the following media asset combinations are supported. Invalid combinations will cause an error.
kling/kling-v4-video-generation Supports first_frame, middle_frame, and last_frame in any combination, including only a last or intermediate frame. Omit media for text-to-video. Pass no more than 1 first frame, 1 last frame, and 10 frame images in total. refer, feature, base, and element_list are not supported.
kling/kling-v4-omni-reference-video-generation Supports frame images, reference images ( refer), feature reference videos (feature), videos to be edited (base), and entities. The asset-exclusivity rules for 3.0 do not apply: a last frame does not require a first frame, and base can be combined with frame images and feature.
Properties type string (Required)The type of media asset. The valid values depend on the selected model:
kling/kling-v3-turbo-video-generation Valid values:
last_frame is not supported. For restrictions on combinations of different media assets, see "Asset combination rules" under the media parameter.
kling/kling-v3-video-generation Valid values:
media parameter.
kling/kling-v3-omni-video-generation Valid values:
media parameter.
kling/kling-v4-video-generation
kling/kling-v4-omni-reference-video-generation
string (Required)The URL of the media asset. Assets include images and videos.
Pass an image (type=first_frame, middle_frame, last_frame, or refer) The image URL.
Pass a video (type=base or feature) The URL of the video file.
feature and base):
string (Optional)Supported model: kling/kling-v3-omni-video-generation.Effective condition: This parameter takes effect only when a video is passed (type=base or feature).Specifies whether to keep the original video's sound.
yes causes a parameter error; passing no or omitting the field does not affect the request.boolean (Optional)For 3.0 models, specifies whether to enable multi-shot generation.
string (Conditionally required)For 3.0 models, required when multi_shot=true. The type of multi-shot mode.
shot_type=customize causes a parameter error. Describe shot-division requirements in prompt instead.multi_prompt array (Conditionally required)For 3.0 models, required when shot_type=customize. A list of segments for the custom multi-shot mode. Passing this field to a 4.0 model causes a parameter error.
Properties index integer (Required)The index of the shot segment. The number of shots can be from 1 to 6. The index starts from 1.prompt string (Required)The prompt for the corresponding segment. Chinese and English are supported. The maximum length is 512 characters. Excess characters are automatically truncated.duration integer (Required)The duration of the corresponding segment, in seconds.An integer in the range [1, parameters.duration].array (Optional)A list of entities to be included in the video.Note: kling/kling-v3-turbo-video-generation and kling/kling-v4-video-generation do not support entities. Do not pass this field to these models.
Properties element_id integer (Conditionally required)Required when passing element_list. It represents the entity ID. Retrieve the entity ID from the official Kling entity library.Entity count limits for 3.0 models (element_list array length):
array (Optional; 4.0 models only)A list of up to 3 voices. Voices already bound to entities do not count toward this limit. Each item requires a voice_id from the official voice library; the custom voice API is not supported. Reference voices in prompt with <<<voice_1>>>、<<<voice_2>>>, and so on, using the order in voice_list.object (Optional)Video generation parameters. You can set the generation mode, aspect ratio, video duration, and whether to generate audio.
Properties mode string (Optional)The video generation mode.
kling/kling-v3-turbo-video-generation and both 4.0 models support only std (720p) and pro (1080p), not 4k. The default for 4.0 is pro.aspect_ratio string (Conditionally required for 3.0; optional for 4.0)The aspect ratio of the generated video.Valid values for 3.0 models:
Other 3.0 scenarios do not require this field
21:9, 16:9, 9:16, or 1:1:
integer (Optional)The duration of the generated video, in seconds.
boolean (Optional)For 3.0 models, specifies whether to generate a video with sound. If enabled, the model automatically generates matching background music or sound effects based on the video content.
boolean (Optional)Specifies whether to also generate a watermarked video. For 3.0, the watermark appears in the lower-right corner and displays "Kling AI". For both 3.0 and 4.0, setting this field to true adds watermark_video_url to the response.
| The existing 3.0 examples use model-specific parameters. Do not use them with 4.0 by changing only the model ID. For 4.0, see the last two examples and follow the asset and parameter rules above.
Supported models: kling/kling-v3-turbo-video-generation, kling/kling-v3-video-generation, and kling/kling-v3-omni-video-generation. |
Response parametersoutputobjectTask output information.
Properties task_id stringThe task ID. Valid for queries for 24 hours.task_status stringThe status of the task.
Enumeration values
stringUnique request identifier for tracing and troubleshooting.codestringError code. Returned only for failed requests. See Error codes.messagestringDetailed error message. Returned only for failed requests. See Error codes. |
Save the task_id, which is used to query the task status and results. |
Step 2: Query the result by task ID
Beijing region: GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
- Polling recommendation: Video generation takes several minutes. Use a polling mechanism with a reasonable query interval (such as 15 seconds) to retrieve the result.
- Task status flow: PENDING (In queue) → RUNNING (Processing) → SUCCEEDED (Successful) / FAILED (Failed).
- task_id validity: 24 hours. After this period, you cannot query the result, and the API returns the task status as
UNKNOWN. - RPS limit: The default records per second (RPS) for the query API is 20. For higher-frequency queries or event notifications, configure an asynchronous task callback.
- More operations: To perform operations such as batch queries or canceling tasks, see Manage asynchronous tasks.
Request parametersHeadersAuthorizationstring (Required)Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.URL path parameterstask_idstring (Required)The ID of the task. |
Replace {task_id} with the task_id value returned by the previous API call. The task_id is valid for queries for 24 hours, Replace {WorkspaceId} with your actual workspace ID. |
Response parametersoutputobjectTask output information.
Properties task_id stringThe task ID. Valid for queries for 24 hours.task_status stringThe status of the task.
Enumeration values
stringThe time when the task was submitted. format is YYYY-MM-DD HH:mm:ss.SSS.scheduled_time stringThe time when the task was executed. format is YYYY-MM-DD HH:mm:ss.SSS.end_time stringThe time when the task was completed. format is YYYY-MM-DD HH:mm:ss.SSS.video_urlstringThe video URL. This is returned only when task_status is SUCCEEDED.The video is in MP4 format (H.264 encoding) and the link is valid for 30 days. Do not rely on it for long-term storage; download it promptly.watermark_video_urlstringThe URL of the video with a watermark. Returned only when task_status is SUCCEEDED and watermarking is enabled.The video is in MP4 format (H.264 encoding) and the link is valid for 30 days. Do not rely on it for long-term storage; download it promptly.orig_prompt stringThe original input prompt, corresponding to the request parameter prompt.codestringError code. Returned only for failed requests. See Error codes.messagestringDetailed error message. Returned only for failed requests. See Error codes.objectStatistics for the output information. Only successful results are counted.
Properties duration numberThe billable duration in seconds. This equals the generated video duration when there is no video input. For 3.0 Omni video editing with base, billing uses the input video duration rounded to the nearest integer. For 4.0 models with video input, it equals max(total input video duration, generated video duration) + generated video duration.input_video_duration numberFor 4.0 models, the total input video duration in seconds, rounded to two decimal places. This includes feature reference videos, videos to edit, and video entities. The value is 0.00 when there is no video input.output_video_duration numberFor 4.0 models, the generated video duration in seconds, rounded to two decimal places.reference_type stringFor 4.0 models with a feature reference video, video to edit, or video entity, this field is video. It is omitted when there is no video input.size stringThe resolution of the generated video. Example: 1280×720.fps integerThe frame rate of the generated video. Example: 24.SR stringThe resolution tier of the generated video. Example value: 720. When mode=4k, 4k is returned; kling/kling-v3-turbo-video-generation only returns 720 or 1080.audio booleanIndicates whether the generated video has sound. Example: false. This is always true for kling/kling-v3-turbo-video-generation and both 4.0 models.video_count integerThe number of generated videos. This is fixed at 1.stringUnique request identifier for tracing and troubleshooting. |
|