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. - The
camera_control
,aspect_ratio
parameters are only accepted for text-to-video tasks, not for image-to-video tasks.
About v1.5
The V1.5 model currently has the following restrictions:
- Only supports video generation in Professional Mode.
- Only support 5s generation not 10s.
- "Image to video" task does not support
image_tail_url
parameter. - Generated videos do not support Extend.
:::
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"
}