Model ID
Use with the Workers AI binding, the AI Gateway REST API, or the Unified API.
Calling the provider directly? Use the provider's model name instead, including with provider-native endpoints or the provider's own SDK. For example, Anthropic's name for anthropic/claude-opus-4.8 is claude-opus-4-8.
- Third-party
Kling 4.0 is Kling AI's video generation model for text-to-video and multi-keyframe image-to-video, producing up to 30 seconds of 720p or 1080p video from prompts of up to 26,000 characters and up to 10 keyframes.
| Model Info | |
|---|---|
| Terms and License | link ↗ |
| More information | link ↗ |
| Pricing |
|
const response = await env.AI.run(
'klingai/kling-v4',
{
aspect_ratio: '16:9',
duration: 5,
prompt:
'A paper boat drifts down a narrow, rain-soaked Tokyo alley at night. Neon signs in pink and teal reflect in the puddles and ripple as raindrops fall. The camera tracks low alongside the boat, close to the water. Cinematic, photorealistic, shallow depth of field.',
resolution: '1080p',
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "klingai/kling-v4",
"input": {
"aspect_ratio": "16:9",
"duration": 5,
"prompt": "A paper boat drifts down a narrow, rain-soaked Tokyo alley at night. Neon signs in pink and teal reflect in the puddles and ripple as raindrops fall. The camera tracks low alongside the boat, close to the water. Cinematic, photorealistic, shallow depth of field.",
"resolution": "1080p"
}
}'{
"state": "Completed",
"result": {
"video": "https://examples.aig.cloudflare.com/klingai/kling-v4/neon-alley-paper-boat.mp4"
}
}Ultra-Wide Canyon Sunrise — Ultra-wide 21:9 text-to-video, an aspect ratio new in Kling 4.0
const response = await env.AI.run(
'klingai/kling-v4',
{
aspect_ratio: '21:9',
duration: 8,
prompt:
'A sweeping aerial shot glides over a red sandstone canyon at sunrise. Long shadows stretch across the canyon floor as a river catches the first golden light. The camera slowly pushes forward and rises to reveal the desert horizon. Epic cinematic landscape, anamorphic look.',
resolution: '720p',
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "klingai/kling-v4",
"input": {
"aspect_ratio": "21:9",
"duration": 8,
"prompt": "A sweeping aerial shot glides over a red sandstone canyon at sunrise. Long shadows stretch across the canyon floor as a river catches the first golden light. The camera slowly pushes forward and rises to reveal the desert horizon. Epic cinematic landscape, anamorphic look.",
"resolution": "720p"
}
}'{
"state": "Completed",
"result": {
"video": "https://examples.aig.cloudflare.com/klingai/kling-v4/ultra-wide-canyon-sunrise.mp4"
}
}Sketch to Product Reveal — Image-to-video from one first frame: a pencil concept sketch becomes a photoreal product shot
const response = await env.AI.run(
'klingai/kling-v4',
{
prompt:
'The pencil sneaker sketch in @image_1 comes to life. The graphite lines fill in with real materials: white leather, a perforated toe box, an orange suede heel panel, a translucent cushioned sole. The sneaker lifts off the sketchbook page and settles onto a slowly rotating white studio turntable as the paper fades into a soft grey seamless backdrop. Studio softbox lighting, crisp reflections, macro detail on the stitching. Smooth, continuous camera orbit.',
first_frame: 'https://examples.aig.cloudflare.com/klingai/kling-v4/inputs/sneaker-sketch.jpg',
duration: 10,
resolution: '1080p',
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "klingai/kling-v4",
"input": {
"prompt": "The pencil sneaker sketch in @image_1 comes to life. The graphite lines fill in with real materials: white leather, a perforated toe box, an orange suede heel panel, a translucent cushioned sole. The sneaker lifts off the sketchbook page and settles onto a slowly rotating white studio turntable as the paper fades into a soft grey seamless backdrop. Studio softbox lighting, crisp reflections, macro detail on the stitching. Smooth, continuous camera orbit.",
"first_frame": "https://examples.aig.cloudflare.com/klingai/kling-v4/inputs/sneaker-sketch.jpg",
"duration": 10,
"resolution": "1080p"
}
}'{
"state": "Completed",
"result": {
"video": "https://examples.aig.cloudflare.com/klingai/kling-v4/sketch-to-product-reveal.mp4"
}
}Mascot Hops Off the Page — One continuous shot through three keyframes (first, middle, last), with each keyframe referenced in the prompt
const response = await env.AI.run(
'klingai/kling-v4',
{
prompt:
'A flat illustrated robot mascot printed on a notebook page wakes up. In @image_1 it is flat ink on the paper; it blinks, its antenna wiggles, and it peels itself up off the page into a glossy 3D toy. In @image_2 it stands on the page beside its own faded print, knees bent, mid-hop. By @image_3 it has hopped onto the wooden desk next to the coffee mug and waves at the camera. Warm morning sunlight, shallow depth of field, playful stop-motion feel, one continuous shot with a fixed camera.',
first_frame: 'https://examples.aig.cloudflare.com/klingai/kling-v4/inputs/mascot-page.jpg',
middle_frames: ['https://examples.aig.cloudflare.com/klingai/kling-v4/inputs/mascot-hop.jpg'],
last_frame: 'https://examples.aig.cloudflare.com/klingai/kling-v4/inputs/mascot-desk.jpg',
duration: 15,
resolution: '1080p',
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "klingai/kling-v4",
"input": {
"prompt": "A flat illustrated robot mascot printed on a notebook page wakes up. In @image_1 it is flat ink on the paper; it blinks, its antenna wiggles, and it peels itself up off the page into a glossy 3D toy. In @image_2 it stands on the page beside its own faded print, knees bent, mid-hop. By @image_3 it has hopped onto the wooden desk next to the coffee mug and waves at the camera. Warm morning sunlight, shallow depth of field, playful stop-motion feel, one continuous shot with a fixed camera.",
"first_frame": "https://examples.aig.cloudflare.com/klingai/kling-v4/inputs/mascot-page.jpg",
"middle_frames": [
"https://examples.aig.cloudflare.com/klingai/kling-v4/inputs/mascot-hop.jpg"
],
"last_frame": "https://examples.aig.cloudflare.com/klingai/kling-v4/inputs/mascot-desk.jpg",
"duration": 15,
"resolution": "1080p"
}
}'{
"state": "Completed",
"result": {
"video": "https://examples.aig.cloudflare.com/klingai/kling-v4/mascot-hops-off-the-page.mp4"
}
}prompt
stringrequiredminLength: 1maxLength: 26000Text prompt describing the video, up to 26,000 English characters. Refer to keyframes as @image_1, @image_2, and so on, numbered first frame, middle frames, then last frame.first_frame
stringminLength: 1Image the video starts from. An https URL, a data URI, or raw base64 (JPG or PNG, up to 30 MB, at least 300 px per side, aspect ratio between 2:5 and 5:2)▶middle_frames[]
arraymaxItems: 9Keyframes the video passes through, in orderlast_frame
stringminLength: 1Image the video ends on. An https URL, a data URI, or raw base64 (JPG or PNG, up to 30 MB, at least 300 px per side, aspect ratio between 2:5 and 5:2)duration
integerrequireddefault: 5minimum: 3maximum: 30Video duration in secondsaspect_ratio
stringrequireddefault: 16:9enum: 21:9, 16:9, 9:16, 1:1Video aspect ratio. Ignored when keyframes are given.resolution
stringrequireddefault: 1080penum: 720p, 1080pOutput resolutionvideo
stringURL to the generated video