Skip to Content
Video ModelsKling 4.0

Kling 4.0

Overview

Kling 4.0 is Kuaishou’s AI video model for professional video creation. It delivers realistic motion and synchronized audio, with up to 30s video in 720p and 1080p

Test API KEY: key_00000000000000000000000000000000

Endpoints

1. Create Task

Request

POST https://api.pixwithapi.online/api/task/create

Headers

HeaderValueRequired
Content-Typeapplication/jsonYes
Api-Key{API_KEY}Yes

Request Parameters

ParameterTypeRequiredDescription
model_idstringYes2-99.
promptstringYesVideo description, 1–8,000 characters. Use @first_frame and @last_frame to refer to the supplied frames.
image_urlsarray of URLsNoOmit or pass [] for text-to-video. For image-to-video, provide one start-frame image or two ordered start/end-frame images. JPG, JPEG, PNG, or WebP, up to 10 MiB per image.
optionsobjectNoOmitted fields use the defaults below.
options.resolutionstringNo720P or 1080P. Default: 720P.
options.durationintNoAny whole number from 3 through 30 seconds. Default: 5.
options.aspect_ratiostringNoText-to-video only: 16:9, 9:16, 1:1, 21:9, or Auto. Default: 16:9. Ignored when frame images are provided.
options.prompt_optimizationbooleanNoOptimize the prompt before generation. Default: false.

Without images, the request generates a video from text. With images, the output aspect ratio follows the input frame. A sound option is not exposed. Each API request produces one video.

Example Request — Text to Video

{ "model_id": "2-99", "prompt": "An orange ball rolls slowly across a blue background, fixed camera", "options": { "resolution": "720P", "duration": 5, "aspect_ratio": "16:9", "prompt_optimization": false } }

Example Request — Start and End Frames

{ "model_id": "2-99", "prompt": "The character walks from the scene in @first_frame to the scene in @last_frame", "image_urls": [ "https://media.example.com/start.jpg", "https://media.example.com/end.png" ], "options": { "resolution": "1080P", "duration": 10, "prompt_optimization": false } }

Response Parameters

ParameterTypeDescription
codeint1 for success, 0 for error.
messagestringSuccess or failure message.
data.task_idstringTask identifier for querying the result.
data.estimated_timeintEstimated generation time in seconds.

Response

{ "code": 1, "message": "success", "data": { "task_id": "d425ab4dc256f0ebaa84862b9cea8a3d", "estimated_time": 500 } }

2. Create Task With R2V

Use the same endpoint and headers as above.

Request Parameters

ParameterTypeRequiredDescription
model_idstringYes2-100.
promptstringYesVideo description, 1–8,000 characters. Reference images as @image_1, @image_2, etc.; videos as @video_1, @video_2, etc.; voices as @Voice1, @Voice2, or @Voice3.
reference_urlsobjectYesOrdered reference media URL arrays.
reference_urls.reference_imagesarray of URLsYes1–10 JPG, JPEG, PNG, or WebP images, up to 10 MiB each. At least one image is required
reference_urls.reference_videosarray of URLsNo0–5 MP4 or MOV videos, up to 10 MiB each. Each video must be 5–30 seconds; their actual combined duration must not exceed 30 seconds.
reference_urls.reference_audiosarray of URLsNo0–3 MP3 or WAV voice samples, 5–30 seconds and up to 15 MiB each. Names are assigned automatically by array position: Voice1, Voice2, Voice3.
optionsobjectNoOmitted fields use the defaults below.
options.resolutionstringNo720P or 1080P. Default: 720P.
options.durationintNoAny whole number from 3 through 30 seconds. Default: 5.
options.aspect_ratiostringNoAuto, 16:9, 9:16, 1:1, or 21:9. Default: Auto.
options.soundbooleanNoGenerate a new soundtrack instead of retaining reference-video audio. true disables retention; false retains it (default). Without a reference video, native audio is generated automatically.
options.prompt_optimizationbooleanNoOptimize the prompt before generation. Default: true.

Images, videos, and voices together must not exceed 15 materials. All reference URLs must be publicly downloadable HTTPS URLs with a supported path extension. Optional arrays may be omitted or set to []; do not pass null. The order of each array determines its prompt references. Elements and custom voice names are not supported. Only include references to materials supplied in the request.

Example Request

{ "model_id": "2-100", "prompt": "The person in @image_1 follows the camera movement in @video_1 and greets the viewer using @Voice1", "reference_urls": { "reference_images": ["https://media.example.com/person.jpg"], "reference_videos": ["https://media.example.com/motion.mp4"], "reference_audios": ["https://media.example.com/voice.wav"] }, "options": { "resolution": "720P", "duration": 10, "aspect_ratio": "16:9", "sound": false, "prompt_optimization": false } }

Response

{ "code": 1, "message": "success", "data": { "task_id": "d425ab4dc256f0ebaa84862b9cea8a3d" } }

This response confirms acceptance for asynchronous media preparation. It does not include estimated_time or confirm that generation has started. Preparation failures can be retrieved using the same task ID. Preparation that exceeds 10 minutes is cancelled; this is not a limit on generation time.

3. Get Task Status & Results

Call POST /api/task/get with the returned task_id. Public status values are 1 for processing, 2 for completed, and 3 for failed. Completed tasks include result_urls; preparation failures or cancellations include error_code and error_message when available.

See Get Task Status & Results for the complete request and response format.

Last updated on