{"openapi":"3.0.2","info":{"title":"kling/kling-4.0","description":"The request body Comfy Router accepts for the model \"kling/kling-4.0\", and the response body it returns. The INPUT schema is the same schema the server validates a call against before it reaches the provider, so what is published and what is enforced cannot differ. `x-comfy-router-input-modalities` records the media kinds the model is documented to accept; the request schema is shared across sibling models and may admit media kinds this model ignores. The OUTPUT schema describes the provider's native result document exactly as Router returns it: Router does not validate, narrow or re-envelope the response, so the output schema is descriptive rather than enforced, and Comfy owns no output shape of its own.","version":"8490a9ed058f"},"paths":{"/v2/models/kling/kling-4.0":{"post":{"operationId":"runRouterModel","summary":"Run kling/kling-4.0 synchronously.","security":[{"BearerAuth":[]},{"ApiKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"description":"Request body for a Kling 4.0 generation. Send `prompt` for text-to-video, `contents` holding only a prompt and frame images for image-to-video, or `contents` holding any reference image, video, element or voice for omni video. Send either `prompt` or `contents`, not both; with `contents`, the prompt is a contents item of type \"prompt\". `settings.resolution` is required, and so is `settings.duration` unless `contents` holds a \"base_video\", so the request never falls back to Kling's own defaults, which are the most expensive configuration.","example":{"contents":[{"text":"The fox turns toward the camera.","type":"prompt"},{"type":"first_frame","url":"https://example.com/fox.png"}],"settings":{"duration":3,"resolution":"720p"}},"properties":{"contents":{"description":"The prompt and the input media. Holding only \"prompt\", \"first_frame\", \"middle_frame\" and \"last_frame\" items selects image-to-video (a prompt and up to 10 frames); holding any \"refer_image\", \"feature_video\", \"base_video\", \"element\" or \"voice\" selects omni video (up to 15 inputs, with at most 10 images, 5 videos, 7 elements and 3 voices). A request with a \"feature_video\", a \"base_video\" or a video character element bills at the video-input rate.","items":{"$ref":"#/components/schemas/KlingV4Content"},"maxItems":16,"type":"array"},"options":{"allOf":[{"$ref":"#/components/schemas/KlingV4Text2VideoOptions"}],"description":"General configuration such as watermark options. `options.callback_url` and `options.external_task_id` are not supported on Kling 4.0; Comfy Router refuses a request that sets either inside `options`. A top-level `callback_url` or `external_task_id` is not part of this schema and is removed before the request reaches Kling. An explicit null `options` is treated as absent, as the /proxy Kling 4.0 check and Kling do.","nullable":true,"type":"object"},"prompt":{"description":"Text-to-video prompt. Required when `contents` is absent or empty, and refused alongside a non-empty `contents`. Up to 26,000 English characters or 11,000 non-English characters; comfy-api enforces 1 to 26,000 characters, and Kling itself refuses longer non-English text.","maxLength":26000,"minLength":1,"type":"string"},"settings":{"description":"Output configuration such as resolution, aspect ratio and duration.","properties":{"aspect_ratio":{"description":"Aspect ratio (width:height) of the generated frames. One of \"21:9\", \"16:9\", \"9:16\", \"1:1\", \"4:3\" or \"3:4\" for text-to-video (default \"16:9\"), those or \"adaptive\" for omni video (default \"adaptive\"). Image-to-video follows the images. An explicit null is treated as absent, as the /proxy Kling 4.0 check and Kling do.","enum":["21:9","16:9","9:16","1:1","4:3","3:4","adaptive"],"nullable":true,"type":"string"},"duration":{"description":"Video length in seconds, 3 through 30. Required unless `contents` holds a \"base_video\", where an edit may omit it to keep the base video's length. Such a call is held and estimated at the 30-second maximum at the requested resolution, an upper bound rather than the price, and is billed from the price Kling reports for the finished task.","maximum":30,"minimum":3,"type":"integer"},"dynamic_range":{"description":"Dynamic range of the generated video. One of \"sdr\" or \"hdr\". Default \"sdr\". \"hdr\" needs a \"1080p\" or \"4k\" resolution and is refused at \"720p\". An HDR video costs more per output second. An explicit null is treated as absent, as the /proxy Kling 4.0 check and Kling do.","enum":["sdr","hdr"],"nullable":true,"type":"string"},"resolution":{"description":"Resolution of the generated video. One of \"720p\", \"1080p\" or \"4k\". Required.","enum":["720p","1080p","4k"],"type":"string"}},"required":["resolution"],"type":"object"}},"required":["settings"],"type":"object"}}}},"responses":{"200":{"description":"OK - the model's native JSON output, returned unchanged; the schema describes the provider's terminal result document as Router returns it.","content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/KlingV2QueryTaskResponse"}],"description":"Comfy Router output schema for Kling's v2 task surface: the terminal `GET /tasks?task_ids={id}` document, forwarded unchanged. Every Router id on that surface is submit-and-poll (`routerresult/classification.go` records each as `ReturnModeSubmitPoll`) — and Router polls on the caller's behalf, so the body a caller receives is the finished task rather than the `data.id` handle the underlying submit answers with.\nThis is NOT the document the eleven Kling v1 video ids answer (`KlingVideoRouterOutput`), and the three differences are the reason it is its own component. `data` is a LIST — one element per task id the query named — rather than a single object, so the generated video's download URL is at `data[].outputs[].url`, under the element for the polled task. Router always polls ONE task (the poll route is built from the single id the submit returned, so the request is always `?task_ids=\u003cone id\u003e`), so that list carries one element in practice; a caller polling this route directly with several ids gets one element each and must match on `data[].id`. Second, the terminal status spells `succeeded`, where every v1 Kling route says `succeed`. Third, the outputs live under `outputs[]` rather than `task_result`.\nRead the ELEMENT field, not the `outputs` container: `KlingV2Output` is `{type, id, url, watermark_url, duration, ...}`, so a one-element list carrying an id and a type and no URL is a non-empty array holding nothing playable. `data[].outputs[].watermark_url` is the same asset under Kling's hotlink-protection form and counts as a result. `mp3_url` and `wav_url` deliberately do NOT: the operation Router serves here is text-to-video, so a success carrying only audio is a shape anomaly. `routerpollstate.classifyKlingV2` draws exactly those lines.\n`url` is hotlink-protected and Kling clears it after 30 days, so download it rather than storing the link.","example":{"code":0,"data":[{"create_time":1798761600000,"id":"kling-v2-task-7c8d9e0f1a2b","message":"","outputs":[{"duration":"5","id":"kling-v2-output-2b1a0f9e8d7c","type":"video","url":"https://example.invalid/kling/v2/generated.mp4"}],"status":"succeeded","update_time":1798761820000}],"message":"SUCCEED","request_id":"3d7e5c91-0b42-4f68-9a13-8e2c6d4b0a75"}}}}}}}}},"components":{"schemas":{"KlingV2Output":{"description":"A generated output. The fields present depend on `type` (video, image, audio, voice or element).","properties":{"duration":{"description":"Duration of the generated video in seconds.","type":"string"},"group_id":{"description":"Grouping marker, present only for grouped images.","type":"string"},"id":{"description":"Output ID generated by the system.","type":"string"},"mp3_duration":{"description":"Duration of the generated MP3 audio in seconds.","type":"string"},"mp3_url":{"description":"MP3 URL of the generated audio (hotlink-protected).","type":"string"},"name":{"description":"Name of the generated material.","type":"string"},"owned_by":{"description":"Source of the material. \"kling\" denotes the official library; numbers are creator IDs.","type":"string"},"status":{"description":"Status of the material. One of \"succeeded\" or \"deleted\".","type":"string"},"type":{"description":"Output content type. One of \"video\", \"image\", \"audio\", \"voice\" or \"element\".","type":"string"},"url":{"description":"URL of the generated result (hotlink-protected). Cleared after 30 days.","type":"string"},"watermark_url":{"description":"URL of the watermarked result (hotlink-protected).","type":"string"},"wav_duration":{"description":"Duration of the generated WAV audio in seconds.","type":"string"},"wav_url":{"description":"WAV URL of the generated audio (hotlink-protected).","type":"string"}},"type":"object"},"KlingV2QueryTaskResponse":{"description":"Response returned when querying Kling v2 tasks by ID.","properties":{"code":{"description":"Error code. 0 indicates success.","type":"integer"},"data":{"description":"Tasks matching the query.","items":{"$ref":"#/components/schemas/KlingV2Task"},"type":"array"},"message":{"description":"Error message.","type":"string"},"request_id":{"description":"Request ID generated by the system.","type":"string"}},"type":"object"},"KlingV2Task":{"description":"A single Kling v2 task record.","properties":{"billing":{"description":"Billing details for the task.","items":{"properties":{"amount":{"description":"Consumption amount, accurate to two decimal places.","type":"string"},"cash_type":{"description":"Cash account the charge was drawn from (only present when charge_type is \"cash\"), for example \"balance\". Some tasks return it; others may omit it.","type":"string"},"charge_type":{"description":"Consumption account type. \"cash\" for balance, \"unit\" for a resource package.","type":"string"},"currency":{"description":"ISO 4217 currency code of `amount` and `list_price`, for example \"USD\". Some tasks return it; others may omit it.","type":"string"},"list_price":{"description":"List price of the task before any discount, as a decimal string. Some tasks return it; others may omit it.","type":"string"},"package_type":{"description":"Consumable resource bundle type (only present when charge_type is \"unit\"). One of \"video\", \"image\" or \"audio\".","type":"string"}},"type":"object"},"type":"array"},"create_time":{"description":"Task creation time. Unix timestamp in milliseconds.","format":"int64","type":"integer"},"external_id":{"description":"The custom task ID for this task, if any.","type":"string"},"id":{"description":"The task ID.","type":"string"},"message":{"description":"Task status information, displaying the failure reason when the task fails.","type":"string"},"outputs":{"description":"Generated outputs for the task.","items":{"$ref":"#/components/schemas/KlingV2Output"},"type":"array"},"status":{"description":"Task status. One of \"submitted\", \"processing\", \"succeeded\" or \"failed\".","type":"string"},"update_time":{"description":"Task update time. Unix timestamp in milliseconds.","format":"int64","type":"integer"}},"type":"object"},"KlingV4Content":{"description":"One item of a Kling 4.0 `contents` array. The fields present depend on `type`.","properties":{"element_id":{"description":"Element ID, when type is \"element\".","type":"string"},"id":{"description":"Reference ID for this input, used as @id in the prompt. Must be unique within the task. Required for \"element\" and \"voice\".","type":"string"},"text":{"description":"Text prompt, when type is \"prompt\". Up to 26,000 English characters or 11,000 non-English characters; comfy-api enforces 1 to 26,000 characters, and Kling itself refuses longer non-English text. Reference other inputs as @id.","type":"string"},"type":{"description":"Input type. Image-to-video accepts only \"prompt\", \"first_frame\", \"middle_frame\" and \"last_frame\", and refuses any other type. Omni video also accepts \"refer_image\", \"feature_video\" (a reference video), \"base_video\" (the video to edit, at most one), \"element\" and \"voice\".","enum":["prompt","first_frame","middle_frame","last_frame","refer_image","feature_video","base_video","element","voice"],"type":"string"},"url":{"description":"Image or video URL, when type is a frame, \"refer_image\", \"feature_video\" or \"base_video\". Images may also be Base64. Images are .jpg, .jpeg or .png up to 30MB, at least 300px per side, with an aspect ratio between 2:5 and 5:2. Videos are .mp4 or .mov up to 300MB and 3 to 30 seconds long.","type":"string"},"voice_id":{"description":"Voice ID, when type is \"voice\". A Kling preset voice or a custom voice.","type":"string"}},"required":["type"],"type":"object"},"KlingV4Text2VideoOptions":{"additionalProperties":false,"description":"General configuration such as watermark options. `options.callback_url` and `options.external_task_id` are not supported on Kling 4.0; Comfy Router refuses a request that sets either inside `options`. A top-level `callback_url` or `external_task_id` is not part of this schema and is removed before the request reaches Kling.","properties":{"watermark_info":{"description":"Whether to generate watermarked results simultaneously. Custom watermarks are not supported. An explicit null is treated as absent, as the /proxy Kling 4.0 check and Kling do.","nullable":true,"properties":{"enabled":{"description":"true means generate watermarked result, false means do not generate. Default false.","type":"boolean"}},"type":"object"}},"type":"object"}},"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}}},"x-comfy-router-model-id":"kling/kling-4.0","x-comfy-input-schema-authored":true,"x-comfy-output-schema-authored":true,"x-comfy-router-input-modalities":["text","image","video"],"x-comfy-router-output-modalities":["video"]}
