> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyfast.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Kling 4.0

> Kling 4.0 video generation and editing API through AnyFast.

Kling 4.0 uses capability-specific creation paths. The model name is part of each path; do not send `model` or `model_name` in the request body. Configure output with `settings` and general options with `options`.

> [tab] Text to video
>
> ## Create task
>
> `POST /kling/v2/text-to-video/kling-4.0`
>
> ```bash cURL theme={null}
> curl --request POST \
>   --url 'https://www.anyfast.ai/kling/v2/text-to-video/kling-4.0' \
>   --header 'Authorization: Bearer YOUR_ANYFAST_API_KEY' \
>   --header 'Content-Type: application/json' \
>   --data '{
>     "prompt": "A red car drives in rain as the camera pans right. Realistic style, natural sound.",
>     "settings": {
>       "resolution": "720p",
>       "aspect_ratio": "21:9",
>       "duration": 3
>     },
>     "options": {
>       "watermark_info": {
>         "enabled": false
>       }
>     }
>   }'
> ```
>
> ## Request headers
>
> **Authorization** `string` *required*
>
> Bearer authentication. Use `Bearer YOUR_ANYFAST_API_KEY`.
>
> **Content-Type** `string` *required* (default: application/json)
>
> Request body format.
>
> ## Request body
>
> **prompt** `string` *required*
>
> Video description. You can include both desired and unwanted content. Prompt limits depend on character type; see the prompt length section.
>
> **settings** `object`
>
> Output resolution, duration, and aspect ratio.
>
> **settings.resolution** `string`
>
> `720p` or `1080p`. Explicitly setting a value is recommended.
>
> **settings.duration** `integer`
>
> Integer from 3 to 30 seconds. Explicitly setting a value is recommended. If omitted, the prompt duration is used when clear; otherwise the default is 10 seconds.
>
> **settings.aspect\_ratio** `string`
>
> `21:9`, `16:9`, `9:16`, or `1:1`. `adaptive` is also supported by the shared output settings.
>
> **options** `object`
>
> General task options.
>
> **options.watermark\_info.enabled** `boolean` (default: false)
>
> Whether to additionally generate a watermarked version.
>
> **options.external\_task\_id** `string`
>
> Caller-defined task identifier. Keep it unique within the current user scope. It does not replace the system task ID or guarantee duplicate-charge prevention.
>
> **options.callback\_url** `string`
>
> Task-status callback URL defined by the official protocol. Confirm support on the current channel before use.
>
> ## Create response
>
> ```json 200 theme={null}
> {
>   "code": 0,
>   "message": "",
>   "request_id": "REQUEST_ID",
>   "data": {
>     "id": "asyntask_EXAMPLE",
>     "status": "submitted",
>     "create_time": 1793672435967,
>     "update_time": 1793672435967,
>     "external_id": ""
>   }
> }
> ```
>
> **code** `integer`
>
> Business status code; the success example is `0`.
>
> **message** `string`
>
> API message.
>
> **request\_id** `string`
>
> Request tracing identifier, when returned.
>
> **data.id** `string`
>
> System task ID. Save it for querying.
>
> **data.status** `string`
>
> Current task status.
>
> **data.create\_time** `integer`
>
> Creation time as a Unix timestamp in milliseconds.
>
> **data.update\_time** `integer`
>
> Update time as a Unix timestamp in milliseconds.
>
> **data.external\_id** `string`
>
> Caller-defined task ID; may be empty if unset.

