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.
:::info
HYA vs PAYG
(What is HYA (Host-Your-Account) vs PAYG (Pay-As-You-Go)? Click here to learn more.)
The difference between using Kling API under the HYA (Host-your-Account) service option vs. the PAYG (Pay-as-you-go) service option are the following:
For this API, HYA user has access to the following parameters but PAYG user does not:
- version (valid values are "1.0" or "1.5")
- professional mode (valid values are "true" or "false")
- extend
For this API, PAYG user has access to the following parameters but HYA user does not:
- mode (valid values are "std" or "pro")
For parameter "service mode"
This allows users to choose whether this specific task will get processed under PAYG or HYA mode. If unspecified, then this task will get processed under whatever mode (PAYG or HYA) the user chose on the workspace setting of your account.public
means this task will be processed under PAYG mode.private
means this task will be processed under HYA modeText-to-video vs Image-to-video
For parameter
image_url
, if 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
parameter is only available in text-to-video task not image-to-video task.
:::
Request
Your API Key used for request authorization
the model name
type of the task
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
only HYA users have access
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
.
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": "public",
"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"
}