calesthio/OpenMontage · error · KlingAPIError

Kling Turbo task failed

Error message

Kling Turbo task failed

What it means

Raised when a polled Turbo task reaches TURBO_FAILURE_STATUS. The message comes from the record's message or error field, defaulting to 'Kling Turbo task failed'; code and request_id are attached to the exception for support escalation.

Source

Thrown at tools/_kling/client.py:131

        timeout_seconds: int = 900,
        poll_interval: float = 5.0,
    ) -> list[dict[str, Any]]:
        deadline = time.time() + timeout_seconds
        while time.time() < deadline:
            data = self.get("/tasks", params={"task_ids": task_id})
            records = data.get("data") or []
            if not records:
                raise KlingAPIError(f"Kling Turbo poll response missing data[0]: {data}")
            record = records[0]
            status = record.get("status") or record.get("task_status")
            if status == TURBO_SUCCESS_STATUS:
                outputs = record.get("outputs") or []
                if not isinstance(outputs, list):
                    raise KlingAPIError("Kling Turbo result path data[0].outputs is not a list")
                return outputs
            if status == TURBO_FAILURE_STATUS:
                message = record.get("message") or record.get("error") or "Kling Turbo task failed"
                raise KlingAPIError(str(message), code=record.get("code"), request_id=record.get("request_id"), response=data)
            if status not in TURBO_PENDING_STATUSES:
                raise KlingAPIError(f"Unexpected Kling Turbo task status {status!r}", response=data)
            time.sleep(min(poll_interval, max(0.0, deadline - time.time())))
        raise TimeoutError(f"Kling Turbo task {task_id} timed out after {timeout_seconds}s")

    def _request(self, method: str, path: str, **kwargs: Any) -> dict[str, Any]:
        url = self._url(path)
        last_error: KlingAPIError | None = None
        for attempt in range(self.max_retries + 1):
            try:
                response = getattr(self.session, method)(url, headers=self.headers, timeout=30, **kwargs)
                self._raise_for_http_error(response)
                data = response.json()
                self._raise_for_business_error(data)
                return data
            except KlingAPIError as error:
                last_error = error
                if attempt >= self.max_retries or not is_retryable_kling_error(error):

View on GitHub (pinned to 95e1c3d0ab)

Solutions

  1. Inspect error.response -> data[0].message and the code/request_id kwargs for the exact reason
  2. Check credits/quota on the Turbo deployment
  3. Validate input media before submission (playable, supported format, reasonable size)
  4. Adjust prompt or parameters and resubmit
  5. Escalate to Kling/Turbo support with the request_id if the failure reason is opaque

Example fix

// before
outputs = client.poll_turbo(task_id)

// after
from tools._kling.errors import KlingAPIError
try:
    outputs = client.poll_turbo(task_id)
except KlingAPIError as e:
    raise RuntimeError(f'turbo task failed: {e} (code={e.code}, request_id={e.request_id})') from e
Defensive patterns

Strategy: try-catch

Validate before calling

from pathlib import Path

def input_media_ok(path: str) -> bool:
    return Path(path).is_file() and Path(path).stat().st_size > 0

Type guard

def is_turbo_failure(exc: Exception) -> bool:
    return isinstance(exc, KlingAPIError) and getattr(exc, 'code', None) is not None

Try / catch

try:
    outputs = client.poll_turbo(task_id)
except KlingAPIError as e:
    logger.error('turbo failed: %s code=%s request_id=%s', e, e.code, e.request_id)
    if is_retryable_kling_error(e):
        outputs = client.poll_turbo(client.create_turbo(path, payload))
    else:
        raise

Prevention

When it happens

Trigger: Calling poll_turbo() after create_turbo() and the task fails server-side: moderation rejection, invalid input media (corrupt base64, unsupported codec), quota/credit exhaustion, or invalid generation parameters.

Common situations: Passing an image reference the Turbo model cannot use; prompt flagged by moderation; account billing limits reached; generating with parameter combos (duration x resolution x fps) the Turbo model does not support.

Related errors


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