### Base64 Image Encoding Example Source: https://kling.ai/document-api/api/image/3-0-omni Illustrates the correct format for Base64 encoded image data, excluding any prefixes. ```text iVBORw0KGgoAAAANSUhEUgAAAAUA... ``` -------------------------------- ### Dual-Image Effect Example Source: https://kling.ai/document-api/api/effects/video-effects Use this to apply one of the 15 available dual-image effects. This requires two images, typically provided as Base64 strings or URLs. ```json { "effect": "pet_skateboard", "images": [ "iVBORw0KGgoAAAANSUhEUgAAAAUA...", "iVBORw0KGgoAAAANSUhEUgAAAAUA..." ] } ``` -------------------------------- ### cURL Example for Querying Tasks Source: https://kling.ai/document-api/api/video/3-0-turbo This cURL command demonstrates how to query asynchronous tasks with specific filters for status and product type. Ensure you replace {apikey} with your actual API key. ```bash curl --location 'https://api-singapore.klingai.com/tasks' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer {apikey}' \ --data '{ "start_time": "1781193600000", "end_time": "1781516352968", "cursor": "", "limit": 500, "filters": [ { "key": "status", "values": ["succeeded"] }, { "key": "product_type", "values": ["video"] } ] }' ``` -------------------------------- ### Import Kling Credentials Source: https://kling.ai/document-api/api/get-started/kling-skills Manually bind your Kling account by importing AK/SK credentials using this command. Ensure Node.js 18+ is installed. ```bash node kling.mjs account --import-credentials --access_key_id --secret_access_key ``` -------------------------------- ### Image to Video Task Creation Response Source: https://kling.ai/document-api/api/video/3-0-omni This is an example of a successful response when creating an image-to-video task. It includes task details such as task ID, status, and creation timestamps. ```JSON { "code": 0, // Error codes; Specific definitions can be found in "Error Code" "message": "string", // Error information "request_id": "string", // Request ID, generated by the system "data": { "task_id": "string", // Task ID, generated by the system "task_info": { // Task creation parameters "external_task_id": "string" // Customer-defined task ID }, "task_status": "string", // Task status, Enum values: submitted, processing, succeed, failed "created_at": 1722769557708, // Task creation time, Unix timestamp, unit ms "updated_at": 1722769557708 // Task update time, Unix timestamp, unit ms } } ``` -------------------------------- ### Image List Request Format Source: https://kling.ai/document-api/api/image/o1 Example of how to format the image_list parameter for reference images in the API request. ```json "image_list":[ { "image":"image_url" } ] ``` -------------------------------- ### Query Task List cURL Example Source: https://kling.ai/document-api/api/video/2-6 Use this cURL command to retrieve a list of video generation tasks. Ensure you replace '' with your actual API token. The 'pageNum' and 'pageSize' parameters can be adjusted to paginate through results. ```bash curl --request GET \ --url 'https://api-singapore.klingai.com/v1/videos/image2video?pageNum=1&pageSize=30' \ --header 'Authorization: Bearer ' ``` -------------------------------- ### cURL Request Example for Image-to-Video Generation Source: https://kling.ai/document-api/api/video/3-0-turbo Use this cURL command to send a request to the Kling AI 3.0 Turbo API for image-to-video generation. It includes prompt, first frame URL, resolution, duration, callback URL, and watermark settings. ```curl curl --location 'https://api-singapore.klingai.com/image-to-video/kling-3.0-turbo' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer {apikey}' \ --data-raw '{ \ "contents": [ \ { \ "type": "prompt", \ "text": "A girl sat on the train, looking out the window with a melancholic expression, her head swaying with the train." \ }, \ { \ "type": "first_frame", \ "url": "https://p2-kling.klingai.com/kcdn/cdn-kcdn112452/kling-tob-release_note/image_25.png" \ } \ ], \ "settings": { \ "resolution": "1080p", \ "duration": 10 \ }, \ "options": { \ "callback_url": "https://xxx/callback", \ "external_task_id": "", \ "watermark_info": { \ "enabled": true \ } \ } \ }' ``` -------------------------------- ### Start & End Frames Source: https://kling.ai/document-api/api/video/o1 Utilizes specified images as the starting and ending frames for video generation. ```APIDOC ## POST /v1/videos/omni-video ### Description Generates a video using provided images as the first and last frames. ### Method POST ### Endpoint https://api-singapore.klingai.com/v1/videos/omni-video ### Parameters #### Request Body - **model_name** (string) - Required - The name of the model to use, e.g., "kling-video-o1". - **prompt** (string) - Required - The text prompt describing the video content. - **image_list** (array) - Required - A list of image objects, each with 'image_url' and 'type' set to "first_frame" or "end_frame". - **mode** (string) - Optional - The generation mode, e.g., "pro". ### Request Example ```json { "model_name": "kling-video-o1", "prompt": "The person in the video is dancing.", "image_list": [ { "image_url": "xxx", "type": "first_frame" }, { "image_url": "xxx", "type": "end_frame" } ], "mode": "pro" } ``` ### Response #### Success Response (200) - **video_url** (string) - URL of the generated video. - **message** (string) - Confirmation message. ``` -------------------------------- ### Single-Image Effect Example Source: https://kling.ai/document-api/api/effects/video-effects Use this to apply one of the 265 available single-image effects. Ensure the 'image' field is a raw Base64 string without any prefixes. ```json { "effect": "bicycle_kick", "image": "iVBORw0KGgoAAAANSUhEUgAAAAUA..." } ``` -------------------------------- ### Query Task List cURL Example Source: https://kling.ai/document-api/api/image/o1 Use this cURL command to list image tasks. Ensure you replace '' with your actual API token. The 'pageNum' and 'pageSize' parameters control pagination. ```bash curl --request GET \ --url 'https://api-singapore.klingai.com/v1/images/omni-image?pageNum=1&pageSize=30' \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' ``` -------------------------------- ### Single-Image Effect Request Example Source: https://kling.ai/document-api/api/effects/video-effects This JSON object shows how to request a single-image effect, specifying the 'pet_lion' effect scene and providing a single image URL. ```json { "effect_scene": "pet_lion", "input": { "image": "https://p4-kling.klingai.com/bs2/upload-ylab-stunt/c54e463c95816d959602f1f2541c62b2.png?x-kcdn-pid=112452" } } ``` -------------------------------- ### Create Task Source: https://kling.ai/document-api/api/video/avatar Creates a video generation task from an image and a sound file. The API supports custom prompts to guide the avatar's actions and expressions. ```APIDOC ## POST /v1/videos/avatar/image2video ### Description Creates a video generation task from an image and a sound file. The API supports custom prompts to guide the avatar's actions and expressions. ### Method POST ### Endpoint /v1/videos/avatar/image2video ### Parameters #### Request Body - **image** (string) - Required - URL of the input image. - **sound_file** (string) - Required - URL of the input sound file. - **prompt** (string) - Required - Text prompt describing the desired avatar actions and expressions. - **mode** (string) - Optional - Mode for video generation (e.g., 'std'). - **external_task_id** (string) - Optional - Customer-defined task ID. - **callback_url** (string) - Optional - URL for receiving task status updates. ### Request Example ```json { "image": "https://p1-kling.klingai.com/kcdn/cdn-kcdn112452/kling-qa-test/pink_boy.png", "sound_file": "https://p1-kling.klingai.com/kcdn/cdn-kcdn112452/kling-qa-test/go-to-world.mp3", "prompt": "While talking, excitedly shaking head, finally reaching out and making a fist, deciding to set off, hopping happily", "mode": "std", "external_task_id": "", "callback_url": "" } ``` ### Response #### Success Response (200) - **code** (integer) - Error codes; Specific definitions can be found in "Error Code". - **message** (string) - Error information. - **request_id** (string) - Request ID, generated by the system. - **data** (object) - Task creation details. - **task_id** (string) - Task ID, generated by the system. - **task_status** (string) - Task status, Enum values: submitted, processing, succeed, failed. - **task_info** (object) - Task creation parameters. - **external_task_id** (string) - Customer-defined task ID. - **created_at** (integer) - Task creation time, Unix timestamp, unit ms. - **updated_at** (integer) - Task update time, Unix timestamp, unit ms. #### Response Example ```json { "code": 0, "message": "string", "request_id": "string", "data": { "task_id": "string", "task_status": "string", "task_info": { "external_task_id": "string" }, "created_at": 1722769557708, "updated_at": 1722769557708 } } ``` ### Request Header - **Content-Type** (string) - Required - Default to application/json. Data Exchange Format. - **Authorization** (string) - Required - Authentication information, refer to API authentication. ``` -------------------------------- ### Generate Video with Specified Start and End Frames Source: https://kling.ai/document-api/api/video/o1 Use this to generate a video that begins and ends with specific frames provided as images. This offers precise control over the video's temporal boundaries. ```cURL curl --location 'https://api-singapore.klingai.com/v1/videos/omni-video' \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ \ "model_name": "kling-video-o1", \ "prompt": "The person in the video is dancing.", \ "image_list": [ \ { \ "image_url": "xxx", \ "type": "first_frame" \ }, \ { \ "image_url": "xxx", \ "type": "end_frame" \ } \ ], \ "mode": "pro" \ }' ``` -------------------------------- ### Successful Response for Query Task List Source: https://kling.ai/document-api/api/video/o1 This is an example of a successful response when querying a list of video tasks. It includes task status, IDs, and results, such as video URLs. Note that generated videos are deleted after 30 days. ```json { "code": 0, // Error codes; Specific definitions can be found in "Error Code" "message": "string", // Error information "request_id": "string", // Request ID, generated by the system, is used for tracking requests and troubleshooting "data": [ { "task_id": "string", // Task ID, generated by the system "task_status": "string", // Task status, Enum values: submitted, processing, succeed, failed "task_status_msg": "string", // Task status message, displaying the failure reason when the task fails (such as triggering the content risk control of the platform, etc.) "task_info": { "external_task_id": "string" //User-defined task ID, choose either task_id or external_task_id for querying }, "task_result": { "videos": [ { "id": "string", // Generated video ID; globally unique "url": "string", // Generated video URL, anti-leech format (Please note that for security purposes, generated images/videos will be deleted after 30 days. Please save them promptly.) "watermark_url": "string", // Watermarked video download URL, anti-leech format "duration": "string" //Total video duration, unit: s (seconds) } ] }, "watermark_info": { "enabled": boolean }, "final_unit_deduction": "string", // Final unit deduction for the task "created_at": 1722769557708, // Task creation time, Unix timestamp, unit: ms "updated_at": 1722769557708 //Task update time, Unix timestamp, unit: ms } ] } ``` -------------------------------- ### Query Account Resource Package List (cURL) Source: https://kling.ai/document-api/api/assets/account-usage Use this cURL command to fetch the list of resource packages and their remaining quantities under your account. Ensure you replace `` with your actual API token. ```bash curl --request GET \ --url 'https://api-singapore.klingai.com/account/costs?start_time=1726124664368&end_time=1727366400000' \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' ``` -------------------------------- ### Image Generation Request Example Source: https://kling.ai/document-api/api/image/3-0-omni Example of a cURL request to generate an image using the Kling AI API. Includes model name, prompt, and image URL. ```curl curl --request POST \ --url https://api-singapore.klingai.com/v1/images/generations \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ \ "model_name": "kling-v2-1", \ "prompt": "Generate a Pixar-style puppy", \ "negative_prompt": "", \ "image": "https://p1-kling.klingai.com/kcdn/cdn-kcdn112452/kling-qa-test/dog.png", \ "n": 2, \ "external_task_id": "", \ "callback_url": "" \ }' ``` -------------------------------- ### Video List Structure with Options Source: https://kling.ai/document-api/api/video/o1 Illustrates the structure for the 'video_list' parameter, including options for reference type and original sound retention. The 'video_url' is mandatory. ```json { "video_list": [ { "video_url": "video_url", "refer_type": "base", "keep_original_sound": "yes" } ] } ``` -------------------------------- ### Element List Request Format Source: https://kling.ai/document-api/api/image/o1 Example of how to format the element_list parameter using element IDs in the API request. ```json "element_list":[ { "element_id": 829836802793406551 } ] ``` -------------------------------- ### Successful Task Status Response Source: https://kling.ai/document-api/api/video/2-6 This is an example of a successful response when querying a video generation task. It includes the task's current status, any results, and metadata. ```json { "code": 0, "message": "string", "request_id": "string", "data": { "task_id": "string", "task_status": "string", "task_status_msg": "string", "watermark_info": { "enabled": boolean }, "task_result": { "videos": [ { "id": "string", "url": "string", "watermark_url": "string", "duration": "string" } ] }, "task_info": { "external_task_id": "string" }, "final_unit_deduction": "string", "created_at": 1722769557708, "updated_at": 1722769557708 } } ``` -------------------------------- ### Incorrect Base64 Image Format Source: https://kling.ai/document-api/api/effects/video-effects This example illustrates the incorrect format for Base64 encoded images, which includes a 'data:image/png;base64,' prefix. This prefix should be omitted. ```text data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA... ``` -------------------------------- ### Query Account Resource Package List (Python) Source: https://kling.ai/document-api/api/assets/account-usage This Python code snippet demonstrates how to call the account costs API to retrieve resource package details. It requires the `requests` library and your API token. ```python import requests url = "https://api-singapore.klingai.com/account/costs" headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } params = { "start_time": 1726124664368, "end_time": 1727366400000 } response = requests.get(url, headers=headers, params=params) print(response.json()) ``` -------------------------------- ### Create Avatar Video Task (cURL) Source: https://kling.ai/document-api/api/video/avatar Use this cURL command to send a POST request to create an avatar video task. Ensure you replace `` with your actual API token and provide valid URLs for the image and sound file. ```bash curl --request POST \ --url https://api-singapore.klingai.com/v1/videos/avatar/image2video \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ \ "image": "https://p1-kling.klingai.com/kcdn/cdn-kcdn112452/kling-qa-test/pink_boy.png", \ "sound_file": "https://p1-kling.klingai.com/kcdn/cdn-kcdn112452/kling-qa-test/go-to-world.mp3", \ "prompt": "While talking, excitedly shaking head, finally reaching out and making a fist, deciding to set off, hopping happily", \ "mode": "std", \ "external_task_id": "", \ "callback_url": "" \ }' ``` -------------------------------- ### Create Task Source: https://kling.ai/document-api/api/image/common Initiates an AI Multi-Shot Outpainting task. This endpoint allows users to submit an image and optional parameters to generate an outpainting task. ```APIDOC ## POST /v1/general/ai-multi-shot ### Description Initiates an AI Multi-Shot Outpainting task by providing an image and optional task details. ### Method POST ### Endpoint /v1/general/ai-multi-shot ### Parameters #### Request Header - **Content-Type** (string) - Required - Default to application/json - Data Exchange Format - **Authorization** (string) - Required - Authentication information, refer to API authentication #### Request Body - **element_frontal_image** (string) - Required - The frontal side of element image. Supports inputting image Base64 encoding or image URL (ensure accessibility). Supported image formats: .jpg / .jpeg / .png. Image file size cannot exceed 10MB, and the width and height dimensions shall not be less than 300px, and the aspect ratio should be between 1:2.5 ~ 2.5:1. - **external_task_id** (string) - Optional - Customized Task ID. Users can provide a customized task ID, which will not overwrite the system-generated task ID but can be used for task queries. Please note that the customized task ID must be unique within a single user account. - **callback_url** (string) - Optional - The callback notification address for the result of this task. If configured, the server will actively notify when the task status changes. For the specific message schema, see Callback Protocol. ### Request Example ```json { "element_frontal_image": "https://v1-kling.klingai.com/kcdn/cdn-kcdn112452/kling-qa-test/multi-1.png", "external_task_id": "", "callback_url": "" } ``` ### Response #### Success Response (200) - **code** (integer) - Error code; Specific definitions can be found in "Error Code" - **message** (string) - Error message - **request_id** (string) - Request ID, generated by the system, used to track requests and troubleshoot problems - **data** (object) - Task creation parameters - **task_id** (string) - Task ID, generated by the system - **task_status** (string) - Task status, Enum values: submitted, processing, succeed, failed - **task_info** (object) - Task creation parameters - **external_task_id** (string) - Customer-defined task ID - **created_at** (integer) - Task creation time, Unix timestamp, unit: ms - **updated_at** (integer) - Task update time, Unix timestamp, unit: ms #### Response Example ```json { "code": 0, "message": "string", "request_id": "string", "data": { "task_id": "string", "task_status": "string", "task_info": { "external_task_id": "string" }, "created_at": 1722769557708, "updated_at": 1722769557708 } } ``` ``` -------------------------------- ### Create Task Source: https://kling.ai/document-api/api/video/3-0-turbo Creates a new text-to-video task. This endpoint allows users to submit text prompts and parameters to generate video content. ```APIDOC ## POST /tasks ### Description Creates a new text-to-video task. ### Method POST ### Endpoint /tasks ### Request Body - **materials** (array) - Required - List of materials to be used for video generation. - **type** (string) - Required - Type of material (image, video, voice). - **role** (string) - Required - Role of the material (fixed value: refer). - **url** (string) - Required - Download link for the material. - **id** (string) - Optional - ID of the voice material. - **name** (string) - Optional - Name of the voice material. - **owned_by** (string) - Optional - Source of the voice material (kling or creator ID). - **owned_by** (string) - Optional - Source of the element (kling or creator ID). - **status** (string) - Optional - Status of the element (succeeded, deleted). - **tags** (array) - Optional - Information related to element tags. - **id** (integer) - Required - Tag ID. - **name** (string) - Required - Tag name. - **description** (string) - Optional - Tag description. - **billing** (array) - Optional - Billing information for the task. - **charge_type** (string) - Required - Consumption account type (cash or unit). - **amount** (string) - Required - Consumption amount (decimal with 2 digits). - **package_type** (string) - Optional - Consumable resource bundle type (video, image, audio), only applicable when charge_type is 'unit'. ### Response #### Success Response (200) - **count** (integer) - Number of query results. - **next_cursor** (string) - Cursor for querying subsequent results. - **has_more** (boolean) - Indicates if there are more results. ```