Kling 4.0

This guide shows how to generate videos using the Kling 4.0 model via the Leonardo.AI REST API.

Sample Request

curl --request POST \
     --url https://cloud.leonardo.ai/api/rest/v2/generations \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <YOUR_API_KEY>' \
     --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": "<YOUR_START_IMAGE_ID>",
              "type": "GENERATED"
            }
          }
        ]
      }
    }
}
'

Recipe

API Request Endpoint, Headers, Parameters

Endpoint

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

Headers

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

Body Parameters

ParameterTypeDefinition
durationnumberLength of the generated video in seconds. Set to 3 up to 30. Defaults to 5.
guidances.end_framearrayMaximum 1 item. Each item includes image.id and image.type (GENERATED or UPLOADED).
guidances.image_referencearrayArray of up to 10 reference images used to guide the visual style or content of the generation. Each item includes image.id and image.type (GENERATED or UPLOADED).
guidances.start_framearrayMaximum 1 item. Each item includes image.id and image.type (GENERATED or UPLOADED).
guidances.video_reference_basearraySpecify the video to edit. Maximum 1 item. Each item includes video.id and video.type (GENERATED or UPLOADED). The reference video must be 700 to 4553 pixels in width and height, and 3 to 30 seconds long.
heightnumberSets the height of the video in pixels. Defaults to 720.
modelstringRequired. Specifies the model used for generation. Set to kling-4.0.
motion_has_audiobooleanControls whether to generate audio (true) or not (false). Defaults to true.
promptstringRequired. Text description of the video content to generate. Maximum of 2500 characters.
publicbooleanControls whether the generated video is public (true) or private (false).
quantitynumberNumber of videos to generate. Set to 1. Defaults to 1.
widthnumberSets the width of the video in pixels. Defaults to 1280.

Dimensions

The API accepts width and height parameters in the following aspect ratio combinations:

ResolutionAspect RatioPixel Values (Width x Height)
720p16:91280x720
1:1960x960
9:16720x1280
21:91470x630
1080p16:91920x1080
1:11440x1440
9:161080x1920
21:92520x1080

Note: width and height must be specified together. When both are omitted, the generation defaults to 1280x720.


Did this page help you?