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).
Kling 4.0 puts the people, objects or scenes in your reference images into a newly generated video. You can also add reference videos, for example for the subject to copy the moves in one.
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 | reference_to_video. |
image_urls | string[] | This or video_urls | Up to 10 reference images. Each is an http(s) link of at most 4096 characters that can be downloaded directly, not a private address. |
video_urls | string[] | This or image_urls | Up to 5 reference videos, links as for image_urls. Each 3–30 seconds, together at most 30 seconds, 720p or higher, aspect ratio at most 2.5:1, see Media. With reference videos the task is billed at the video_edit price, see Pricing. |
prompt | string | No | What the video shows, for example what the subject of the images does, at most 8000 characters. Refer to the files as @Image1, @Video1 and so on, see Referring to files. |
aspect_ratio | string | Yes | auto, 21:9, 16:9, 9:16 or 1:1. auto doesn't follow the reference images: if you need a particular ratio (for example portrait), set it. |
resolution | string | Yes | 720p or 1080p. Sets the price. |
duration | integer | Yes | Output length in seconds, 3–30. It's what you pay for, see Pricing. |
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. |
Send at least one of image_urls and video_urls (reference videos alone are fine); with neither, the request returns 400 invalid_request with param set to image_urls. video_url isn't accepted: sending it returns 400 invalid_request with param set to video_url.
Two reference images, portrait 1080p, 5 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": "reference_to_video",
"image_urls": [
"https://example.com/cat.jpg",
"https://example.com/car.jpg"
],
"prompt": "The cat sits on the hood of the car",
"aspect_ratio": "9:16",
"resolution": "1080p",
"duration": 5
}'A reference image and a reference video (the cat walks like the woman in the video), 16:9 720p, 5 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": "reference_to_video",
"image_urls": ["https://example.com/cat.jpg"],
"video_urls": ["https://example.com/walk.mp4"],
"prompt": "The cat from @Image1 walks down the street like the woman in @Video1",
"aspect_ratio": "16:9",
"resolution": "720p",
"duration": 5
}'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 5 seconds (the first request above) costs 5 × the 1080p price per second.
With reference videos (video_urls) the task is billed at the video_edit price per second instead; GET /v1/products has no separate row for it. The second request above (720p, 5 seconds) costs 5 × the video_edit 720p price per second:
Loading the current prices…
Billed seconds are the duration you ask for, however many images or videos you send and however long the videos are. Prices change, so read the current ones from GET /v1/products (the prices rows whose mode is this mode, or video_edit with reference videos) 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 | Neither image_urls nor video_urls was sent (param is image_urls, message is image_urls or video_urls is required for mode reference_to_video), image_urls has more than 10 images or video_urls more than 5 videos, video_url was sent, or aspect_ratio, resolution or duration is missing or 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 |
|---|---|---|
invalid_media | A reference image or video can't be downloaded or read (corrupt or an unsupported format), or a reference 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. | Replace the file error.message points to, check the video requirements and create the task again. |
video_too_short | A reference video 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 reference video is longer than 30 seconds, or they 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) 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.