Comfy-Org/ComfyUI · error · Exception

Kling initial request failed. Code: {response.code}, Message

Error message

Kling initial request failed. Code: {response.code}, Message: {response.message}, Data: {response.data}

What it means

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.

Source

Thrown at comfy_api_nodes/nodes_kling.py:299

def validate_prompts(prompt: str, negative_prompt: str, max_length: int) -> bool:
    """Verifies that the positive prompt is not empty and that neither promt is too long."""
    if not prompt:
        raise ValueError("Positive prompt is empty")
    if len(prompt) > max_length:
        raise ValueError(f"Positive prompt is too long: {len(prompt)} characters")
    if negative_prompt and len(negative_prompt) > max_length:
        raise ValueError(
            f"Negative prompt is too long: {len(negative_prompt)} characters"
        )
    return True


def validate_task_creation_response(response) -> None:
    """Validates that the Kling task creation request was successful."""
    if not is_valid_task_creation_response(response):
        error_msg = f"Kling initial request failed. Code: {response.code}, Message: {response.message}, Data: {response.data}"
        logging.error(error_msg)
        raise Exception(error_msg)


def validate_video_result_response(response) -> None:
    """Validates that the Kling task result contains a video."""
    if not is_valid_video_response(response):
        error_msg = f"Kling task {response.data.task_id} succeeded but no video data found in response."
        logging.error("Error: %s.\nResponse: %s", error_msg, response)
        raise Exception(error_msg)


def validate_image_result_response(response) -> None:
    """Validates that the Kling task result contains an image."""
    if not is_valid_image_response(response):
        error_msg = f"Kling task {response.data.task_id} succeeded but no image data found in response."
        logging.error("Error: %s.\nResponse: %s", error_msg, response)
        raise Exception(error_msg)

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Read the logged error_msg — it contains Kling's code, message, and data
  2. Fix the root cause per the code (re-auth for token errors, top up for balance errors)
  3. Retry after resolving; transient malformed payloads often clear
  4. Update comfy_api_nodes if a Kling model endpoint changed
Defensive patterns

Strategy: try-catch

Try / catch

try:
    out = await kling_node(...)
except Exception as e:
    msg = str(e)
    if "Kling initial request failed" in msg:
        log.error("Kling envelope: %s", msg)
        # inspect embedded code/message/data and fix credentials/credits/params
        raise

Prevention

When it happens

Trigger: 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.

Common situations: Wrong/expired Kling credentials; credits run out mid-session; Kling model version renamed/retired; transient upstream errors during high load.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/021a6812a1eca588. Report an issue: GitHub.