## Basic model info - Model name: kling/kling kling-v4 - Model description: Kling 4.0: up to 30-second native video with two-channel stereo audio and lip sync, from text, up to 10 keyframes, or up to 15 mixed references (images, videos, elements and voices), plus video editing. 720p and 1080p. - Endpoint name: reference-to-video ## Model schema The model schema is defined in the OpenAPI schema: [OpenAPI Schema](https://oapi.sunra.ai/main/kling/kling-v4/latest.json) ### Model input schema The model input schema is: ```json { "properties": { "prompt": { "description": "Text prompt. Refer to inputs as @image_1, @video_1, @element_1, @voice_1.", "maxLength": 26000, "minLength": 1, "title": "Prompt", "type": "string", "x-sr-order": 201 }, "aspect_ratio": { "default": "adaptive", "description": "Aspect ratio. 'adaptive' follows the references.", "enum": [ "adaptive", "21:9", "16:9", "9:16", "1:1" ], "title": "Aspect Ratio", "type": "string", "x-sr-order": 401 }, "duration": { "default": 5, "description": "Duration of the generated video in seconds (3-30).", "maximum": 30, "minimum": 3, "title": "Duration", "type": "integer", "x-sr-order": 402 }, "element_ids": { "anyOf": [ { "items": { "type": "string" }, "maxItems": 7, "type": "array" }, { "type": "null" } ], "description": "Kling element IDs (characters/objects). Refer to them as @element_1, @element_2, ... Up to 7.", "title": "Element Ids", "x-sr-order": 306 }, "end_image_url": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "Optional last frame.", "title": "End Image Url", "x-sr-order": 302 }, "image_urls": { "anyOf": [ { "items": { "type": "string" }, "maxItems": 10, "type": "array" }, { "type": "null" } ], "description": "Reference images for subjects, scenes or style. Refer to them in the prompt as @image_1, @image_2, ...", "title": "Image Urls", "x-sr-order": 304 }, "resolution": { "default": "1080p", "description": "Output resolution. Pricing depends on resolution.", "enum": [ "720p", "1080p" ], "title": "Resolution", "type": "string", "x-sr-order": 403 }, "start_image_url": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "description": "Optional first frame.", "title": "Start Image Url", "x-sr-order": 301 }, "video_urls": { "anyOf": [ { "items": { "type": "string" }, "maxItems": 5, "type": "array" }, { "type": "null" } ], "description": "Reference videos (MP4/MOV, 3-30s each, 30s combined). Refer to them as @video_1, @video_2, ... Input video seconds are billed in addition to the output.", "title": "Video Urls", "x-sr-order": 305 }, "voice_ids": { "anyOf": [ { "items": { "type": "string" }, "maxItems": 3, "type": "array" }, { "type": "null" } ], "description": "Kling voice IDs to use for speech. Refer to them as @voice_1, ... Up to 3.", "title": "Voice Ids", "x-sr-order": 307 } }, "required": [ "prompt" ], "title": "ReferenceToVideoInput", "type": "object" } ``` ### Model output schema The model output schema is: ```json { "description": "Output for the omni endpoints, billed post-hoc on `units` (USD x 1000).", "properties": { "output_video_dur": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "description": "Output video duration in seconds as reported by Kling.", "title": "Output Video Dur" }, "units": { "description": "Billable amount in thousandths of a USD (see pricing.py).", "title": "Units", "type": "integer" }, "video": { "properties": { "content_type": { "description": "The mime type of the file.", "title": "Content Type", "type": "string" }, "file_name": { "description": "The name of the file. It will be auto-generated if not provided.", "title": "File Name", "type": "string" }, "file_size": { "description": "The size of the file in bytes.", "title": "File Size", "type": "integer" }, "url": { "description": "The URL where the file can be downloaded from.", "title": "Url", "type": "string" } }, "required": [ "content_type", "file_name", "file_size", "url" ], "title": "SunraFile", "type": "object" } }, "required": [ "video", "units" ], "title": "KlingV4UnitsOutput", "type": "object" } ``` ## Example inputs and outputs Use the following example inputs and outputs to understand the model. ### Input example ```json { "prompt": "", "aspect_ratio": "adaptive", "duration": 5, "element_ids": null, "end_image_url": null, "image_urls": null, "resolution": "1080p", "start_image_url": null, "video_urls": null, "voice_ids": null } ``` ### Output example ```json { } ``` ## Model code examples ### JavaScript ```javascript import { sunra } from "@sunra/client"; const result = await sunra.subscribe("kling/kling-v4/reference-to-video", { input: { image_urls: null, element_ids: null, prompt: '', start_image_url: null, end_image_url: null, video_urls: null, voice_ids: null, aspect_ratio: 'adaptive', duration: 5, resolution: '1080p' }, logs: true, onQueueUpdate: (update) => { console.log(`Status Update: ${update.status}, Request ID: ${update.request_id}`); }, }); console.log(result.data); console.log(result.requestId); ``` ### Python ```python import sunra_client result = sunra_client.subscribe( "kling/kling-v4/reference-to-video", arguments={ "image_urls": None, "element_ids": None, "prompt": "", "start_image_url": None, "end_image_url": None, "video_urls": None, "voice_ids": None, "aspect_ratio": "adaptive", "duration": 5, "resolution": "1080p" }, with_logs=True, on_enqueue=print, on_queue_update=print, ) print(result) ``` ### Java ```java import ai.sunra.client.*; import java.util.Map; import com.google.gson.JsonObject; var client = SunraClient.withEnvCredentials(); var response = client.subscribe( "kling/kling-v4/reference-to-video", SubscribeOptions.builder() .input(Map.of( "image_urls", null, "element_ids", null, "prompt", "", "start_image_url", null, "end_image_url", null, "video_urls", null, "voice_ids", null, "aspect_ratio", "adaptive", "duration", 5, "resolution", "1080p")) .resultType(JsonObject.class) .onQueueUpdate(update -> System.out.printf( "\nStatus Update: %s, Request ID: %s%n", update.getStatus(), update.getRequestId() )) .logs(true) .build() ); System.out.println("Completed!"); System.out.println(response.getData()); ``` ### Kotlin ```kotlin import ai.sunra.client.kt.* import com.google.gson.JsonObject val client = createSunraClient() val response = client.subscribe( endpointId = "kling/kling-v4/reference-to-video", input = mapOf( "image_urls" to null, "element_ids" to null, "prompt" to "", "start_image_url" to null, "end_image_url" to null, "video_urls" to null, "voice_ids" to null, "aspect_ratio" to "adaptive", "duration" to 5, "resolution" to "1080p"), options = ai.sunra.client.kt.SubscribeOptions(logs = true), onUpdate = { update -> println("\nStatus Update: ${update.status}, Request ID: ${update.requestId}") } ) println("Completed!") println(response.data) ``` ### Curl ```bash curl --request POST \ --url https://api.sunra.ai/v1/queue/kling/kling-v4/reference-to-video \ --header "Authorization: Key $SUNRA_KEY" \ --header "Content-Type: application/json" \ --data '{"image_urls":null,"element_ids":null,"prompt":"","start_image_url":null,"end_image_url":null,"video_urls":null,"voice_ids":null,"aspect_ratio":"adaptive","duration":5,"resolution":"1080p"}' ``` ## Model readme >