Kling - Video Generation API documentation

更新时间:
复制 MD 格式

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.

Important

This document applies only to the China (Beijing) region. Use an API key from this region.

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 all belong to the same region. Cross-region calls will fail.

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.

Note
  • After the task is created, use the returned task_id to query the result. The task_id is valid for 24 hours. Do not create duplicate tasks. Instead, use polling to retrieve the result.

  • For guidance for beginners, see Call APIs with Postman or cURL.

Request parameters

Text-to-video

Supported models: kling/kling-v3-omni-video-generation and kling/kling-v3-video-generation.

# The URL below is for the China (Beijing) region. Replace {WorkspaceId} with your actual workspace ID.
curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "kling/kling-v3-video-generation",
    "input": {
        "prompt": "A kitten runs under the moonlight"
    },
    "parameters": {
        "mode": "std",
        "aspect_ratio": "16:9",
        "duration": 5,
        "audio": false,
        "watermark": true
    }
}'

Text-to-video (custom shot division)

Supported models: kling/kling-v3-omni-video-generation and kling/kling-v3-video-generation.

# The URL below is for the China (Beijing) region. Replace {WorkspaceId} with your actual workspace ID.
curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "kling/kling-v3-video-generation",
    "input": {
        "prompt": "",
        "multi_shot": true,
        "shot_type": "customize",
        "multi_prompt": [
            {
                "index": 1,
                "prompt": "Wuling Town is smaller than it appears on the map. Mountain mist, like cotton fluff, blocks the street entrance. Behind the post office, there are indeed three locust trees. The soil by the roots of the third tree has been disturbed.",
                "duration": 5
            },
            {
                "index": 2,
                "prompt": "Lin Che squats down and digs up an iron box. Inside, besides a rusty key, is an old cassette tape. The tape recorder was borrowed from the post office. When the play button is pressed, his father's voice emerges from the static: 'If you are hearing this, it means you have walked the path I once walked.'",
                "duration": 5
            }
        ],
        "media": [],
        "element_list": []
    },
    "parameters": {
        "mode": "pro",
        "duration": 10,
        "audio": true,
        "aspect_ratio": "9:16",
        "watermark": true
    }
}'

Image-to-video (from a first frame)

Supported models: kling/kling-v3-omni-video-generation and kling/kling-v3-video-generation.

# The URL below is for the China (Beijing) region. Replace {WorkspaceId} with your actual workspace ID.
curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "kling/kling-v3-omni-video-generation",
    "input": {
        "prompt": "Animate the person in the picture, with their hair blowing in a gentle breeze",
        "media": [
            {
                "type": "first_frame",
                "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260121/zlpocv/wan-i2v-haigui.webp"
            }
        ]
    },
    "parameters": {
        "mode": "std",
        "duration": 5,
        "audio": false,
        "watermark": true
    }
}'

Image-to-video (from first and last frames)

Supported models: kling/kling-v3-omni-video-generation and kling/kling-v3-video-generation.

# The URL below is for the China (Beijing) region. Replace {WorkspaceId} with your actual workspace ID.
curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "kling/kling-v3-omni-video-generation",
    "input": {
        "prompt": "Realistic style, a small black cat looks up at the sky curiously. The camera starts at eye level, gradually rises, and ends with a top-down shot of its curious eyes.",
        "media": [
            {
                "type": "first_frame",
                "url": "https://wanx.alicdn.com/material/20250318/first_frame.png"
            },
          {
                "type": "last_frame",
                "url": "https://wanx.alicdn.com/material/20250318/last_frame.png"
            }
        ]
    },
    "parameters": {
        "mode": "std",
        "duration": 5,
        "audio": false,
        "watermark": true
    }
}'

Video editing

Supported model: kling/kling-v3-omni-video-generation.

