进阶 docs.leonardo.ai 2026-11-22 15:11:20 · 0 阅读

第44章 使用 Kling 4.0 生成视频

Kling 4.0

本指南演示如何通过 Leonardo.AI REST API 使用 Kling 4.0 模型生成视频。

示例请求

curl --request POST \
    --url https://cloud.leonardo.ai/api/rest/v2/generations \
    --header 'accept: application/json' \
    --header 'authorization: Bearer ' \
    --header 'content-type: application/json' \
    --data '
{
    "model": "kling-4.0",
    "public": false,
    "parameters": {
        "prompt": "A lone surfer paddles out at sunrise as waves roll toward the shore",
        "duration": 10,
        "width": 2520,
        "height": 1080,
        "motion_has_audio": true,
        "guidances": {
            "start_frame": [
                {
                    "image": {
                        "id": "",
                        "type": "GENERATED"
                    }
               }
            ]
        }
    }
}
'

配方

API 请求端点、请求头和参数

端点

https://cloud.leonardo.ai/api/rest/v2/generations

请求头

--header "accept: application/json" \
--header "authorization: Bearer " \
--header "content-type: application/json"

Body 参数

参数 类型 定义
duration number 生成视频的时长(秒)。取值范围 3 到 30,默认 5。
guidances.end_frame array 最多 1 项。每项包含 image.id 和 image.type(GENERATED 或 UPLOADED)。
guidances.image_reference array 最多 10 张参考图的数组,用于指导生成的视觉风格或内容。每项包含 image.id 和 image.type(GENERATED 或 UPLOADED)。
guidances.start_frame array 最多 1 项。每项包含 image.id 和 image.type(GENERATED 或 UPLOADED)。
guidances.video_reference_base array 指定要编辑的视频。最多 1 项,每项包含 video.id 和 video.type(GENERATED 或 UPLOADED)。参考视频的宽高须在 700 到 4553 像素之间,时长须在 3 到 30 秒之间。
height number 设置视频高度(像素),默认 720。
model string 必填。指定用于生成的模型,设为 kling-4.0。
motion_has_audio boolean 控制是否生成音频(true)或不生成(false),默认 true。
prompt string 必填。待生成视频内容的文本描述,最多 2500 个字符。
public boolean 控制生成的视频为公开(true)或私有(false)。
quantity number 生成的视频数量,设为 1,默认 1。
width number 设置视频宽度(像素),默认 1280。

尺寸规格

API 接受以下宽高比组合的 width 和 height 参数:

分辨率 宽高比 像素值(宽 x 高)
720p 16:9 1280x720
720p 1:1 960x960
720p 9:16 720x1280
720p 21:9 1470x630
1080p 16:9 1920x1080
1080p 1:1 1440x1440
1080p 9:16 1080x1920
1080p 21:9 2520x1080

注意:width 和 height 必须同时指定。若两者均省略,生成结果默认为 1280x720。

更新于 24 天前   此页面对你有帮助吗?

评论 (0)