Kling - Video Generation API documentation

Updated at:

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 .

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

Model overview

ModelCapabilitiesInput ModalityOutput video specifications
kling/kling-v3-turbo-video-generationT2V; I2V based on first frameText, ImageResolution 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-generationT2V; I2V based on first frame; I2V based on first and last framesText, ImageResolution 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-generationT2V; I2V based on first frame; I2V based on first and last frames; reference-to-video; Video EditingText, Image, VideoResolution modes: std (720P), pro (1080P), 4k; aspect ratios: 16:9, 9:16, 1:1; video duration: 3-15 s; video format: MP4

The following two Kling 4.0 models are available only in the China (Beijing) region. They use the same Model Studio asynchronous call process but support different media assets:

ModelCapabilitiesInput ModalityOutput video specifications
kling/kling-v4-video-generationT2V, keyframe-to-video (first, intermediate, and last frames can be combined freely)Text, frame imagesstd (720P), pro (1080P); 21:9, 16:9, 9:16, 1:1; 3-30 s; MP4 (H.264)
kling/kling-v4-omni-reference-video-generationT2V, keyframe-to-video, reference-to-video, Video EditingText, frame images, reference images, videos, subjectsstd (720P), pro (1080P); 21:9, 16:9, 9:16, 1:1; 3-30 s; MP4 (H.264)

Kling 4.0 always generates videos with audio and does not support the 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.

Note

  • After the task is created, use the task_id returned 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.

Request parameters

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)

Asynchronous processing configuration parameter. HTTP requests support asynchronous mode only and must be set to enable.

ImportantIf 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-turbo-video-generation
  • kling/kling-v3-video-generation
  • kling/kling-v3-omni-video-generation
  • kling/kling-v4-video-generation
  • kling/kling-v4-omni-reference-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.

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:

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

For 4.0 models, describe both desired and unwanted content in prompt, including any shot-division requirements:

  • kling/kling-v4-video-generation: Required for text-to-video; optional when frame images are provided.
  • kling/kling-v4-omni-reference-video-generation: Required.
  • Maximum length: 26,000 English characters or 11,000 non-English characters. For mixed input, the number of English characters ÷ 26,000 + the number of non-English characters ÷ 11,000 must be no greater than 1.

Omni models can reference entities, images, and videos in prompt:

  • Supported models: kling/kling-v3-omni-video-generation and kling/kling-v4-omni-reference-video-generation. This usage applies to reference-to-video with the 3.0 model.
  • Reference format: Use markers such as <<<element_1>>>、<<<image_1>>>、<<<video_1>>>. Kling 4.0 also supports <<<voice_1>>> for a voice in voice_list.
  • Reference order: In 4.0, number images and videos separately in their order of appearance within media; number entities and voices in the order of element_list and voice_list, respectively. In 3.0, use the order in media for image and video references.
  • Example: A <<<element_1>>> runs under the moonlight.

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

  • kling/kling-v3-turbo-video-generation does not support a separate negative prompt. This field has no effect (include negative descriptions in prompt instead).
  • Supported models: kling/kling-v3-video-generation and kling/kling-v3-omni-video-generation.
  • This field has no effect on 4.0 models. Include negative descriptions in prompt instead.

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-turbo-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: Exactly 1 first frame. last_frame is not supported.

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.

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.

  • Up to 10 images (first, intermediate, and last frames plus reference images), including no more than 1 first frame and 1 last frame.
  • Up to 5 videos (feature and base), including no more than 1 base video. The combined number of video-type entities and input videos cannot exceed 5.
  • Up to 7 entities, including no more than 3 video-type entities; up to 3 voices, excluding those already bound to entities.
  • Up to 15 assets in total across images, videos, entities, and voices. See url below for asset specifications.

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:

  • first_frame: The first frame image.

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:

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

kling/kling-v4-video-generation

  • first_frame: First-frame image.
  • middle_frame: Intermediate-frame image; multiple are supported.
  • last_frame: Last-frame image.