# The URL below is for the China (Beijing) region. Replace {WorkspaceId} with your actual workspace ID.
curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
    -H 'X-DashScope-Async: enable' \
    -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "model": "kling/kling-v3-omni-video-generation",
    "input": {
        "prompt": "<<<element_1>>> background, <<<image_2>>> and <<<image_1>>> shake hands and talk, <<<video_1>>> a detective in a black trench coat stands on the roof of an apartment building, observing the street with binoculars",
        "multi_shot": false,
        "shot_type": "intelligence",
        "multi_prompt": [],
        "media": [
            {
                "url": "https://p2-kling.klingai.com/kcdn/cdn-kcdn112452/kling-qa-test/lip_sync_5s.mp4",
                "type": "base",
                "keep_original_sound": "yes"
            },
            {
                "type": "refer",
                "url": "https://p2-kling.klingai.com/kcdn/cdn-kcdn112452/kling-qa-test/zem_test/yangmi01.jpg"
            },
            {
                "type": "refer",
                "url": "https://p2-kling.klingai.com/kcdn/cdn-kcdn112452/kling-qa-test/human_2.JPG"
            }
        ],
        "element_list": [
            {
                "element_id": 171
            }
        ]
    },
    "parameters": {
        "mode": "pro",
        "duration": 10,
        "audio": false,
        "aspect_ratio": "1:1",
        "watermark": true
    }
}'
Headers

Content-Type string (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)

Enables asynchronous processing. HTTP requests support only asynchronous calls. Must be enable.

Important

If this request header is missing, the error "current user api does not support synchronous calls" is returned.

Request Body

model string (Required)

The model name.

Valid values:

  • kling/kling-v3-omni-video-generation

  • kling/kling-v3-video-generation

input 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.

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.

Logic:

  • When shot_type=intelligence, this parameter is required.

  • When shot_type=customize, this parameter is ignored. Use multi_prompt instead.

The Omni model can use the prompt with entities, images, and videos to achieve various capabilities:

  • Supported model: kling/kling-v3-omni-video-generation.

  • Applicable task: reference-to-video.

  • Reference format: Use the <<<>>> format to specify an entity, image, or video, such as <<<element_1>>>, <<<image_1>>>, or <<<video_1>>>.

  • Reference order: Define the reference order in the prompt according to the order in the media array.

  • Example: A <<<element_1>>> runs under the moonlight.

media 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-video-generation

Only the following media asset combinations are supported. Invalid combinations will cause an error.

  • Image-to-video from a first frame: first_frame.

    • Quantity limit: 1 first frame.

  • Image-to-video from first and last frames: first_frame+last_frame.

    • Quantity limit: 1 first frame and 1 last frame.

kling/kling-v3-omni-video-generation

Only the following media asset combinations are supported. Invalid combinations will cause an error.

  • Image-to-video from a first frame: first_frame.

    • Image quantity: 1 first frame.

  • Image-to-video from first and last frames: first_frame+last_frame.

    • Image quantity: 1 first frame and 1 last frame.

  • Reference-to-video: The following media combinations are supported.

    • If only feature is passed: 1 video must be passed.

    • If only refer is passed: The sum of reference images and multi-image entities (the length of the element_list array) cannot exceed 7.

    • If feature+refer is passed: 1 video must be passed, and the sum of reference images and multi-image entities (the length of the element_list array) cannot exceed 4.

    • If feature+first_frame is passed: 1 video and 1 first frame must be passed.

  • Video editing: The following media combinations are supported.

    • If only base is passed: 1 video must be passed.

    • If base+refer is passed: 1 video must be passed, and the sum of reference images and multi-image entities (the length of the element_list array) cannot exceed 4.

Properties

type string (Required)

The type of media asset. The valid values depend on the selected model:

kling/kling-v3-video-generation

Valid values:

  • first_frame: The first frame image.

  • last_frame: The last frame image.

For restrictions on combinations of different media assets, see "Asset combination rules" under the media parameter.

kling/kling-v3-omni-video-generation

Valid values:

  • first_frame: The first frame image.

  • last_frame: The last frame image.

  • refer: The reference image.

  • base: The video to be edited.

  • feature: The feature reference video.

For restrictions on combinations of different media assets, see "Asset combination rules" under the media parameter.

url string (Required)

The URL of the media asset. Assets include images and videos.

Pass an image (type=first_frame, last_frame, or refer)

The image URL.

  • HTTP and HTTPS protocols are supported.

  • Example: https://xxx/xxx.png.

Image restrictions:

  • Format: JPEG, JPG, or PNG (alpha channels are not supported).

  • Resolution: The width and height must be between 300 and 8000 pixels.

  • Aspect ratio: Between 1:2.5 and 2.5:1.

  • File size: No more than 10 MB.