> [tab] Image to video
>
> ## Create task
>
> `POST /kling/v2/image-to-video/kling-4.0`
>
> ```bash cURL theme={null}
> curl --request POST \
>   --url 'https://www.anyfast.ai/kling/v2/image-to-video/kling-4.0' \
>   --header 'Authorization: Bearer YOUR_ANYFAST_API_KEY' \
>   --header 'Content-Type: application/json' \
>   --data '{
>     "contents": [
>       {
>         "type": "prompt",
>         "text": "Start from @start. Preserve identity; the person smiles and raises a hand in a breeze."
>       },
>       {
>         "type": "first_frame",
>         "url": "https://example.com/first-frame.jpg",
>         "id": "start"
>       }
>     ],
>     "settings": {
>       "resolution": "720p",
>       "duration": 3
>     },
>     "options": {
>       "watermark_info": {
>         "enabled": false
>       }
>     }
>   }'
> ```
>
> ## Request headers
>
> **Authorization** `string` *required*
>
> Bearer authentication. Use `Bearer YOUR_ANYFAST_API_KEY`.
>
> **Content-Type** `string` *required* (default: application/json)
>
> Request body format.
>
> ## Request body
>
> **contents** `object[]` *required*
>
> Prompt and keyframe images. Include a `prompt` item. Image input supports up to 10 images.
>
> **contents\[].type** `string` *required*
>
> Use `prompt`, `first_frame`, `middle_frame`, or `last_frame` for this workflow.
>
> **contents\[].text** `string`
>
> Prompt text when `type` is `prompt`. Use an asset ID as `@id` to reference an image in the prompt.
>
> **contents\[].url** `string`
>
> Publicly accessible image URL, or a supported Base64 image value.
>
> **contents\[].id** `string`
>
> Optional unique asset ID used by the prompt. IDs must not repeat within a task.
>
> **settings** `object`
>
> Output settings.
>
> **settings.resolution** `string`
>
> `720p` or `1080p`.
>
> **settings.duration** `integer`
>
> Integer from 3 to 30 seconds.
>
> **settings.aspect\_ratio** `string`
>
> Optional output ratio. For keyframe input, use images with the intended composition; the example omits this field.
>
> **options.watermark\_info.enabled** `boolean` (default: false)
>
> Whether to additionally generate a watermarked version.
>
> **options.external\_task\_id** `string`
>
> Optional caller-defined task ID. It does not replace the system task ID or guarantee duplicate-charge prevention.
>
> **options.callback\_url** `string`
>
> Optional callback URL; confirm current-channel support before use.
>
> ## Create response
>
> ```json 200 theme={null}
> {
>   "code": 0,
>   "message": "",
>   "request_id": "REQUEST_ID",
>   "data": {
>     "id": "asyntask_EXAMPLE",
>     "status": "submitted",
>     "create_time": 1793672435967,
>     "update_time": 1793672435967,
>     "external_id": ""
>   }
> }
> ```
>
> **data.id** `string`
>
> System task ID. Save it for querying.
>
> **data.status** `string`
>
> Initial task status, such as `submitted`.
>
> **data.create\_time** `integer`
>
> Creation Unix timestamp in milliseconds.
>
> **data.update\_time** `integer`
>
> Update Unix timestamp in milliseconds.
>
> ### Keyframe types
>
> | Type | Use | Fields |
> | - | - | - |
> | `prompt` | Describe action, camera, and sound | `text` |
> | `first_frame` | First-frame image | `url`, optional `id` |
> | `middle_frame` | Intermediate keyframe | `url`, optional `id` |
> | `last_frame` | Last-frame image | `url`, optional `id` |
>
> Assign unique IDs when the prompt needs to reference keyframes. Up to 10 images are supported. Image requirements are listed in the Input requirements tab.

> [tab] Omni reference
>
> ## Create task
>
> `POST /kling/v2/omni-video/kling-4.0`
>
> ```bash cURL theme={null}
> curl --request POST \
>   --url 'https://www.anyfast.ai/kling/v2/omni-video/kling-4.0' \
>   --header 'Authorization: Bearer YOUR_ANYFAST_API_KEY' \
>   --header 'Content-Type: application/json' \
>   --data '{
>     "contents": [
>       {
>         "type": "prompt",
>         "text": "Preserve @actor identity; use @motion pacing in a bright studio."
>       },
>       {
>         "type": "refer_image",
>         "url": "https://example.com/character.jpg",
>         "id": "actor"
>       },
>       {
>         "type": "feature_video",
>         "url": "https://example.com/motion.mp4",
>         "id": "motion"
>       }
>     ],
>     "settings": {
>       "resolution": "720p",
>       "aspect_ratio": "1:1",
>       "duration": 3
>     },
>     "options": {
>       "watermark_info": {
>         "enabled": false
>       }
>     }
>   }'
> ```
>
> ## Request headers
>
> **Authorization** `string` *required*
>
> Bearer authentication. Use `Bearer YOUR_ANYFAST_API_KEY`.
>
> **Content-Type** `string` *required* (default: application/json)
>
> Request body format.
>
> ## Request body
>
> **contents** `object[]` *required*
>
> Prompt and reference assets. Include a prompt item. Asset IDs must be unique within a task.
>
> **contents\[].type** `string` *required*
>
> Use `prompt`, `refer_image`, `first_frame`, `middle_frame`, `last_frame`, `feature_video`, or `base_video`.
>
> **contents\[].text** `string`
>
> Prompt text for a `prompt` item. Use `@id` to specify how a reference asset should be used.
>
> **contents\[].url** `string`
>
> Publicly accessible URL for an image or video asset. Images may also use supported Base64 content.
>
> **contents\[].id** `string`
>
> Unique asset ID used to reference an item from the prompt.
>
> **settings** `object`
>
> Output settings.
>
> **settings.resolution** `string`
>
> `720p` or `1080p`.
>
> **settings.duration** `integer`
>
> Integer from 3 to 30 seconds. If omitted, use prompt duration, then `base_video` duration, then default to 10 seconds.
>
> **settings.aspect\_ratio** `string`
>
> `21:9`, `16:9`, `9:16`, `1:1`, or `adaptive`.
>
> **options.watermark\_info.enabled** `boolean` (default: false)
>
> Whether to additionally generate a watermarked version.
>
> **options.external\_task\_id** `string`
>
> Optional caller-defined task ID. It does not replace the system task ID or guarantee duplicate-charge prevention.
>
> **options.callback\_url** `string`
>
> Optional callback URL; confirm current-channel support before use.
>
> ## Create response
>
> ```json 200 theme={null}
> {
>   "code": 0,
>   "message": "",
>   "request_id": "REQUEST_ID",
>   "data": {
>     "id": "asyntask_EXAMPLE",
>     "status": "submitted",
>     "create_time": 1793672435967,
>     "update_time": 1793672435967,
>     "external_id": ""
>   }
> }
> ```
>
> **data.id** `string`
>
> System task ID. Save it for querying.
>
> **data.status** `string`
>
> Initial task status, such as `submitted`.
>
> **data.create\_time** `integer`
>
> Creation Unix timestamp in milliseconds.
>
> **data.update\_time** `integer`
>
> Update Unix timestamp in milliseconds.
>
> ### Reference content types
>
> | Type | Use | Main fields |
> | - | - | - |
> | `prompt` | Describe generation or editing requirements | `text` |
> | `refer_image` | Appearance, scene, or style reference | `url`, `id` |
> | `first_frame` | First-frame constraint | `url`, `id` |
> | `middle_frame` | Intermediate keyframe constraint | `url`, `id` |
> | `last_frame` | Last-frame constraint | `url`, `id` |
> | `feature_video` | Motion or other feature reference | `url`, `id` |
> | `base_video` | Source video for editing | `url`, `id` |
>
> The protocol also defines `element` and `voice` assets for previously created characters and voices. These require corresponding assets and management capabilities; this reference does not describe those management APIs.
>
> ### Duration selection
>
> Duration is determined in this order: explicit `settings.duration`, clear duration intent in the prompt, `base_video` duration, then the 10-second default. Submit at most one `base_video`.

