- Get Started
- Endpoints
- Flux
- AI Hug
- LLM
- Midjourney
- Faceswap
- TTS
- Song(Suno+Udio)
- Trellis
- Luma Dream Machine
- Kling
- Hailuo
- Skyreels
- WanX
- Hunyuan Video
- PiAPI Account Management
- Mmaudio
- DiffRhythm
- Tools
- Resources
- Legacy Documentation
Create Task
POST
https://api.piapi.ai/api/v1/task
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.
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#
Video Lengths#
Request
Header Params
x-api-key
string
required
Body Params application/json
model
enum<string>
required
Allowed value:
kling
task_type
enum<string>
required
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
task_type
.refer to the example for more details.prompt
string
optional
<= 2500 characters
negative_prompt
string
optional
<= 2500 characters
cfg_scale
string
optional
duration
enum<integer>
optional
Allowed values:
510
aspect_ratio
enum<string>
optional
Allowed values:
16:99:161:1
camera_control
object
optional
mode
enum<string>
optional
Allowed values:
stdpro
version
enum<string>
optional
Allowed values:
1.01.51.6
image_url
string
optional
image_tail_url
string
optional
image_url
.origin_task_id
string
optional
tts_text
string
optional
lip_sync
task only; will be ignored if local_dubbing_url
is settts_speed
number
optional
lip_sync
task with valid tts_text
only.>= 0.8<= 2
Default:
1
tts_timbre
string
optional
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
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
effect
enum<string>
optional
Allowed values:
squishexpansion
config
object
optional
webhook_config
object
optional
service_mode
enum<string>
optional
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
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
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-02-19 09:34:47