PiAPI
HomeWorkspace
HomeWorkspace
Join Discord
  1. Kling
  • Get Started
    • Overview
    • Quickstart
    • Make Instruction: How to Use PiAPI to Build a Workflow on Make?
  • Endpoints
    • Song(Udio)
      • Song API Task Creation Examples
      • [Udio] Song Extend
      • Get Task
      • Create Task
      • [Udio] Generate Lyrics
    • Kling
      • Lipsync With PiAPI Kling API Examples
      • Motion Brush With PiAPI Kling API Example
      • Kling Elements Video Generation API
      • Kling Effects Video Generation
      • Cancel Task
        • Cancel Tasks
        • Cancel Task
      • Get Task
        GET
      • Create Task
        POST
      • Kling Virtual Try-On
        POST
    • Hailuo
      • Hailuo Director Mode Example
      • Generate Video
      • Get Task
    • Flux
      • Flux with LoRA and Controlnet
      • Available LoRA and Controlnet
      • Flux API with Redux Variation, Fill, Inpaint and Outpaint
      • Create Task
        • Text to Image
        • Image to Image
      • Get Task
    • AI Hug
      • Get Task
      • Create Task
    • LLM
      • Use Cases for GPT-4o Image API
      • How To Avoid Timeouts in Completion API
      • GPT-4o Image Generation API
      • LLM API | Basic Completions
      • Get Task
    • Midjourney
      • PiAPI Penalties on Midjourney Usage
      • Detailed Explaination on Midjourney Task Result
      • Midjourney V7 API Instructions
      • Create Task
        • Imagine
        • Upscale
        • Variation
        • Reroll
        • Describe
        • Seed
        • Blend
        • Inpaint
        • Outpaint
        • Pan
      • Cancel Task
        • Cancel Task
        • Cancel Tasks
      • Get Task
    • Faceswap
      • Multi Faceswap
      • Image Faceswap
      • Video Faceswap
      • Get Task
    • TTS
      • Zeroshot Text-to-Speech F5-TTS
      • Get Task
    • Trellis
      • Create Task
      • Get Task
    • Luma Dream Machine
      • Cancel Task
        • Cancel Tasks
        • Cancel Task
      • Create Task
      • Get Task
    • WanX
      • Available LoRA Types for Wanx
      • Generate WanX Task with LoRA Using PiAPI
      • Use Cases for Wanx LoRA
      • Create Task
      • Get Task
    • Skyreels
      • Create Task
      • Get Task
    • Framepack
      • Create Task
      • Get Task
    • Hunyuan Video
      • How to Make a Hunyuan API Call
      • Get Task
      • Generate Video
    • Mmaudio
      • Get Task
      • Generate Audio
    • DiffRhythm
      • Generate Audio
      • Get Task
    • Tools
      • File Upload API
      • Video Upscale
      • Video Upscale-Get Task
      • Remove Background API
      • Remove Background-Get Task
      • Segment With Prompt API
      • Segment With Prompt API-Get Task
      • Image Upscale(Super Resolution) API
      • Image Upscale-Get Task
    • PiAPI Account Management
      • PiAPI Account Info
      • Task List Info
      • User Task History
  • Resources
    • Change Log
    • Output Storage
    • Unified API Schema
    • Webhook
    • Bulk Generation Service
    • Billings
    • PiAPI MCP Server
    • Workspace Manual
      • Host-your-account (HYA) | Back-up Account
      • Host-your-account (HYA) | Debug Checklist
      • Host-your-account (HYA) | Connected Account Status
    • Announcements
      • PiAPI 2025 January 1st Pricing Update
  • Legacy Documentation
    • Midjourney
      • Midjourney Webhook
      • Imagine
      • Reroll
      • Upscale
      • Variation
      • Inpaint
      • Outpaint
      • Pan
      • Describe
      • Blend
      • Seed
      • Fetch
      • Multi Fetch
      • Cancel
    • Face Swap
      • Video Faceswap
      • Multi-face-swap
      • Fetch
    • Dream Machine
      • Video Generation
      • Video Extend
      • Get Video Generation
    • Kling
      • Video Generation
      • Video Extend
      • Get Video Generation
  1. Kling

Create Task

POST
/api/v1/task
This is provided as part of the Kling API from PiAPI.
This service allows you access to APIs for the most advanced video generation model - Kuaishou's KlingAI.
You can create Text-to-video, Image-to-video, Extend video, Lipsync task and Effects task through this endpoint.
INFO

Text-to-video vs Image-to-video#

1.
If the parameter image_url is left null then the task would be a text-to-video task; if filled out, then the task would be an image-to-video task.

About version 1.5 1.6 and 2.0#

The V1.5 model through the API currently has all the features and constraints as per klingai.com
pricing for 2.0: 2.0-pro-5s: USD0.96/generation, 2.0-pro-10s: USD1.92/generation

Video Lengths#

For the video lengths (5s vs 10s) of the API-generated-videos for each model (1.0 1.5 1.6 and 2.0) and modes (std vs pro) combination, please refer to what is allowed on klingai.com; the API currently aligns with the website.

Request

