Kling 2.1 AI Video Generator Serverless API

Kling 2.1 offers hyper-realistic video generation with improved motion, sharper 1080p visuals, and instant restyling capabilities. Its cost-effective pricing and faster rendering times make it a game-changer for creators seeking cinematic-quality AI videos.

~134.69s
 1import requests
 2import json
 3
 4url = "https://api.segmind.com/v1/kling-2.1"
 5headers = {
 6    "x-api-key": "YOUR_API_KEY",
 7    "Content-Type": "application/json"
 8}
 9
10data = {
11    "image": "https://segmind-resources.s3.amazonaws.com/input/e1fcf474-2790-4e1a-b094-ae0b20a18ab8-428e317b-d7c2-48fb-a001-ed0820fb04be.jpg",
12    "prompt": "Front View Shot of model in casual wear. [Push in] [Static shot] Subtle shoulder rotation, confident smile, hands in pockets, slight weight shift.",
13    "negative_prompt": "No jittery motion, avoid rapid scene changes.",
14    "cfg_scale": 0.7,
15    "mode": "pro",
16    "aspect_ratio": "16:9",
17    "duration": "5"
18}
19
20response = requests.post(url, headers=headers, json=data)
21
22if response.status_code == 200:
23    result = response.json()
24    print(json.dumps(result, indent=2))
25else:
26    print(f"Error: {response.status_code}")
27    print(response.text)

API Endpoint

POSThttps://api.segmind.com/v1/kling-2.1

Parameters

imagerequired
string (uri)

Provide an image to be animated. Use clear, high-quality images for best results.

Default: "https://segmind-resources.s3.amazonaws.com/input/e1fcf474-2790-4e1a-b094-ae0b20a18ab8-428e317b-d7c2-48fb-a001-ed0820fb04be.jpg"
aspect_ratiooptional
string

Select output aspect ratio. '16:9' is best for widescreens, '1:1' for social media.

Default: "16:9"
Allowed values :
"16:9""9:16""1:1"
cfg_scaleoptional
number

Controls animation adherence to the prompt. Lower for more freedom, higher for precise adherence.

Default: 0.7Range: 0 - 1
durationoptional
integer

Set animation duration. Choose '5' for short previews, '10' for detailed views.

Default: 5
Allowed values :
510
image_tailoptional
string (uri)

Last frame of the video (pro mode is required when this parameter is set)

Default: null
modeoptional
string

Choose animation quality mode. 'Pro' for balanced quality, 'Master' for quality focus.

Default: "pro"
Allowed values :
"std""pro""master"
negative_promptoptional
string

Specify unwanted effects. List distractions like sudden flashes or fast zooms to avoid them.

Default: "No jittery motion, avoid rapid scene changes."
promptoptional
string

Describe the desired animation effect. Use creative, vivid descriptions for dynamic animations.

Default: "Front View Shot of model in casual wear. [Push in] [Static shot] Subtle shoulder rotation, confident smile, hands in pockets, slight weight shift."

Response Type

Returns: Video

Common Error Codes

The API returns standard HTTP status codes. Detailed error messages are provided in the response body.

400

Bad Request

Invalid parameters or request format

401

Unauthorized

Missing or invalid API key

403

Forbidden

Insufficient permissions

404

Not Found

Model or endpoint not found

406

Insufficient Credits

Not enough credits to process request

429

Rate Limited

Too many requests

500

Server Error

Internal server error

502

Bad Gateway

Service temporarily unavailable

504

Timeout

Request timed out