kling/kling-v4-omni-reference-video-generation

  • first_frame, middle_frame, last_frame: First, intermediate, and last-frame images.
  • refer: Reference image.
  • feature: Feature reference video.
  • base: Video to be edited.

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

  • HTTP and HTTPS protocols are supported.
  • Example: https://example.com/image.png.

Image restrictions for 3.0 models:

  • Format: JPEG, JPG, PNG (transparent channels are not supported).
  • Resolution: width and height range from [300, 8000] pixels.
  • Aspect ratio: 1:2.5 ~ 2.5:1.
  • File size: no more than 10 MB.

Image restrictions for 4.0 models:

  • Format: JPG, JPEG, or PNG.
  • Resolution: Both width and height must be at least 300 pixels.
  • Aspect ratio: Between 2:5 and 5:2.
  • File size: No more than 30 MB.

Pass a video (type=base or feature)

The URL of the video file.

  • HTTP and HTTPS protocols are supported.
  • Example: https://example.com/video.mp4.

Video restrictions for the 3.0 Omni model:

  • Format: mp4, mov.
  • File size: no more than 200 MB.
  • Duration: 3 to 15.5 s.
  • Resolution: width and height range from [700, 4553] pixels, and the total pixel area must not exceed 8294400.
  • Aspect ratio: 0.4 to 2.
  • Frame rate: 24 to 60 fps.

Video restrictions for the 4.0 Omni model (feature and base):

  • Format: MP4 or MOV; up to 300 MB per file.
  • Each video and the combined duration of all input videos must be between 3 and 30 seconds. The combined duration includes video-type entities.
  • Width and height must each be between 700 and 4553 pixels; total pixel area cannot exceed 8,294,400. The aspect ratio must be between 2:5 and 5:2, and the frame rate must be between 24 and 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.

The 4.0 Omni model does not preserve the original sound of input videos. Passing yes causes a parameter error; passing no or omitting the field does not affect the request.

multi_shot boolean (Optional)

For 3.0 models, specifies whether to enable multi-shot generation.

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

Note:

  • For Kling 3.0, the video feature reference (feature) scenario supports multi-shot (shot_type only supports intelligence).
  • For Kling 3.0, the video editing (base) scenario does not support multi-shot.
  • Kling 4.0 uses intelligent shot splitting by default; you do not need to set this field. Any multi_shot value passed in has no effect. Describe shot requirements directly in the prompt.

shot_type string (Conditionally required)

For 3.0 models, 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.

Kling 4.0 does not use this field. Passing 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].

element_list 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):

  • 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.
  • Video input scenario (omni model): Supports video-type entities, up to 1. After referencing a video-type entity, you cannot pass reference images or image-type entities.

