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.
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) 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
https://api.segmind.com/v1/kling-2.1Parameters
imagerequiredstring (uri)Provide an image to be animated. Use clear, high-quality images for best results.
"https://segmind-resources.s3.amazonaws.com/input/e1fcf474-2790-4e1a-b094-ae0b20a18ab8-428e317b-d7c2-48fb-a001-ed0820fb04be.jpg"aspect_ratiooptionalstringSelect output aspect ratio. '16:9' is best for widescreens, '1:1' for social media.
"16:9""16:9""9:16""1:1"cfg_scaleoptionalnumberControls animation adherence to the prompt. Lower for more freedom, higher for precise adherence.
0.7Range: 0 - 1durationoptionalintegerSet animation duration. Choose '5' for short previews, '10' for detailed views.
5510image_tailoptionalstring (uri)Last frame of the video (pro mode is required when this parameter is set)
nullmodeoptionalstringChoose animation quality mode. 'Pro' for balanced quality, 'Master' for quality focus.
"pro""std""pro""master"negative_promptoptionalstringSpecify unwanted effects. List distractions like sudden flashes or fast zooms to avoid them.
"No jittery motion, avoid rapid scene changes."promptoptionalstringDescribe the desired animation effect. Use creative, vivid descriptions for dynamic animations.
"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.
Bad Request
Invalid parameters or request format
Unauthorized
Missing or invalid API key
Forbidden
Insufficient permissions
Not Found
Model or endpoint not found
Insufficient Credits
Not enough credits to process request
Rate Limited
Too many requests
Server Error
Internal server error
Bad Gateway
Service temporarily unavailable
Timeout
Request timed out