Skip to main content
Use Kling 4.0 through AnyFast API to generate or edit videos from text prompts, keyframe images, and image or video references. Kling 4.0 uses a new interface: the model name is in the request path, output settings go in settings, and general options go in options.
Use the /kling/v2/.../kling-4.0 creation endpoints shown here. Do not include model or model_name in the request body. Do not mix in Kling Legacy parameters such as mode: "std", a top-level string duration, or multi_prompt.

Key capabilities

  • Text to video — Describe the scene, people, action, camera work, and sound in a prompt.
  • Image to video — Submit a prompt and first, middle, or last frame images in contents.
  • Omni reference generation — Combine prompts, reference images, and reference videos, then assign each asset a role in the prompt using its id.
  • Video editing — Use the Omni reference endpoint with a base_video and describe what to change and preserve.
  • Asynchronous task query — Query status and results using the system task ID from the create response.

Base URL and authentication

Use https://www.anyfast.ai as the base URL. Include these request headers:
Replace YOUR_ANYFAST_API_KEY with an AnyFast API key that has access to this model.

Quick examples

Query task results

Video generation is asynchronous. A successful create response means the task was accepted, not that the video is ready. Save data.id from the create response and query it with the same AnyFast API key:
cURL
The create response’s data is an object; the query response’s data is an array. Create response example:
We recommend querying every 10–20 seconds and setting an application-level wait limit. If the limit is reached, keep the task ID and query it later; do not immediately submit the same generation request again. Successful query response example:
Select the output with type: "video" from the matching task’s outputs: The query path does not include a model name or require an upstream task ID. Result URLs may expire or include access signatures. Download and save the video soon after generation; do not treat the URL as permanent storage.

Parameters

Create request

contents asset types

Asset IDs must be unique within a task. Assign separate unique IDs to multiple middle_frame or refer_image items. The official protocol also defines element and voice asset types for referencing created characters and voices. These require the corresponding assets and management capabilities, so this page does not include asset-management examples.

Output and input limits

Output settings

When settings.aspect_ratio is specified, the output uses that ratio. With adaptive or when the field is omitted, the system first checks the prompt for an aspect-ratio request, then uses the edited video, keyframes, or other input videos to determine the ratio. If none applies, it uses 16:9. For text-to-video, an explicit settings.duration takes precedence. If omitted, the system checks the prompt for a duration request and defaults to 10 seconds when none is clear. For the Omni reference endpoint, duration is determined in this order:
  1. Explicit settings.duration.
  2. A clear duration request in the prompt.
  3. The duration of base_video.
  4. A default of 10 seconds if none of the above is available.
Submit at most one base_video to the Omni reference endpoint. The video-editing example omits settings.duration; set it to control the output length explicitly.

Input asset requirements

The following are official parameter constraints; actual availability can also depend on the connected resources. Images can be submitted by URL or supported Base64 content. Videos use URLs. The server must be able to access each URL directly and retrieve the asset file. The Omni reference endpoint also has these limits:
  • Images, videos, elements, and voices combined: up to 15 assets.
  • With no video-character elements, up to 5 reference videos.
  • With video-character elements, the combined number of video-character elements and reference videos must not exceed 5.
  • Total input-video duration includes feature reference videos, the video being edited, and video-character elements.

Prompt length

These limits apply to the text-to-video prompt or the prompt item’s text in contents:

Prompting tips

Describe the following in order:
You can describe multiple shots directly in the prompt. Prompts state the intended result; exact action timing and shot cuts are not guaranteed. We recommend explicitly setting settings.duration to control output length and cost.

General options

  • external_task_id does not replace the system task ID or guarantee duplicate-charge prevention.
  • This guide uses data.id from the create response to query tasks; callbacks and external-ID queries are not required.

API Reference

View Kling 4.0 request and response fields for each capability.