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. 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.
-
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.
-
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-videoSupported 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 SDKimport 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 editingSupported 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-videoSupported 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-videoSupported 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
}
}'
|