Pass a video (type=base or feature)

The URL of the video file.

  • HTTP and HTTPS protocols are supported.

  • Example: https://xxx/xxx.mp4.

Video restrictions:

  • Format: MP4 or MOV.

  • Duration: 3 to 10 seconds.

  • Resolution: The width and height must be between 720 and 2160 pixels.

  • File size: No more than 200 MB.

  • Frame rate: 24 to 60 fps.

keep_original_sound 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.

  • no: Default value. The original sound is not kept.

  • yes: The original sound is kept.

multi_shot boolean (Optional)

Specifies whether to enable multi-shot generation.

  • false: Default value. Multi-shot generation is disabled.

  • true: Multi-shot generation is enabled.

shot_type string (Conditionally required)

Required when multi_shot=true. The type of multi-shot mode.

  • intelligence: Intelligent shot division. The model automatically plans the shots.

  • customize: Custom mode. You can customize the prompt and duration for each segment.

multi_prompt array (Conditionally required)

Required when shot_type=customize. A list of segments for the custom multi-shot mode.

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.

The value must be an integer between 1 and parameters.duration.

element_list array (Optional)

A list of entities to be included in the video.

Properties

element_id integer (Conditionally required)

Required when passing element_list. It represents the entity ID. Retrieve the entity ID from the Kling - Entity ID List.

Entity count limit (element_list array length limit):

  • Image-to-video from a first frame: Supports up to 3 entities.

  • Image-to-video from first and last frames: Supports up to 3 entities.

  • Reference-to-video (type=refer): The sum of reference images and multi-image entities cannot exceed 7.

  • Reference-to-video (type=feature+refer): The sum of reference images and multi-image entities cannot exceed 4.

parameters 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.

  • pro: Default value. Professional mode. The output video resolution is 1080p.

  • std: Standard mode. The output video resolution is 720p.

  • 4k: 4K mode. The output video resolution is 4K.

aspect_ratio string (Conditionally required)

The aspect ratio of the generated video.

Valid values:

  • 16:9: Default value.

  • 9:16

  • 1:1

This must be specified in the following scenarios:

  • Text-to-video: Must be set.

  • Reference-to-video (type=feature, type=feature+refer, type=refer): Must be set.

You do not need to set this in other scenarios

  • Image-to-video from a first frame: The aspect ratio of the first frame is used. You do not need to specify this.

  • Image-to-video from first and last frames: The aspect ratio of the first frame is used. You do not need to specify this.

  • Reference-to-video (type=feature+first_frame): The aspect ratio of the first frame is used. You do not need to specify this.

  • Video editing: The aspect ratio of the input video is used. You do not need to specify this.

duration integer (Optional)

Important

The duration directly affects the cost. Billing is based on seconds. The longer the duration, the higher the cost. Go to the Model Studio console to view prices.

The duration of the generated video, in seconds.

  • kling/kling-v3-omni-video-generation: The value must be an integer between 3 and 15. The default value is 5.

    • Note: When a reference video is passed, the behavior of this parameter varies depending on the type:

      • type=feature: The value must be an integer between 3 and 10. The default value is 5.

      • type=base: The output video duration is the same as the input video duration. This parameter is ignored. Billing is based on the input video duration, rounded to the nearest integer.

  • kling/kling-v3-video-generation: The value must be an integer between 3 and 15. The default value is 5.

Example: 5.

audio boolean (Optional)

Important

Audio directly affects the cost. Go to the Model Studio console to view prices.

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.

  • false: Default value. A silent video is output.

  • true: A video with sound is output.

Note: When a video is passed in (type=base or feature), audio can only be set to false.

watermark boolean (Optional)

Specifies whether to simultaneously generate a watermarked version of the video. The watermark is located in the lower-right corner and displays "Kling AI". When set to true, the response will additionally return the watermark_video_url field.

  • false: Default value. No watermarked video is generated.

  • true: A watermarked video is generated simultaneously.

Response parameters

Successful response

Save the task_id to query the task status and result.

{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}

Error response

Task creation failed. See Error codes.

