Create Task
POST
/api/v1/taskThis 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 through this endpoint.
:::info
Text-to-video vs Image-to-video
- 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 v1.5 and v1.6
The V1.5 model through the API currently has all the features and constraints as per klingai.com
Video Lengths
For the video lengths (5s vs 10s) of the API-generated-videos for each model (1.0 1.5 and 1.6) and modes (std vs pro) combination, please refer to what is allowed on klingai.com; the API currently aligns with the website.
:::
Request
Your API Key used for request authorization
the model name
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
the input param of the kling task, depends on the task_type
.refer to the example for more details.
float between 0 and 1
only required in text-to-video task
the model version
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.
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
.
The task_id of the video to extend or lip_sync.
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
The speed of the lip_sync speech, used in lip_sync
task with valid tts_text
only.
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=
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.
It's highly recommended that you read our example doc before acutally use motion brush
This field allows for more flexible switching between HYA and PAYG.
public
->Pay As You Go(PAYG)
private
->Host Your Account(HYA)
{
"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
Responses
{
"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"
}