typetext
{
"aspect_ratio": "16:9",
"duration": 5,
"middle_images": [],
"prompt": "a red fox trotting across a snowy meadow at sunrise, breath visible in the cold air, cinematic tracking shot",
"reference_images": [],
"reference_videos": [],
"resolution": "720p"
}npm install replicate
REPLICATE_API_TOKEN environment variable:export REPLICATE_API_TOKEN=r8_dSb**********************************
This is your API token. Keep it to yourself.
import Replicate from "replicate";
import fs from "node:fs";
const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN,
});
Run kwaivgi/kling-v4.0 using Replicate’s API. Check out the model's schema for an overview of inputs and outputs.
const input = {
aspect_ratio: "16:9",
duration: 5,
middle_images: [],
prompt: "a red fox trotting across a snowy meadow at sunrise, breath visible in the cold air, cinematic tracking shot",
reference_images: [],
reference_videos: [],
resolution: "720p"
};
const output = await replicate.run("kwaivgi/kling-v4.0", { input });
// To access the file URL:
console.log(output.url()); //=> "http://example.com"
// To write the file to disk:
fs.writeFile("my-image.png", output);
To learn more, take a look at the guide on getting started with Node.js.
pip install replicate
REPLICATE_API_TOKEN environment variable:export REPLICATE_API_TOKEN=r8_dSb**********************************
This is your API token. Keep it to yourself.
import replicate
Run kwaivgi/kling-v4.0 using Replicate’s API. Check out the model's schema for an overview of inputs and outputs.
output = replicate.run(
"kwaivgi/kling-v4.0",
input={
"aspect_ratio": "16:9",
"duration": 5,
"middle_images": [],
"prompt": "a red fox trotting across a snowy meadow at sunrise, breath visible in the cold air, cinematic tracking shot",
"reference_images": [],
"reference_videos": [],
"resolution": "720p"
}
)
# To access the file URL:
print(output.url())
#=> "http://example.com"
# To write the file to disk:
with open("my-image.png", "wb") as file:
file.write(output.read())
To learn more, take a look at the guide on getting started with Python.
REPLICATE_API_TOKEN environment variable:export REPLICATE_API_TOKEN=r8_dSb**********************************
This is your API token. Keep it to yourself.
Run kwaivgi/kling-v4.0 using Replicate’s API. Check out the model's schema for an overview of inputs and outputs.
curl -s -X POST \
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \
-H "Content-Type: application/json" \
-H "Prefer: wait" \
-d $'{
"input": {
"aspect_ratio": "16:9",
"duration": 5,
"middle_images": [],
"prompt": "a red fox trotting across a snowy meadow at sunrise, breath visible in the cold air, cinematic tracking shot",
"reference_images": [],
"reference_videos": [],
"resolution": "720p"
}
}' \
https://api.replicate.com/v1/models/kwaivgi/kling-v4.0/predictions
To learn more, take a look at Replicate’s HTTP API reference docs.
{
"id": "a4rvj7m8ahrmy0d1f7c9d9570r",
"model": "kwaivgi/kling-v4.0",
"version": "hidden",
"input": {
"aspect_ratio": "16:9",
"duration": 5,
"middle_images": [],
"prompt": "a red fox trotting across a snowy meadow at sunrise, breath visible in the cold air, cinematic tracking shot",
"reference_images": [],
"reference_videos": [],
"resolution": "720p"
},
"logs": "Using endpoint /text-to-video/kling-4.0 with settings {'resolution': '720p', 'duration': 5, 'aspect_ratio': '16:9'}\nCreated Kling task 943785298831100563\nGenerated video in 554.3sec\nDownloading 4862584 bytes\nDownloaded 4.64MB in 0.76sec\nOutput video duration: 5.04s",
"output": "https://replicate.delivery/xezq/1oA04jEVxn5PA5XajU0590KXL1rvlSyGv4HNPlaDvPxho12F/tmpj0gvyv6_.mp4",
"data_removed": false,
"error": null,
"source": "web",
"status": "succeeded",
"created_at": "2026-10-26T20:13:16.244Z",
"started_at": "2026-10-26T20:13:16.257129Z",
"completed_at": "2026-10-26T20:22:31.678265Z",
"urls": {
"cancel": "https://api.replicate.com/v1/predictions/a4rvj7m8ahrmy0d1f7c9d9570r/cancel",
"get": "https://api.replicate.com/v1/predictions/a4rvj7m8ahrmy0d1f7c9d9570r",
"stream": "https://stream.replicate.com/v1/files/jbxs-3h3hmp6m4ncqqcuhp27ghgrsm7wyoydaygft5bmmtbjeoptxapya",
"web": "https://replicate.com/p/a4rvj7m8ahrmy0d1f7c9d9570r"
},
"metrics": {
"model_variant": "no-video-input",
"predict_time": 555.421136197,
"resolution_target": "720p",
"total_time": 555.434265717,
"video_output_duration_seconds": 5.042
}
}