calesthio/OpenMontage · error · KlingAPIError

Kling TTS task failed

Error message

Kling TTS task failed

What it means

Template for a KlingAPIError raised when the create response's task_status/status is 'failed'. The actual message prefers task_status_msg, then message, then this literal default when neither field exists — so seeing the raw text 'Kling TTS task failed' means the failure payload carried no reason fields at all.

Source

Thrown at tools/audio/kling_tts.py:257

        """
        if hasattr(client, "post"):
            data = client.post(request["path"], request["payload"])
            payload = data.get("data") or {}
            task_id = payload.get("task_id")
            if not task_id:
                raise KlingAPIError(f"Kling TTS create response missing data.task_id: {data}")

            task_result = payload.get("task_result") or {}
            outputs = task_result.get("audios")
            if outputs is not None:
                if not isinstance(outputs, list):
                    raise KlingAPIError("Kling TTS result path data.task_result.audios is not a list")
                return str(task_id), outputs

            status = payload.get("task_status") or payload.get("status")
            if status == "failed":
                message = payload.get("task_status_msg") or payload.get("message") or "Kling TTS task failed"
                raise KlingAPIError(str(message), code=payload.get("task_status"), response=data)

            return str(task_id), client.poll_classic(
                request["path"],
                str(task_id),
                "audios",
                timeout_seconds=int(inputs.get("timeout_seconds", 300)),
                poll_interval=float(inputs.get("poll_interval", 3.0)),
            )

        task_id = client.create_classic_task(request["path"], request["payload"])
        return task_id, client.poll_classic(
            request["path"],
            task_id,
            "audios",
            timeout_seconds=int(inputs.get("timeout_seconds", 300)),
            poll_interval=float(inputs.get("poll_interval", 3.0)),
        )

View on GitHub (pinned to 95e1c3d0ab)

Solutions

  1. When the default text appears, log the full payload — the reason fields are missing and the code+response carry the only clues
  2. Check text content against Kling moderation policies (sensitive words, URLs)
  3. Confirm voice_id entitlement, then retry with a different voice or sanitized text
Defensive patterns

Strategy: try-catch

Try / catch

try:
    result = kling_tts_tool.execute(inputs)
except KlingAPIError as e:
    msg = str(e)
    if msg == "Kling TTS task failed":
        logger.error("kling failed without reason fields; response=%s", getattr(e, "response", None))
    raise

Prevention

When it happens

Trigger: Synchronous TTS create returns a terminal failed status immediately: content moderation rejection, invalid voice for the account, or upstream processing error.

Common situations: Text failing Kling safety review; voice_id not entitled; rare upstream incidents where the failure body omits task_status_msg/message.

Related errors


AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15). Data as JSON: /api/errors/74dced2c87b36b6d. Report an issue: GitHub.