The 4.0 Omni model supports up to 7 entities, including up to 3 video-type entities. The combined number of video-type entities and input videos cannot exceed 5; the duration of video-type entities counts toward the total input video duration. The total across images, videos, entities, and voices cannot exceed 15. Entity IDs must come from the official entity library. The entity creation API is not supported.

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

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 (only for 3.0 models that support this 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:

  • 16:9: Default value.
  • 9:16
  • 1:1

Required for these 3.0 scenarios:

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

Other 3.0 scenarios do not require this field

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

For 4.0, choose from 21:9, 16:9, 9:16, or 1:1:

  • kling/kling-v4-video-generation: The field takes effect for text-to-video. If omitted, the model uses the ratio described in the prompt, or 16:9 if none is specified. When frame images are supplied, this field has no effect: the ratio follows the first frame, first intermediate frame, or last frame, in that order.
  • kling/kling-v4-omni-reference-video-generation: You can specify a ratio. If omitted, the model uses the ratio described in the prompt; otherwise, it follows the video to be edited, first frame, first intermediate frame, or last frame, in that order. If none of these is available, it uses 16:9.

duration integer (Optional)

ImportantFor 3.0 models, billing is based on the generated video duration. For 4.0 models, the billable duration in seconds equals the generated video duration when there is no video input. With video input, it equals max(total input video duration, generated video duration) + generated video duration. See Model pricing for unit prices.

The duration of the generated video, in seconds.

  • kling/kling-v3-turbo-video-generation: an integer in the range [3, 15], with a default value of 5.

  • kling/kling-v3-video-generation: an integer in the range [3, 15], with a default value of 5.

  • kling/kling-v3-omni-video-generation: an integer in the range [3, 15], with a default value of 5.

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

      • type=feature: an integer in the range [3, 10], with a default value of 5.
      • type=base: the output video duration is the same as the input video duration, and this parameter is invalid. Billing is measured by the input video duration, rounded to the nearest integer.
  • Both 4.0 models: An integer from 3 to 30. If omitted, the model first follows a duration specified in the prompt. If none is specified and the Omni model receives a video to be edited, it uses that video's duration; otherwise, the default is 10 seconds.

Example: 5.

audio boolean (Optional)

ImportantThe audio option for 3.0 models affects cost. Check the applicable model's price in the Model Studio console. Kling 4.0 always generates video with sound.

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.

  • false: Default value. A silent video is output.
  • true: A video with sound is output.

Notes:

  • When a video is passed to the 3.0 Omni model (type=base or feature), audio can only be set to false.
  • kling/kling-v3-turbo-video-generation always generates video with audio. This field has no effect (audio is always generated).
  • Both 4.0 models always generate video with sound. Any audio value has no effect; sound cannot be disabled.

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

  • false: Default value. No watermarked video is generated.
  • true: A watermarked video is generated simultaneously.

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.

Text-to-video

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

# 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间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-turbo-video-generation",
    "input": {
        "prompt": "一只小猫在月光下奔跑"
    },
    "parameters": {
        "mode": "std",
        "aspect_ratio": "16:9",
        "duration": 5,
        "audio": false,
        "watermark": true
    }
}'

Python SDK

import dashscope
import os
from dashscope import DashScopeError

# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx"
# 获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
client = dashscope.Client(api_key=os.getenv("DASHSCOPE_API_KEY"))

def sample_async_call():
    # 异步提交视频生成任务
    # mode/aspect_ratio/audio 为 parameters 段字段,不在具名签名内,经 parameters 透传
    try:
        job = client.videos.jobs.create(model='kling/kling-v3-turbo-video-generation',
                                        prompt='一只小猫在月光下奔跑',
                                        duration=5,
                                        watermark=True,
                                        parameters={'mode': 'std',
                                                    'aspect_ratio': '16:9',
                                                    'audio': False})
        print(job)
        print("task_id: %s" % job.task_id)
    except DashScopeError as e:
        print(f"HTTP返回码:{e.status_code}")
        print(f"错误码:{e.code}")
        print(f"错误信息:{e.message}")
        print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")
        return

    # 查询任务状态
    try:
        snapshot = client.videos.jobs.fetch(job.task_id)
        print(snapshot.status)
    except DashScopeError as e:
        print(f"HTTP返回码:{e.status_code}")
        print(f"错误码:{e.code}")
        print(f"错误信息:{e.message}")
        print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")

    # 等待任务完成
    try:
        done = client.videos.jobs.wait(job)
        print(done)
        print(done.video_url)
    except DashScopeError as e:
        print(f"HTTP返回码:{e.status_code}")
        print(f"错误码:{e.code}")
        print(f"错误信息:{e.message}")
        print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")

if __name__ == '__main__':
    sample_async_call()

Text-to-video (custom shot division)

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

# 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间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": "雾岭镇比地图上更小,山雾像棉絮一样堵在街口。邮局背后果然有三棵槐树,第三棵树根旁的泥土被人动过。",
                "duration": 5
            },
            {
                "index": 2,
                "prompt": "林澈蹲下挖出一个铁盒,里面除了一把生锈的钥匙,还有一盘老旧的录音带。录音机是邮局借的,按下播放键时,父亲的声音从沙沙杂音里爬出来:“如果你听到这段话,说明你已经走到我走过的路上了。",
                "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-turbo-video-generation, kling/kling-v3-video-generation, and kling/kling-v3-omni-video-generation.

# 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间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": "让图片中的人物动起来,头发被微风吹动",
        "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-video-generation and kling/kling-v3-omni-video-generation.

# 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间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": "写实风格,一只黑色小猫好奇地看向天空,镜头从平视逐渐上升,最后俯拍它的好奇的眼神。",
        "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.

# 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间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>>>背景,<<<image_2>>>和<<<image_1>>>握手交谈,<<<video_1>>>人物穿着黑色风衣的侦探站在公寓楼顶,手持望远镜观察街道",
        "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
    }
}'