{
    "code": "InvalidApiKey",
    "message": "Invalid API-key provided.",
    "request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}

output object

Task output information.

Properties

task_id string

The task ID. Valid for queries for 24 hours.

task_status string

The status of the task.

Enumeration values

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN: The task does not exist or its status is unknown.

request_id string

Unique request identifier for tracing and troubleshooting.

code string

Error code. Returned only for failed requests. See Error codes.

message string

Detailed error message. Returned only for failed requests. See Error codes.

Step 2: Query the result by task ID

Beijing region: GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}

Note
  • 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 parameters

Query task result

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.

curl -X GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

Headers

Authorization string (Required)

Authenticates the request with a Model Studio API key. Example: Bearer sk-xxxx.

URL path parameters

task_id string (Required)

The ID of the task.

Response parameters

Task successful

{
    "request_id": "340f0d7d-bf7e-4c8f-9c03-xxxxxx",
    "output": {
        "task_id": "24f5c51e-d67b-44dc-9acb-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-03-27 21:30:32.575",
        "scheduled_time": "2026-03-27 21:30:32.603",
        "end_time": "2026-03-27 21:31:09.177",
        "video_url": "https://v4-fdl.kechuangai.com/ksc2/xxx.mp4?xxxx",
        "watermark_video_url": "https://v2-fdl.kechuangai.com/ksc2/xxx.mp4?xxxx"
    },
    "usage": {
        "duration": 5,
        "size": "1280*720",
        "fps": 24,
        "video_count": 1,
        "audio": false,
        "SR": "720"
    }
}

Task failed

When a task fails, task_status is FAILED with an error code and message. See Error codes.

{
    "request_id": "e5d70b02-ebd3-98ce-9fe8-759d7d7b107d",
    "output": {
        "task_id": "86ecf553-d340-4e21-af6e-a0c6a421c010",
        "task_status": "FAILED",
        "code": "InvalidParameter",
        "message": "The parameter is invalid xxxxxx"
    }
}

Task query expired

The task_id is valid for 24 hours. After this period, queries return the following error.

{
    "request_id": "a4de7c32-7057-9f82-8581-xxxxxx",
    "output": {
        "task_id": "502a00b1-19d9-4839-a82f-xxxxxx",
        "task_status": "UNKNOWN"
    }
}

output object

Task output information.

Properties

task_id string

The task ID. Valid for queries for 24 hours.

task_status string

The status of the task.

Enumeration values

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN: The task does not exist or its status is unknown.

State transitions during polling:

  • PENDING → RUNNING → SUCCEEDED or FAILED.

  • The initial query status is usually PENDING or RUNNING.

  • When the status changes to SUCCEEDED, the response contains the generated video URL.

  • If the status is FAILED, check the error message and retry the task.

submit_time string

The time when the task was submitted. format is YYYY-MM-DD HH:mm:ss.SSS.

scheduled_time string

The time when the task was executed. format is YYYY-MM-DD HH:mm:ss.SSS.

end_time string

The time when the task was completed. format is YYYY-MM-DD HH:mm:ss.SSS.

video_url string

The video URL. This is returned only when task_status is SUCCEEDED.

The video is in MP4 format (H.264 encoding). The video link is valid for 30 days, but do not rely on it for long-term storage. Download the video promptly.

watermark_video_url string

The URL of the video with a watermark. This is returned only when task_status is SUCCEEDED.

The video is in MP4 format (H.264 encoding). The video link is valid for 30 days, but do not rely on it for long-term storage. Download the video promptly.

orig_prompt string

The original input prompt, corresponding to the request parameter prompt.

code string

Error code. Returned only for failed requests. See Error codes.

message string

Detailed error message. Returned only for failed requests. See Error codes.

usage object

Statistics for the output information. Only successful results are counted.

Properties

duration integer

The total duration of the generated video, used for billing.

size string

The resolution of the generated video. Example: 1280×720.

fps integer

The frame rate of the generated video. Example: 24.

SR string

The resolution tier of the generated video. Example: 720.

audio boolean

Indicates whether the generated video has sound. Example: false.

video_count integer

The number of generated videos. This is fixed at 1.

request_id string

Unique request identifier for tracing and troubleshooting.

Error codes

If the model call fails and returns an error message, see Error codes for resolution.