Kwaivgi Kling V4.0 Video Edit API Documentation
Playground
Try it on WaveSpeedAI!Kling V4.0 Video Edit rewrites a 3 to 30 second video from a text instruction: it keeps the scene, subject and motion and changes what you describe, with optional reference images, 720p and 1080p output and the original sound kept by default. Ready-to-use REST inference API, best performance, no coldstarts, affordable pricing.
Features
Kling V4.0 Video Edit rewrites a video from a text instruction. It keeps the scene, the subject and the motion of your video and changes what you describe: swap a character, change the setting or the weather, restyle the look. The result is a clip of 3 to 30 seconds at 720p or 1080p, and the original sound is kept by default.
Why Choose This?
- Edit by instruction Describe the change in plain language; everything you do not mention stays as it was.
- Follows your footage The output keeps the source video’s length and aspect ratio unless you choose otherwise, up to 30 seconds.
- Original sound kept Your video’s own sound is carried over by default; turn it off to generate new synchronized audio.
- Reference images Add up to 10 images to bring a specific subject, object or style into the edit.
Pricing
Each counted second costs $0.094 at 720p and $0.141 at 1080p. The counted seconds are the output length plus the longer of the output length and the input video’s length (3 to 30 seconds each).
When the output follows the input video, this is $0.188 per second of video at 720p and $0.282 at 1080p. For example, editing a 5 second clip at 720p costs $0.94.
Parameters
| Parameter | Description |
|---|---|
| video | Required. The video to edit. 3 to 30 seconds; longer videos are trimmed to 30 seconds. |
| prompt | Required. The edit to apply. Refer to the video as @Video1 and to reference images as @Image1, @Image2 … in array order. |
| images | Optional reference images, up to 10. |
| keep_original_sound | Keep the input video’s own sound (default true). When false, new synchronized audio is generated. |
| resolution | 720p (default) or 1080p. |
| duration | Output length in seconds, 3 to 30. Follows the input video if not set. |
| aspect_ratio | 16:9, 9:16, 1:1 or 21:9. Follows the input video if not set. |
Prompting Guide
- Describe the change, not the whole scene: “replace the man with a silver robot, keep the room and the lighting”.
- Name what must stay: the camera move, the setting, the action.
- With reference images, say what each one is for: “dress the character in the jacket from @Image1”.
- Use a clear source video with a visible subject; busy footage gives less predictable edits.
Authentication
For authentication details, please refer to the Authentication Guide.
API Endpoints
Submit Task & Query Result
set -euo pipefail
export WAVESPEED_API_KEY="your-api-key"
REQUEST_BODY=$(cat <<'JSON'
{
"prompt": "A cinematic ocean wave at sunrise, highly detailed",
"video": "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4",
"keep_original_sound": true,
"resolution": "720p",
"duration": 3,
"aspect_ratio": "16:9"
}
JSON
)
# 1. Submit the prediction once. Never retry this request automatically:
# a retry after an unclear failure can create a second, billed task.
CHECK='The task may already exist. Check History or the predictions list before submitting again.'
if ! SUBMIT_RESPONSE=$(curl --silent --show-error --fail-with-body \
--connect-timeout 10 --max-time 60 \
-X POST "https://api.wavespeed.ai/api/v3/kwaivgi/kling-v4.0/video-edit" \
-H "Authorization: Bearer ${WAVESPEED_API_KEY}" \
-H "Content-Type: application/json" \
-d "${REQUEST_BODY}"); then
printf 'Submit failed. %s\n' "${CHECK}" >&2
exit 1
fi
TASK=$(printf '%s' "${SUBMIT_RESPONSE}" | jq 'if type == "object" and has("data") then .data else . end')
PREDICTION_ID=$(printf '%s' "${TASK}" | jq -r '.id // empty')
if [ -z "${PREDICTION_ID}" ]; then
printf 'Submission response did not contain a prediction id. %s\n' "${CHECK}" >&2
exit 1
fi
RESULT_URL="https://api.wavespeed.ai/api/v3/predictions/${PREDICTION_ID}/result"
# 2. Poll until the prediction reaches a final status.
BODY_FILE=$(mktemp)
trap 'rm -f "${BODY_FILE}"' EXIT
while true; do
# Transient errors (429, 5xx) are retried, honoring Retry-After.
HTTP_CODE=$(curl --silent --show-error --fail-with-body \
--connect-timeout 10 --max-time 60 --retry 5 --retry-delay 2 \
--output "${BODY_FILE}" --write-out '%{http_code}' \
"${RESULT_URL}" \
-H "Authorization: Bearer ${WAVESPEED_API_KEY}" || true)
case "${HTTP_CODE}" in
2??) ;;
000|429|5??) # dropped connection or temporary error: keep polling
printf 'Task %s: HTTP %s, polling again in 10s\n' "${PREDICTION_ID}" "${HTTP_CODE}" >&2
sleep 10; continue ;;
*) printf 'Task %s: HTTP %s\n' "${PREDICTION_ID}" "${HTTP_CODE}" >&2
cat "${BODY_FILE}" >&2; exit 1 ;;
esac
RESULT=$(jq 'if type == "object" and has("data") then .data else . end' "${BODY_FILE}")
STATUS=$(printf '%s' "${RESULT}" | jq -r '.status // empty')
case "${STATUS}" in
completed) printf '%s\n' "${RESULT}" | jq '.outputs'; break ;;
failed|cancelled|timeout|deleted)
printf 'Task %s ended with status %s\n' "${PREDICTION_ID}" "${STATUS}" >&2
printf '%s\n' "${RESULT}" | jq . >&2; exit 1 ;;
*) sleep 2 ;;
esac
doneRetry temporary errors only while polling, never the submit request. Errors, retries and timeouts
Parameters
Task Submission Parameters
Request Parameters
| Parameter | Type | Required | Default | Range | Description |
|---|---|---|---|---|---|
| prompt | string | Yes | - | Describe the edit you want applied to the video - change a subject, the setting, the weather or the style. Refer to the video as @Video1 and to reference images as @Image1, @Image2, ... in array order. | |
| video | string | Yes | - | URL of the video to edit. The edit keeps its scene, subject and motion; 3-30 seconds, longer videos are trimmed to 30 seconds. | |
| images | array<string> | No | - | 0 ~ 10 items | Optional reference images (up to 10) for a subject, object or style to bring into the edit. |
| keep_original_sound | boolean | No | true | - | Keep the input video's own sound. When false, new synchronized audio is generated instead. |
| resolution | string | No | 720p | 720p, 1080p | Output resolution. |
| duration | integer | No | - | 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 | Output duration in seconds (3-30). Follows the input video's length if not specified. |
| aspect_ratio | string | No | - | 16:9, 9:16, 1:1, 21:9 | Aspect ratio of the output video. Follows the input video if not specified. |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| code | integer | HTTP status code (e.g., 200 for success) |
| message | string | Status message (e.g., “success”) |
| data.id | string | Unique identifier for the prediction, Task Id |
| data.model | string | Model ID used for the prediction |
| data.outputs | array | Output values, usually URL strings; some models return text strings or structured result objects (empty when status is not completed) |
| data.urls | object | Object containing related API endpoints |
| data.status | string | Task status. completed is successful; failed, cancelled, timeout, and deleted are failure terminal statuses. |
| data.created_at | string | ISO timestamp of when the request was created (e.g., “2023-04-01T12:34:56.789Z”) |
| data.error | string | Error message (empty if no error occurred) |
| data.timings | object | Object containing timing details |
| data.timings.inference | integer | Inference time in milliseconds |
Result Request Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| id | string | Yes | - | Task ID |
Result Response Parameters
| Parameter | Type | Description |
|---|---|---|
| code | integer | HTTP status code (e.g., 200 for success) |
| message | string | Status message (e.g., “success”) |
| data | object | The prediction data object containing all details |
| data.id | string | Unique identifier for the prediction |
| data.model | string | Model ID used for the prediction |
| data.outputs | array<string | object> | Array of generated outputs (empty when status is not completed). Items are usually URL strings, but may be text strings or structured result objects, depending on the model. |
| data.urls | object | Object containing related API endpoints |
| data.status | string | Status: completed is successful; failed, cancelled, timeout, and deleted are failure terminal statuses |
| data.created_at | string | ISO timestamp of when the request was created |
| data.error | string | Error message (empty if no error occurred) |
| data.timings | object | Object containing timing details |
| data.timings.inference | integer | Inference time in milliseconds |