Header Params
x-api-key
string 
required
Your API Key used for request authorization
Body Params application/json
model
enum<string> 
required
the model name
Allowed value:
kling
task_type
enum<string> 
required
type of the task. If you want to extend video,set to extend_video and include origin_task_id filed in input; if you want lipsync, use lip_sync and include origin_task_id in input
Allowed values:
video_generationextend_videolip_synceffects
input
object 
required
the input param of the kling task, depends on the task_type .refer to the example for more details.
prompt
string 
optional
<= 2500 characters
negative_prompt
string 
optional
<= 2500 characters
cfg_scale
string 
optional
float between 0 and 1, it is strongly recommended to use 0.5
duration
enum<integer> 
optional
Allowed values:
510
aspect_ratio
enum<string> 
optional
only required in text-to-video task
Allowed values:
16:99:161:1
camera_control
object 
optional
mode
enum<string> 
optional
Allowed values:
stdpro
version
enum<string> 
optional
the model version
Allowed values:
1.01.51.62.0
image_url
string 
optional
Only required in image-to-video task. Initial frame of the video.No larger than 10MB, and each side must be greater than 300 pixels.
image_tail_url
string 
optional
End frame of the video. No larger than 10MB, and each side must be greater than 300 pixels.Need to be used with image_url.
origin_task_id
string 
optional
The task_id of the video to extend or lip_sync.
tts_text
string 
optional
The text that you want to lipsync in the video, used in lip_sync task only; will be ignored if local_dubbing_url is set
tts_speed
number 
optional
The speed of the lip_sync speech, used in lip_sync task with valid tts_textonly.
>= 0.8<= 2
Default:
1
tts_timbre
string 
optional
The voice that you want to use in lip_sync task with valid ttx_text, the full voice name list and demo list here: https://klingai.com/api/lip/sync/ttsList?type=
local_dubbing_url
string <uri>
optional
Use your audio file for lip_sync through this parameter. All tts related param will be ignored if this is set. Audio format:mp3``wav``flac``ogg, should be less than 20 MB and shorter than 60 seconds. After the audio is submitted, we will trim it to the exact length of the original video.
Example:
https://example.com/hello.mp3
motion_brush
object (motion brush) 
optional
It's highly recommended that you read our example doc before acutally use motion brush
effect
enum<string> 
optional
your choice of kling effect, see Kling Effects
Allowed values:
squishexpansion
config
object 
optional
webhook_config
object 
optional
service_mode
enum<string> 
optional
This field allows for more flexible switching between HYA and PAYG.
public->Pay As You Go(PAYG)
private->Host Your Account(HYA)
Allowed values:
publicprivate
Example
{
  "model": "kling",
  "task_type": "video_generation",
  "input": {
    "prompt": "White egrets fly over the vast paddy fields",
    "negative_prompt": "",
    "cfg_scale": 0.5,
    "duration": 5,
    "aspect_ratio": "1:1",
    "camera_control": {
      "type": "simple",
      "config": {
        "horizontal": 0,
        "vertical": 0,
        "pan": -10,
        "tilt": 0,
        "roll": 0,
        "zoom": 0
      }
    },
    "mode": "std"
  },
  "config": {
    "service_mode": "",
    "webhook_config": {
      "endpoint": "",
      "secret": ""
    }
  }
}

Request samples

Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://api.piapi.ai/api/v1/task' \
--header 'x-api-key;' \
--header 'Content-Type: application/json' \
--data-raw '{
    "model": "kling",
    "task_type": "video_generation",
    "input": {
        "prompt": "White egrets fly over the vast paddy fields",
        "negative_prompt": "",
        "cfg_scale": 0.5,
        "duration": 5,
        "aspect_ratio": "1:1",
        "camera_control": {
            "type": "simple",
            "config": {
                "horizontal": 0,
                "vertical": 0,
                "pan": -10,
                "tilt": 0,
                "roll": 0,
                "zoom": 0
            }
        },
        "mode": "std"
    },
    "config": {
        "service_mode": "",
        "webhook_config": {
            "endpoint": "",
            "secret": ""
        }
    }
}'

Responses

🟢200Success
application/json
Body
code
integer 
required
data
object 
required
task_id
string 
required
model
string 
required
task_type
string 
required
status
enum<string> 
required
Hover on the "Completed" option and you coult see the explaintion of all status: completed/processing/pending/failed/staged
Allowed values:
CompletedProcessingPendingFailedStaged
input
object 
required
output
object 
required
meta
object 
required
detail
null 
required
logs
array [object] 
required
error
object 
required
message
string 
required
If you get non-null error message, here are some steps you chould follow:
Check our common error message
Retry for several times
If you have retried for more than 3 times and still not work, file a ticket on Discord and our support will be with you soon.
Example
{
    "code": 200,
    "data": {
        "task_id": "6e269e8c-2091-46c4-b4a5-40a4704a766a",
        "model": "kling",
        "task_type": "video_generation",
        "status": "",// pending/processing/failed/completed
        "config": {
            "service_mode": "public",
            "webhook_config": {
                "endpoint": "",
                "secret": ""
            }
        },
        "input": {},
        "output": {
            "video_url": ""
        },
        "meta": {},
        "detail": null,
        "logs": [],
        "error": {
            "code": 0,
            "raw_message": "",
            "message": "",
            "detail": null
        }
    },
    "message": "success"
}
Modified at 2025-04-18 08:04:25
Previous
Get Task
Next
Kling Virtual Try-On