> [tab] Video editing
>
> ## Create task
>
> `POST /kling/v2/omni-video/kling-4.0`
>
> Submit the source clip as `base_video`. Describe both the change and the content that should remain unchanged.
>
> ```bash cURL theme={null}
> curl --request POST \
>   --url 'https://www.anyfast.ai/kling/v2/omni-video/kling-4.0' \
>   --header 'Authorization: Bearer YOUR_ANYFAST_API_KEY' \
>   --header 'Content-Type: application/json' \
>   --data '{
>     "contents": [
>       {
>         "type": "prompt",
>         "text": "Edit @base: change the red cup to blue; preserve everything else."
>       },
>       {
>         "type": "base_video",
>         "url": "https://example.com/source-video.mp4",
>         "id": "base"
>       }
>     ],
>     "settings": {
>       "resolution": "720p",
>       "aspect_ratio": "adaptive"
>     },
>     "options": {
>       "watermark_info": {
>         "enabled": false
>       }
>     }
>   }'
> ```
>
> ## Request headers
>
> **Authorization** `string` *required*
>
> Bearer authentication. Use `Bearer YOUR_ANYFAST_API_KEY`.
>
> **Content-Type** `string` *required* (default: application/json)
>
> Request body format.
>
> ## Request body
>
> **contents** `object[]` *required*
>
> Prompt and source video. Include a prompt item and at most one `base_video` item.
>
> **contents\[].type** `string` *required*
>
> Use `prompt` and `base_video` for this editing example. Other Omni reference asset types are listed in the Omni reference tab.
>
> **contents\[].text** `string` *required*
>
> Describe what to change and what to preserve. Use `@id` to refer to the source video.
>
> **contents\[].url** `string` *required*
>
> Publicly accessible source-video URL.
>
> **contents\[].id** `string` *required*
>
> Unique asset ID referenced by the prompt.
>
> **settings.resolution** `string`
>
> `720p` or `1080p`.
>
> **settings.aspect\_ratio** `string`
>
> Set `adaptive` to determine the ratio from the prompt or input video.
>
> **settings.duration** `integer`
>
> Optional integer from 3 to 30 seconds. If omitted, duration follows explicit prompt intent, then the source video, then defaults to 10 seconds.
>
> **options.watermark\_info.enabled** `boolean` (default: false)
>
> Whether to additionally generate a watermarked version.
>
> **options.external\_task\_id** `string`
>
> Optional caller-defined task ID. It does not replace the system task ID or guarantee duplicate-charge prevention.
>
> **options.callback\_url** `string`
>
> Optional callback URL; confirm current-channel support before use.
>
> ## Create response
>
> ```json 200 theme={null}
> {
>   "code": 0,
>   "message": "",
>   "request_id": "REQUEST_ID",
>   "data": {
>     "id": "asyntask_EXAMPLE",
>     "status": "submitted",
>     "create_time": 1793672435967,
>     "update_time": 1793672435967,
>     "external_id": ""
>   }
> }
> ```
>
> **data.id** `string`
>
> System task ID. Save it for querying.
>
> **data.status** `string`
>
> Initial task status.
>
> **data.create\_time** `integer`
>
> Creation Unix timestamp in milliseconds.
>
> **data.update\_time** `integer`
>
> Update Unix timestamp in milliseconds.
>
> Set `settings.duration` when you need to control the output length. The example omits it so the source video duration is used when no explicit duration intent is present in the prompt.

