Skip to main content

Overview

Kling 4.0 creates videos from text, ordered keyframes, or reference materials. Use named subjects and voices to describe which materials should appear in the video.

Endpoint and authentication

Base URL: https://api.apixo.ai/api/v1. Use Authorization: Bearer YOUR_API_KEY on both endpoints. Send JSON requests with Content-Type: application/json.

Copy-paste async quickstart

A successful submission returns a task ID. Save it for subsequent status requests.

Parameters

string
default:"async"
Result delivery mode: async for polling or callback for webhook delivery.
string
Required when request_type=callback. Use a public HTTPS endpoint that can receive the final task payload. See Webhooks.
object
required
Kling 4.0 generation parameters.
All media URLs must be publicly accessible HTTP(S) URLs and remain accessible while the task runs.

Choose a mode and provide materials

Text-to-video

Provide mode=text-to-video and a prompt. Reference materials are not used in this mode.

Image-to-video with keyframes

The first image_urls entry is the first frame; a second entry is the last frame. Add chronological middle frames through keyframe_urls.

Reference-to-video

Provide at least one image, video, named subject, or voice. The four material arrays together cannot exceed 15 entries; one subject counts as one entry. This request uses only a video subject. It uses the with input video price even though video_urls is absent.

Subject and voice parameters

Each standalone voice has a required name and a publicly accessible audio_url. Voice names follow the same 1-20 character rules as subject names. Subject and voice names must be unique across the request, ignoring case. They cannot use reserved names such as image_N, video_N, keyframe_N, object_N, audio_N, first_frame, or last_frame. If a character video has speech and no separate voice is bound, its speech may be used automatically.

Mention materials in the prompt

Every mention must match a declared material. If an ASCII name is followed by another ASCII letter, digit, or underscore, they are treated as part of the name: use a space or punctuation to end the mention. When declared names share a prefix, the longest matching name is used.

Poll for result or receive a webhook

Continue polling until data.state is success or failed. A successful video is returned as a JSON string in data.resultJson:
Parse data.resultJson with JSON.parse() and read resultUrls. Failed tasks return failCode and failMsg; HTTP 200 on a status query does not by itself indicate successful generation. Task timestamps use Unix milliseconds, and costTime is elapsed milliseconds. For webhook delivery, set request_type=callback and provide callback_url when creating the task. The final payload follows the same task status structure. See Webhooks.

Billing

Prices are USD per billable second, with the same rates across modes for the same resolution and input video condition. Let D be output seconds and V the combined measured duration of all reference videos and video subjects.
  • Without input video: billable seconds = D.
  • With input video: billable seconds = D + max(D, V).
  • A video supplied only through elements[].video_url uses the with-video rate and contributes to V.
  • Images and voice references do not add billable seconds.
For example, 720p with 10 output seconds and 5 input video seconds costs 20 × $0.094 = $1.88. Reference-video quotes are estimates; final charges use measured input video durations, including fractional seconds. Do not round the reference duration to whole seconds when estimating charges. See Pricing and current API prices.

Latency and polling

Generation time varies by prompt, media inputs, output duration, resolution, and current workload. Longer clips can take several minutes. Use webhook delivery for applications that do not need frequent status updates. Back off when requests are rate limited.

Errors and troubleshooting

  • Supply a non-empty prompt and a supported mode in every request.
  • In image mode, provide 1-2 image_urls and keep the total frame count within the duration-dependent limit.
  • In reference mode, declare at least one material, respect the combined video and material limits, and use only declared prompt mentions.
  • If an input URL cannot be accessed, use a direct, publicly accessible media URL.
  • On failure, check failCode and failMsg before submitting another task. See Error Codes.