Kling 4.0 keyframe-to-video

Supported model: kling/kling-v4-video-generation. This example uses first and last frames; you can also supply only an intermediate or last frame. Replace the image URLs with accessible images that meet the asset requirements.

# 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间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-v4-video-generation",
    "input": {
        "prompt": "镜头从近景缓慢拉远,人物站在海边看向远处,头发被海风吹动,海浪声渐强",
        "media": [
            {"type": "first_frame", "url": "https://example.com/first.jpeg"},
            {"type": "last_frame", "url": "https://example.com/last.jpeg"}
        ]
    },
    "parameters": {
        "mode": "pro",
        "duration": 10,
        "watermark": false
    }
}'

Kling 4.0 omni reference-to-video

Supported model: kling/kling-v4-omni-reference-video-generation. Replace the video URL and element_id with a usable video and entity ID that meet the requirements.

# 以下为华北2(北京)地域的URL。请将 {WorkspaceId} 替换为您的百炼业务空间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-v4-omni-reference-video-generation",
    "input": {
        "prompt": "让<<<element_1>>>模仿<<<video_1>>>中的动作,从画面左侧走向镜头,整体保持电影感夜景氛围",
        "media": [
            {"type": "feature", "url": "https://example.com/reference.mp4"}
        ],
        "element_list": [
            {"element_id": 148}
        ]
    },
    "parameters": {
        "mode": "pro",
        "duration": 10,
        "aspect_ratio": "16:9",
        "watermark": false
    }
}'

Response parameters

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_idstring

Unique request identifier for tracing and troubleshooting.

codestring

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

messagestring

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

Successful response

Save the task_id, which is used to query the task status and results.

{
    "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": "No API-key provided.",
    "request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}

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

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.

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"

Response parameters

outputobject

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_urlstring

The 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_urlstring

The 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 string

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

codestring

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

messagestring

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 number

The 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 number

For 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 number

For 4.0 models, the generated video duration in seconds, rounded to two decimal places.

reference_type string

For 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 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 value: 720. When mode=4k, 4k is returned; kling/kling-v3-turbo-video-generation only returns 720 or 1080.

audio boolean

Indicates 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 integer

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

request_idstring

Unique request identifier for tracing and troubleshooting.

3.0 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"
    }
}

4.0 task successful

This example shows a 4.0 Omni task with a reference video. Without video input, input_video_duration is 0.00 and reference_type is omitted.

{
    "request_id": "bd547b6a-be36-9a46-857f-xxxxxxxxxxxx",
    "output": {
        "task_id": "6c44c3ee-9c48-462b-8186-xxxxxxxxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-11-16 15:53:34.236",
        "scheduled_time": "2026-11-16 15:53:34.309",
        "end_time": "2026-11-16 15:54:20.367",
        "video_url": "https://v4-fdl.kechuangai.com/ksc2/xxx.mp4?xxxx",
        "watermark_video_url": "https://v4-fdl.kechuangai.com/ksc2/xxx.mp4?xxxx"
    },
    "usage": {
        "video_count": 1,
        "SR": "720",
        "duration": 7.63,
        "input_video_duration": 4.63,
        "output_video_duration": 3.0,
        "reference_type": "video",
        "size": "940*940",
        "audio": true,
        "fps": 24
    }
}

Task failed

If the task fails, task_status is set to FAILED, and an error code and message are provided. See Error codes for troubleshooting.

{
    "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

task_id is valid for queries for 24 hours. After it expires, queries are no longer available and the following error message is returned.

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

Error codes

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