{"record":{"id":"b1612648ac37b21c","repo":"Comfy-Org/ComfyUI","slug":"kling-request-failed-code-response-code-messa","errorCode":null,"errorMessage":"Kling request failed. Code: {response.code}, Message: {response.message}, Data: {response.data}","messagePattern":"Kling request failed\\. Code: (.+?), Message: (.+?), Data: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_kling.py","lineNumber":244,"sourceCode":"    \"\"\"\n    if not prompt:\n        return prompt\n\n    def _image_repl(match):\n        return f\"<<<image_{match.group('idx') or '1'}>>>\"\n\n    def _video_repl(match):\n        return f\"<<<video_{match.group('idx') or '1'}>>>\"\n\n    # (?<!\\w) avoids matching e.g. \"test@image.com\"\n    # (?!\\w) makes sure we only match @image / @image<digits> and not @imageFoo\n    prompt = re.sub(r\"(?<!\\w)@image(?P<idx>\\d*)(?!\\w)\", _image_repl, prompt)\n    return re.sub(r\"(?<!\\w)@video(?P<idx>\\d*)(?!\\w)\", _video_repl, prompt)\n\n\nasync def finish_omni_video_task(cls: type[IO.ComfyNode], response: TaskStatusResponse) -> IO.NodeOutput:\n    if response.code:\n        raise RuntimeError(\n            f\"Kling request failed. Code: {response.code}, Message: {response.message}, Data: {response.data}\"\n        )\n    final_response = await poll_op(\n        cls,\n        ApiEndpoint(path=f\"/proxy/kling/v1/videos/omni-video/{response.data.task_id}\"),\n        response_model=TaskStatusResponse,\n        status_extractor=lambda r: (r.data.task_status if r.data else None),\n    )\n    return IO.NodeOutput(await download_url_to_video_output(final_response.data.task_result.videos[0].url))\n\n\ndef is_valid_task_creation_response(response: KlingText2VideoResponse) -> bool:\n    \"\"\"Verifies that the initial response contains a task ID.\"\"\"\n    return bool(response.data.task_id)\n\n\ndef is_valid_video_response(response: KlingText2VideoResponse) -> bool:\n    \"\"\"Verifies that the response contains a task result with at least one video.\"\"\"","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_kling.py#L226-L262","documentation":"Raised in finish_omni_video_task when the Kling omni-video task-creation response carries a non-zero code. Kling's API envelope uses code/message/data; any non-zero code means the initial request (creating the video task) failed before polling began. The exception embeds Kling's own code, message, and data for diagnosis.","triggerScenarios":"POST to /proxy/kling/v1/videos/omni-video returning an envelope with a code — invalid API key, insufficient Kling credits, malformed request payload (bad model name, invalid parameters), rate limiting, or unwhitelisted region.","commonSituations":"Expired or wrong Kling JWT credentials in ComfyUI API settings; depleted Kling credits; parameter combos the omni model rejects; upstream maintenance window.","solutions":["Read the embedded Kling code/message — e.g. invalid_token means refresh API credentials, insufficient_balance means top up credits","Verify the Kling API key/secret in ComfyUI's API provider settings and re-authenticate","Check Kling credit balance and rate limits on the developer console","Simplify the request (shorter prompt, default params) to isolate a rejected field"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = await kling_omni_video_node(...)\nexcept RuntimeError as e:\n    msg = str(e)\n    if \"invalid_token\" in msg or \"unauthorized\" in msg.lower():\n        refresh_kling_credentials()\n    elif \"insufficient\" in msg.lower():\n        raise InsufficientCredits(msg)\n    else:\n        raise","preventionTips":["Keep Kling API credentials current; watch JWT expiry if you mint tokens yourself","Check the Kling developer console credit balance before batch jobs","Match on the embedded Kling code, not the generic message prefix"],"tags":["kling","video-generation","api-error","credentials"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}