Kling AI T2V API Documentation
Text To Video Request - Request Code
POST https://gateway.pixazo.ai/kling-ai-video/v1/generateVideoTask Content-Type: application/json Cache-Control: no-cache Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY { "prompt": "An enchanted forest with glowing mushrooms, fireflies, and a sparkling river flowing through the trees.", "negative_prompt": "nude, porn, abusive", "cfg_scale": 0.5, "aspect_ratio": "16:9" } import requests url = "https://gateway.pixazo.ai/kling-ai-video/v1/generateVideoTask" headers = { "Content-Type": "application/json", "Cache-Control": "no-cache", "Ocp-Apim-Subscription-Key": "YOUR_SUBSCRIPTION_KEY" } data = { "prompt": "An enchanted forest with glowing mushrooms, fireflies, and a sparkling river flowing through the trees.", "negative_prompt": "nude, porn, abusive", "cfg_scale": 0.5, "aspect_ratio": "16:9" } response = requests.post(url, json=data, headers=headers) print(response.json()) const url = 'https://gateway.pixazo.ai/kling-ai-video/v1/generateVideoTask'; const headers = { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', 'Ocp-Apim-Subscription-Key': 'YOUR_SUBSCRIPTION_KEY' }; const data = { prompt: 'An enchanted forest with glowing mushrooms, fireflies, and a sparkling river flowing through the trees.', negative_prompt: 'nude, porn, abusive', cfg_scale: 0.5, aspect_ratio: '16:9' }; fetch(url, { method: 'POST', headers: headers, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); curl -v -X POST "https://gateway.pixazo.ai/kling-ai-video/v1/generateVideoTask" \ -H "Content-Type: application/json" \ -H "Cache-Control: no-cache" \ -H "Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY" \ --data-raw '{ "prompt": "An enchanted forest with glowing mushrooms, fireflies, and a sparkling river flowing through the trees.", "negative_prompt": "nude, porn, abusive", "cfg_scale": 0.5, "aspect_ratio": "16:9" }' import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.time.Duration; public class ApiExample { public static void main(String[] args) throws Exception { String url = "https://gateway.pixazo.ai/kling-ai-video/v1/generateVideoTask"; String json = """ { "prompt": "An enchanted forest with glowing mushrooms, fireflies, and a sparkling river flowing through the trees.", "negative_prompt": "nude, porn, abusive", "cfg_scale": 0.5, "aspect_ratio": "16:9" } """; HttpClient client = HttpClient.newBuilder() .connectTimeout(Duration.ofSeconds(10)) .build(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(url)) .header("Content-Type", "application/json") .header("Cache-Control", "no-cache") .header("Ocp-Apim-Subscription-Key", "YOUR_SUBSCRIPTION_KEY") .POST(HttpRequest.BodyPublishers.ofString(json)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } <?php $url = 'https://gateway.pixazo.ai/kling-ai-video/v1/generateVideoTask'; $data = [ 'prompt' => 'An enchanted forest with glowing mushrooms, fireflies, and a sparkling river flowing through the trees.', 'negative_prompt' => 'nude, porn, abusive', 'cfg_scale' => 0.5, 'aspect_ratio' => '16:9' ]; $jsonData = json_encode($data); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Cache-Control: no-cache', 'Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY' ]); $response = curl_exec($ch); curl_close($ch); echo $response; ?> Output
Successful API response:
{ "code": 0, "message": "SUCCEED", "request_id": "CjNQtmctxFMAAAAAAO_VAg", "data": { "task_id": "CjNQtmctxFMAAAAAAO_VAg", "task_status": "submitted" } } Request Body - Text To Video Request
Parameters for https://gateway.pixazo.ai/kling-ai-video/v1/generateVideoTask:
| Parameter | Required | Type | Description |
|---|---|---|---|
| prompt | Yes | string | The instruction or description for the video scene to be generated. Cannot exceed 2500 characters |
| negative_prompt | No | string | Negative text prompt. Cannot exceed 2500 characters |
| cfg_scale | No | float | Default 0.5, Value range: [0, 1]. Flexibility in video generation; The higher the value, the lower the model's degree of flexibility, and the stronger the relevance to the user's prompt |
| aspect_ratio | No | string | Default: 16:9. The aspect ratio of the generated video frame (width:height). Enum values:16:9, 9:16, 1:1 |
Example Request - Text To Video Request
JSON
{ "prompt": "An enchanted forest with glowing mushrooms, fireflies, and a sparkling river flowing through the trees.", "negative_prompt": "nude, porn, abusive", "cfg_scale": 0.5, "aspect_ratio": "16:9" } Response - Text To Video Request
JSON
{ "code": 0, "message": "SUCCEED", "request_id": "CjNQtmctxFMAAAAAAO_VAg", "data": { "task_id": "CjNQtmctxFMAAAAAAO_VAg", "task_status": "submitted", "created_at": 1731496477317, "updated_at": 1731496477317 } } Request Headers
| Header | Description |
|---|---|
| Content-Type | application/json |
| Cache-Control | no-cache |
| Ocp-Apim-Subscription-Key | Subscription key for authentication |
Response Handling
The klingai Video returns specific HTTP status codes and response bodies to indicate the success or failure of a request. Developers should implement error handling in their applications to manage these responses effectively.
Common Status Codes and Responses
| Status Code | Description | Response Body |
|---|---|---|
| 200 | Success - The request was successfully processed. | { "success": true, ... } |
| 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" } |
Example Error Response
{ "error": "Invalid parameters" } Retrieving Results
After submitting your request, use this endpoint to check status and retrieve results.
Endpoint
POST https://gateway.pixazo.ai/kling-ai-polling/v1/getVideoStatus
Request Body
{ "task_id": "CjNQtmctxFMAAAAAAO_VAg" } Example Success Response
{ "code": 0, "message": "IN_PROGRESS", "request_id": "54ff1f7b-8a32-4b14-bff7-ad5ad8752885", "data": { "task_id": "54ff1f7b-8a32-4b14-bff7-ad5ad8752885", "task_status": "processing", "task_status_msg": "Processing", "created_at": 1756380385960, "updated_at": 1756380385960 } } { "code": 0, "message": "SUCCEED", "request_id": "54ff1f7b-8a32-4b14-bff7-ad5ad8752885", "data": { "task_id": "54ff1f7b-8a32-4b14-bff7-ad5ad8752885", "task_status": "succeed", "task_status_msg": "", "task_info": {}, "task_result": { "video_url": "https://example.com/video.mp4" }, "created_at": 1756380973496, "updated_at": 1756380973496 } } Code Examples
POST https://gateway.pixazo.ai/kling-ai-polling/v1/getVideoStatus Content-Type: application/json Cache-Control: no-cache { "task_id": "CjNQtmctxFMAAAAAAO_VAg" } import requests url = "https://gateway.pixazo.ai/kling-ai-polling/v1/getVideoStatus" headers = { "Content-Type": "application/json", "Cache-Control": "no-cache" } data = { "task_id": "CjNQtmctxFMAAAAAAO_VAg" } response = requests.post(url, json=data, headers=headers) print(response.json()) const url = 'https://gateway.pixazo.ai/kling-ai-polling/v1/getVideoStatus'; const headers = { 'Content-Type': 'application/json', 'Cache-Control': 'no-cache' }; const data = { task_id: 'CjNQtmctxFMAAAAAAO_VAg' }; fetch(url, { method: 'POST', headers: headers, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); curl -v -X POST "https://gateway.pixazo.ai/kling-ai-polling/v1/getVideoStatus" \ -H "Content-Type: application/json" \ -H "Cache-Control: no-cache" \ --data-raw '{ "task_id": "CjNQtmctxFMAAAAAAO_VAg" }' import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.time.Duration; public class PollingExample { public static void main(String[] args) throws Exception { String url = "https://gateway.pixazo.ai/kling-ai-polling/v1/getVideoStatus"; String json = """ { "task_id": "CjNQtmctxFMAAAAAAO_VAg" } """; HttpClient client = HttpClient.newBuilder() .connectTimeout(Duration.ofSeconds(10)) .build(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(url)) .header("Content-Type", "application/json") .header("Cache-Control", "no-cache") .POST(HttpRequest.BodyPublishers.ofString(json)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } <?php $url = 'https://gateway.pixazo.ai/kling-ai-polling/v1/getVideoStatus'; $data = [ 'task_id' => 'CjNQtmctxFMAAAAAAO_VAg' ]; $jsonData = json_encode($data); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Cache-Control: no-cache' ]); $response = curl_exec($ch); curl_close($ch); echo $response; ?> Kling AI T2V API Pricing
| Resolution | Seconds | Price (USD) |
|---|---|---|
| All Resolution | 5 | $0.35 |