{"record":{"id":"021a6812a1eca588","repo":"Comfy-Org/ComfyUI","slug":"kling-initial-request-failed-code-response-code","errorCode":null,"errorMessage":"Kling initial request failed. Code: {response.code}, Message: {response.message}, Data: {response.data}","messagePattern":"Kling initial request failed\\. Code: (.+?), Message: (.+?), Data: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_kling.py","lineNumber":299,"sourceCode":"def validate_prompts(prompt: str, negative_prompt: str, max_length: int) -> bool:\n    \"\"\"Verifies that the positive prompt is not empty and that neither promt is too long.\"\"\"\n    if not prompt:\n        raise ValueError(\"Positive prompt is empty\")\n    if len(prompt) > max_length:\n        raise ValueError(f\"Positive prompt is too long: {len(prompt)} characters\")\n    if negative_prompt and len(negative_prompt) > max_length:\n        raise ValueError(\n            f\"Negative prompt is too long: {len(negative_prompt)} characters\"\n        )\n    return True\n\n\ndef validate_task_creation_response(response) -> None:\n    \"\"\"Validates that the Kling task creation request was successful.\"\"\"\n    if not is_valid_task_creation_response(response):\n        error_msg = f\"Kling initial request failed. Code: {response.code}, Message: {response.message}, Data: {response.data}\"\n        logging.error(error_msg)\n        raise Exception(error_msg)\n\n\ndef validate_video_result_response(response) -> None:\n    \"\"\"Validates that the Kling task result contains a video.\"\"\"\n    if not is_valid_video_response(response):\n        error_msg = f\"Kling task {response.data.task_id} succeeded but no video data found in response.\"\n        logging.error(\"Error: %s.\\nResponse: %s\", error_msg, response)\n        raise Exception(error_msg)\n\n\ndef validate_image_result_response(response) -> None:\n    \"\"\"Validates that the Kling task result contains an image.\"\"\"\n    if not is_valid_image_response(response):\n        error_msg = f\"Kling task {response.data.task_id} succeeded but no image data found in response.\"\n        logging.error(\"Error: %s.\\nResponse: %s\", error_msg, response)\n        raise Exception(error_msg)\n\n","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_kling.py#L281-L317","documentation":"Raised by validate_task_creation_response when the Kling task-creation response fails is_valid_task_creation_response — no data.task_result with at least one image/video. It means the Kling call returned (possibly with code 0) but the payload lacks a usable task result. The full code/message/data envelope is embedded and logged via logging.error.","triggerScenarios":"Kling task creation returning a non-zero code, or code 0 with a malformed/incomplete data payload — auth failures, quota exhaustion, model deprecation, or upstream partial failures.","commonSituations":"Wrong/expired Kling credentials; credits run out mid-session; Kling model version renamed/retired; transient upstream errors during high load.","solutions":["Read the logged error_msg — it contains Kling's code, message, and data","Fix the root cause per the code (re-auth for token errors, top up for balance errors)","Retry after resolving; transient malformed payloads often clear","Update comfy_api_nodes if a Kling model endpoint changed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    out = await kling_node(...)\nexcept Exception as e:\n    msg = str(e)\n    if \"Kling initial request failed\" in msg:\n        log.error(\"Kling envelope: %s\", msg)\n        # inspect embedded code/message/data and fix credentials/credits/params\n        raise","preventionTips":["Validate credentials and credits up front on the Kling console","Parse the embedded code field programmatically instead of string-matching the whole message","Run a minimal smoke-test request before large batch jobs"],"tags":["kling","api-error","task-creation","response-validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}