The Kling AI Image to Video Generation API Docs provides comprehensive instructions on how to transform static images into high-quality videos. Customize parameters such as style, resolution, and duration with ease. The API supports real-time rendering, batch processing, and seamless integration for streamlined video automation. Designed for developers, it simplifies the creation of dynamic and customizable videos, making it an ideal solution for marketing, education, and creative applications.
To access this API, register and obtain a Subscription-Key. Add the key to the request headers for authentication.
Content-Type | Set to application/json |
---|---|
Cache-Control | Recommended to set to no-cache |
Ocp-Apim-Subscription-Key | YOUR_SUBSCRIPTION_KEY |
Base URL: https://gateway.appypie.com/kling-ai-video/v1/getImageToVideoTask
API Parameters: The API POST- https://gateway.appypie.com/kling-ai-video/v1/getImageToVideoTask takes the following parameters:
Parameters | Type | Required | Description |
image | String | Yes | The image input, which can be a Base64-encoded string or an accessible image URL (e.g., https://example.com/image.jpg). When using Base64, ensure the data is properly encoded without any prefix (e.g., data:image/png;base64). |
image_tail | string | optional | Similar to image, this parameter allows an additional image input in Base64 or URL format. If using Base64, ensure it is properly encoded and without a prefix. Default is null. |
prompt | String | optional | A description or instruction for the video scene to be generated. Must not exceed 2500 characters. Default is null. |
negative_prompt | string | optional | A negative text prompt to exclude specific elements from the generated video. Cannot exceed 2500 characters. Default is null. |
cfg_scale | Float | Optional | A value between 0 and 1 to control flexibility in video generation. The higher the value, the stronger the model’s relevance to the user’s prompt. Default is 0.5. |
callback_url | String | Optional | A URL for receiving callback notifications when the task status changes. If configured, the server will send updates on task status. Default is null. The message schema can be found in the "Callback Protocol". |
JSON
{ "image": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/b-d-a-lbdo-2-5-21.jpg", "negative_prompt": "Dull and Fade" }
POST https://gateway.appypie.com/kling-ai-video/v1/getImageToVideoTask HTTP/1.1 Content-Type: application/json Cache-Control: no-cache { "image": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/b-d-a-lbdo-2-5-21.jpg", "negative_prompt": "Fade" }
import urllib.request, json try: url = "https://gateway.appypie.com/kling-ai-video/v1/getImageToVideoTask" hdr ={ # Request headers 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', } # Request body data = data = json.dumps(data) req = urllib.request.Request(url, headers=hdr, data = bytes(data.encode("utf-8"))) req.get_method = lambda: 'POST' response = urllib.request.urlopen(req) print(response.getcode()) print(response.read()) except Exception as e: print(e)
// Request body const body = { "image": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/b-d-a-lbdo-2-5-21.jpg", "negative_prompt": "Fade" }; fetch('https://gateway.appypie.com/kling-ai-video/v1/getImageToVideoTask', { method: 'POST', body: JSON.stringify(body), // Request headers headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache',} }) .then(response => { console.log(response.status); console.log(response.text()); }) .catch(err => console.error(err));
curl -v -X POST "https://gateway.appypie.com/kling-ai-video/v1/getImageToVideoTask" -H "Content-Type: application/json" -H "Cache-Control: no-cache" --data-raw "{ \"image\": \"https://pub-582b7213209642b9b995c96c95a30381.r2.dev/b-d-a-lbdo-2-5-21.jpg\", \"negative_prompt\": \"Fade\" }"
import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; import java.io.UnsupportedEncodingException; import java.io.DataInputStream; import java.io.InputStream; import java.io.FileInputStream; public class HelloWorld { public static void main(String[] args) { try { String urlString = "https://gateway.appypie.com/kling-ai-video/v1/getImageToVideoTask"; URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); //Request headers connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Cache-Control", "no-cache"); connection.setRequestMethod("POST"); // Request body connection.setDoOutput(true); connection .getOutputStream() .write( "{ \"image\": \"https://pub-582b7213209642b9b995c96c95a30381.r2.dev/b-d-a-lbdo-2-5-21.jpg\", \"negative_prompt\": \"Fade\" }".getBytes() ); int status = connection.getResponseCode(); System.out.println(status); BufferedReader in = new BufferedReader( new InputStreamReader(connection.getInputStream()) ); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content); connection.disconnect(); } catch (Exception ex) { System.out.print("exception:" + ex.getMessage()); } } }
$url = "https://gateway.appypie.com/kling-ai-video/v1/getImageToVideoTask"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); # Request headers $headers = array( 'Content-Type: application/json', 'Cache-Control: no-cache',); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); # Request body $request_body = '{ "image": "https://pub-582b7213209642b9b995c96c95a30381.r2.dev/b-d-a-lbdo-2-5-21.jpg", "negative_prompt": "Fade" }'; curl_setopt($curl, CURLOPT_POSTFIELDS, $request_body); $resp = curl_exec($curl); curl_close($curl); var_dump($resp);
JSON
HTTP/1.1 200 OK { "code": 0, "message": "SUCCEED", "request_id": "CjiL9mdJhswAAAAAAKxcgQ", "data": { "task_id": "CjiL9mdJhswAAAAAAKXXXX", "task_status": "submitted", "created_at": 1733234459337, "updated_at": 1733234459337 } }
To verify the status of your image generation request and retrieve the image URL, make a subsequent API call using the task_id provided in the original response.
Base URL: https://gateway.appypie.com/kling-ai-polling/v1/getImageToVideoStatus
Content-Type | Set to application/json |
---|---|
Cache-Control | Recommended to set to no-cache |
API Parameters: The API POST- https://gateway.appypie.com/kling-ai-polling/v1/getImageToVideoStatus takes the following parameters:
Pass the task_id received from the initial response in your request body.
JSON
{ "task_id":"CjiL9mdJhswAAAAAAKXXXX" }
POST https://gateway.appypie.com/kling-ai-polling/v1/getImageToVideoStatus HTTP/1.1 Content-Type: application/json Cache-Control: no-cache { "task_id": "task_id" }
import urllib.request, json try: url = "https://gateway.appypie.com/kling-ai-polling/v1/getImageToVideoStatus" hdr ={ # Request headers 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', } # Request body data = data = json.dumps(data) req = urllib.request.Request(url, headers=hdr, data = bytes(data.encode("utf-8"))) req.get_method = lambda: 'POST' response = urllib.request.urlopen(req) print(response.getcode()) print(response.read()) except Exception as e: print(e)
// Request body const body = { "task_id": "task_id" }; fetch('https://gateway.appypie.com/kling-ai-polling/v1/getImageToVideoStatus', { method: 'POST', body: JSON.stringify(body), // Request headers headers: { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache',} }) .then(response => { console.log(response.status); console.log(response.text()); }) .catch(err => console.error(err));
curl -v -X POST "https://gateway.appypie.com/kling-ai-polling/v1/getImageToVideoStatus" -H "Content-Type: application/json" -H "Cache-Control: no-cache" --data-raw "{ \"task_id\": \"task_id\" }"
import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; import java.io.UnsupportedEncodingException; import java.io.DataInputStream; import java.io.InputStream; import java.io.FileInputStream; public class HelloWorld { public static void main(String[] args) { try { String urlString = "https://gateway.appypie.com/kling-ai-polling/v1/getImageToVideoStatus"; URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); //Request headers connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Cache-Control", "no-cache"); connection.setRequestMethod("POST"); // Request body connection.setDoOutput(true); connection .getOutputStream() .write( "{ \"task_id\": \"task_id\" }".getBytes() ); int status = connection.getResponseCode(); System.out.println(status); BufferedReader in = new BufferedReader( new InputStreamReader(connection.getInputStream()) ); String inputLine; StringBuffer content = new StringBuffer(); while ((inputLine = in.readLine()) != null) { content.append(inputLine); } in.close(); System.out.println(content); connection.disconnect(); } catch (Exception ex) { System.out.print("exception:" + ex.getMessage()); } } }
$url = "https://gateway.appypie.com/kling-ai-polling/v1/getImageToVideoStatus"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); # Request headers $headers = array( 'Content-Type: application/json', 'Cache-Control: no-cache',); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); # Request body $request_body = '{ "task_id": "task_id" }'; curl_setopt($curl, CURLOPT_POSTFIELDS, $request_body); $resp = curl_exec($curl); curl_close($curl); var_dump($resp);
Upon successful polling, the API returns the video generation status and, if completed, includes the URL of the generated video.
JSON
{ "code": 0, "message": "SUCCEED", "request_id": "CjiL9mdJhswAAAAAAKyg4w", "data": { "task_id": "CjiL9mdJhswAAAAAAKxcgQ", "task_status": "succeed", "task_status_msg": "", "task_result": { "videos": [{ "id": "a4610291-1b77-459f-b535-0047b601c9e4", "url": "https://cdn.klingai.com/bs2/upload-kling-api/6472161052/image2video/CjiL9mdJhswAAAAAAKxcgQ-0_raw_video_1.mp4", "duration": "5.1" }] }, "created_at": 1733234459337, "updated_at": 1733234699138 } }
The Kling AI Image-to-Video Generation API provides specific HTTP status codes and detailed response bodies to indicate the result of each request. Developers are encouraged to implement effective error handling to process these responses accurately, ensuring a smooth and seamless user experience.
Status Code | Description | Response Body |
200 | Success - The request was successfully processed, and the image generation is in progress or completed. | { "msg": "Image Getting Created", ... } |
400 | Bad Request - The request contains invalid parameters or missing fields. | { "error": "Invalid request parameters" } |
401 | Unauthorized - The provided subscription key is missing or invalid. | { "error": "Invalid or missing authentication" } |
403 | Forbidden - The subscription does not have access to this API or action. | { "error": "Access denied for this operation" } |
404 | Not Found - The requested resource or endpoint could not be found. | { "error": "Endpoint not found" } |
429 | Too Many Requests - The request rate limit has been exceeded. | { "error": "Rate limit exceeded, please retry later" } |
500 | Internal Server Error - An unexpected error occurred on the server. | { "error": "An unexpected error occurred, please try again later" } |
{ "task_status": "failed", "task_status_msg": "task not found" }
This comprehensive documentation offers all the essential details for effectively utilizing the Kling AI Image-to-Video Generation API. It includes everything you need, from integration steps to usage guidelines, to help you get started. Ensure you replace YOUR_API_KEY with the actual key provided upon subscription, as it is required for authentication and access. By following the provided instructions, you can seamlessly integrate the API into your applications and unlock its full potential for creating high-quality videos from images.