Video Edit
Change an existing video as your prompt says, optionally with reference images and videos (Kling 4.0 video_edit).
Kling 4.0 changes an existing video as your prompt says, for example replacing an object or changing the style, optionally with reference images and reference videos.
Create a task
https://api.nanoapi.ai/v1/tasksUse the shared create endpoint with model: "kling-4.0". It usually responds in under 1 second and the cost is frozen within a few seconds; the video usually takes 1–5 minutes. Get the result once the task has finished.
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <API key>, see Authentication. |
Content-Type | Yes | application/json |
Idempotency-Key | No | A unique string for every new task, ideally a UUID (1–255 characters). See Preventing duplicate tasks. |
Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | kling-4.0. |
mode | string | Yes | video_edit. |
video_url | string | Yes | The video to edit: 3–30 seconds, 720p or higher (at least 720 pixels on its short side), aspect ratio at most 2.5:1, see Media. An http(s) link of at most 4096 characters that can be downloaded directly, not a private address. |
prompt | string | Yes | How to change it, at most 8000 characters. Refer to the files as @Video1 (the video to edit), @Video2 on (the reference videos) and @Image1 on, see Referring to files. |
image_urls | string[] | No | Up to 10 reference images (for example the object to put in). Each is an http(s) link of at most 4096 characters that can be downloaded directly, not a private address. |
video_urls | string[] | No | Up to 4 reference videos (for example the moves to copy), links as for video_url. Each 3–30 seconds, 720p or higher, aspect ratio at most 2.5:1; together with video_url at most 30 seconds, so a 30-second video_url can't carry any. |
aspect_ratio | string | Yes | auto, 21:9, 16:9, 9:16 or 1:1. auto follows the video you edit. |
resolution | string | Yes | 720p or 1080p. Sets the price. |
duration | integer | No | Output length in seconds, 3–30. It's what you pay for, see Pricing. When you send it, it alone sets the output length, however long the video you edit is. Leave it out and the output follows the video you edit, see Without duration. |
webhook_url | string | No | Notified when the task succeeds or fails: https, up to 2048 characters, not a private, loopback or reserved address. See Webhooks. |
Without duration
- Output length: the length of the video you edit (the longer of its video and audio tracks), rounded up to a whole second; less than 0.05 seconds over doesn't count (10.02 s gives 10 seconds, 10.06 s gives 11).
- Billing: 30 × the price per second is frozen first; when the task succeeds, the actual output length is charged and the rest returned, see Pricing.
- Balance: your available balance must cover the 30 seconds (and so must the key's spend limits), even if the video is shorter; otherwise the task fails with
insufficient_balance(orspend_limit_exceeded). Senddurationto freeze only what you ask for.
Replace the car with the one in the reference image, 1080p, 8 seconds:
curl https://api.nanoapi.ai/v1/tasks \
-H "Authorization: Bearer $NANOAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kling-4.0",
"mode": "video_edit",
"video_url": "https://example.com/source.mp4",
"image_urls": ["https://example.com/ref.jpg"],
"prompt": "Replace the car with the one in the reference image",
"aspect_ratio": "auto",
"resolution": "1080p",
"duration": 8
}'With a reference video and no duration (the output follows the video you edit), 720p:
curl https://api.nanoapi.ai/v1/tasks \
-H "Authorization: Bearer $NANOAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kling-4.0",
"mode": "video_edit",
"video_url": "https://example.com/main.mp4",
"video_urls": ["https://example.com/dance.mp4"],
"prompt": "Edit @Video1: make her move like the dancer in @Video2",
"aspect_ratio": "auto",
"resolution": "720p"
}'Response: 200 OK. data is the newly created task, with only these fields; each one is described in Create a task: Response. Keep data.id to get the result: once the task succeeds, the video is at data.outputs[0].url of the retrieved task or the webhook. The task can still fail after it's created (for example a file can't be downloaded), so go by what retrieving the task or the webhook tells you.
{
"code": 200,
"message": "success",
"data": {
"object": "task",
"id": "tk_01jbc4k7m2n9p5q8r3s6t1v4w7",
"model": "kling-4.0",
"status": "queued",
"error": null,
"created_at": "2026-10-30T08:30:00Z"
}
}Pricing
cost = duration × price per second of the resolutionLoading the current prices…
Example: 1080p for 8 seconds (the first request above) costs 8 × the 1080p price per second.
Without duration (the second request above), 30 × the 720p price per second is frozen first. When the task succeeds, the output length × the price per second is charged and the rest returned: for an 11-second video, 11 seconds are charged and 19 returned. billing.billed_seconds is then the output length. If the task fails, all of it is returned.
Billed seconds are the duration you ask for, however long the video you edit is; without duration, the output length. Prices change, so read the current ones from GET /v1/products (the prices rows whose mode is this mode) instead of hard-coding them; billing.frozen on the retrieved task is what counts. All Kling 4.0 prices: Kling 4.0 → Pricing.
Errors
Create request errors: the request fails with an HTTP error and no task is created. Specific to this mode:
| Status | error.type | When | What to do |
|---|---|---|---|
400 | invalid_request | video_url or prompt is missing, image_urls has more than 10 images or video_urls more than 4 videos (video_urls takes at most 4 videos for mode video_edit), aspect_ratio or resolution is missing, or aspect_ratio, resolution or duration isn't one of the values above. param names the parameter. | Fix the parameter param names and send the request again. |
Other errors of the create endpoint (401, 402, 429 and so on): Create a task → Errors.
Task failures: the create request succeeded (200) and the task later turned failed. There's no HTTP status: the reason is the task's error.type, from retrieving the task or the webhook.
error.type | When | What to do |
|---|---|---|
insufficient_balance | Without duration: your available balance can't cover 30 seconds at the price per second, even if the video is shorter. Within a few seconds of creating the task, nothing frozen. | Top up, or send duration, then create the task again. |
invalid_media | The video, a reference video or a reference image can't be downloaded or read (corrupt or an unsupported format), or a video is below 720p or its aspect ratio is beyond 2.5:1. Found when the files are downloaded, a few seconds after the task is submitted. The frozen amount is returned in full. | Make sure video_url, video_urls and image_urls can be downloaded publicly and every video meets the requirements, then create the task again. |
video_too_short | A video (video_url or a video_urls entry) is shorter than 3 seconds (The video duration must be between 3 and 30 seconds.). Found when the videos are downloaded, a few seconds after the task is submitted (started_at may be null). The frozen amount is returned in full. | Use videos of at least 3 seconds and create the task again. |
video_too_long | A video is longer than 30 seconds, or video_url and video_urls add up to more than 30 (The total duration of the videos must be at most 30 seconds.). Found when the videos are downloaded, a few seconds after the task is submitted (started_at may be null). The frozen amount is returned in full. | Trim the videos (or send fewer reference videos) and create the task again. |
Failure reasons shared by every mode (such as a balance too low for the task): Kling 4.0 → Errors; all of them: Failure reasons.
Reference to Video
Put the people, objects or scenes in your images into a new video, optionally guided by reference videos (Kling 4.0 reference_to_video).
Seedance 2.5
Generate a video with sound from a prompt, frames or reference images, videos and audio, or edit or extend a video, billed by the output length.