> [tab] Query task
>
> ## Query tasks
>
> `GET /kling/v2/tasks?task_ids=YOUR_TASK_ID`
>
> Use the system task ID from the create response's `data.id`. Query with the same AnyFast API key used to create the task. The query path does not require a model name or upstream task ID.
>
> ```bash cURL theme={null}
> curl --request GET \
>   --url 'https://www.anyfast.ai/kling/v2/tasks?task_ids=YOUR_TASK_ID' \
>   --header 'Authorization: Bearer YOUR_ANYFAST_API_KEY'
> ```
>
> ## Query response
>
> ```json 200 theme={null}
> {
>   "code": 0,
>   "message": "",
>   "data": [
>     {
>       "id": "asyntask_EXAMPLE",
>       "status": "succeeded",
>       "create_time": 1793672435967,
>       "update_time": 1793672563000,
>       "outputs": [
>         {
>           "type": "video",
>           "url": "https://example.com/generated-video.mp4",
>           "duration": "3.042"
>         }
>       ]
>     }
>   ]
> }
> ```
>
> ## Response fields
>
> **code** `integer`
>
> Business status code; the success example is `0`.
>
> **message** `string`
>
> API message.
>
> **data** `object[]`
>
> Task records matching the supplied task IDs. The query response uses an array; the create response uses an object.
>
> **data\[].id** `string`
>
> System task ID.
>
> **data\[].status** `string`
>
> `submitted`, `processing`, `succeeded`, or `failed`.
>
> **data\[].create\_time** `integer`
>
> Creation Unix timestamp in milliseconds.
>
> **data\[].update\_time** `integer`
>
> Last-update Unix timestamp in milliseconds.
>
> **data\[].outputs** `object[]`
>
> Generated outputs, available when the task succeeds.
>
> **data\[].outputs\[].type** `string`
>
> Output type. Select `video` for the generated video.
>
> **data\[].outputs\[].url** `string`
>
> Video result URL.
>
> **data\[].outputs\[].duration** `string`
>
> Actual duration in seconds; may be a decimal string.
>
> **data\[].outputs\[].watermark\_url** `string`
>
> Watermarked result URL, present only when provided.
>
> Query every 10–20 seconds and set an application-level wait limit. If the limit is reached, keep the task ID and query it later; do not immediately resubmit the same generation request. Download result URLs soon after generation because they may expire or include access signatures.

> [tab] Input requirements
>
> ## Image requirements
>
> | Property | Requirement |
> | - | - |
> | Formats | JPG, JPEG, PNG |
> | Maximum size | 30 MB per image |
> | Dimensions | At least 300 px wide and 300 px high |
> | Aspect ratio | 2:5–5:2 |
> | Count | Up to 10 images |
>
> Images can be submitted by URL or supported Base64 content. URLs must be directly accessible to the service and return the image file.
>
> ## Video requirements
>
> | Property | Requirement |
> | - | - |
> | Formats | MP4, MOV |
> | Maximum size | 300 MB per video |
> | Duration | Each video and total input-video duration must be 3–30 seconds |
> | Dimensions | 700–4553 px wide and high; up to 8,294,400 total pixels |
> | Aspect ratio | 2:5–5:2 |
> | Input frame rate | 24–60 fps |
> | Output frame rate | 24 fps |
>
> Videos use URLs. The service must be able to access each URL directly and retrieve the video file.
>
> ## Omni reference 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.
> * Submit at most one `base_video` per task.
>
> ## Prompt length
>
> The limits apply to a text-to-video `prompt` or the prompt item's `text` in `contents`:
>
> | Text | Limit |
> | - | -: |
> | English only | 26,000 characters |
> | Non-English only | 11,000 characters |
> | Mixed text | English characters ÷ 26,000 + non-English characters ÷ 11,000 ≤ 1 |

> [!NOTE]
>
> Creation is asynchronous. A successful create response means the task was accepted; query the returned `data.id` to retrieve its status and result.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.