{"record":{"id":"835df806a609cdda","repo":"calesthio/OpenMontage","slug":"kling-turbo-task-failed","errorCode":null,"errorMessage":"Kling Turbo task failed","messagePattern":"Kling Turbo task failed","errorType":"exception","errorClass":"KlingAPIError","httpStatus":null,"severity":"error","filePath":"tools/_kling/client.py","lineNumber":131,"sourceCode":"        timeout_seconds: int = 900,\n        poll_interval: float = 5.0,\n    ) -> list[dict[str, Any]]:\n        deadline = time.time() + timeout_seconds\n        while time.time() < deadline:\n            data = self.get(\"/tasks\", params={\"task_ids\": task_id})\n            records = data.get(\"data\") or []\n            if not records:\n                raise KlingAPIError(f\"Kling Turbo poll response missing data[0]: {data}\")\n            record = records[0]\n            status = record.get(\"status\") or record.get(\"task_status\")\n            if status == TURBO_SUCCESS_STATUS:\n                outputs = record.get(\"outputs\") or []\n                if not isinstance(outputs, list):\n                    raise KlingAPIError(\"Kling Turbo result path data[0].outputs is not a list\")\n                return outputs\n            if status == TURBO_FAILURE_STATUS:\n                message = record.get(\"message\") or record.get(\"error\") or \"Kling Turbo task failed\"\n                raise KlingAPIError(str(message), code=record.get(\"code\"), request_id=record.get(\"request_id\"), response=data)\n            if status not in TURBO_PENDING_STATUSES:\n                raise KlingAPIError(f\"Unexpected Kling Turbo task status {status!r}\", response=data)\n            time.sleep(min(poll_interval, max(0.0, deadline - time.time())))\n        raise TimeoutError(f\"Kling Turbo task {task_id} timed out after {timeout_seconds}s\")\n\n    def _request(self, method: str, path: str, **kwargs: Any) -> dict[str, Any]:\n        url = self._url(path)\n        last_error: KlingAPIError | None = None\n        for attempt in range(self.max_retries + 1):\n            try:\n                response = getattr(self.session, method)(url, headers=self.headers, timeout=30, **kwargs)\n                self._raise_for_http_error(response)\n                data = response.json()\n                self._raise_for_business_error(data)\n                return data\n            except KlingAPIError as error:\n                last_error = error\n                if attempt >= self.max_retries or not is_retryable_kling_error(error):","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/_kling/client.py#L113-L149","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect error.response -> data[0].message and the code/request_id kwargs for the exact reason","Check credits/quota on the Turbo deployment","Validate input media before submission (playable, supported format, reasonable size)","Adjust prompt or parameters and resubmit","Escalate to Kling/Turbo support with the request_id if the failure reason is opaque"],"exampleFix":"// before\noutputs = client.poll_turbo(task_id)\n\n// after\nfrom tools._kling.errors import KlingAPIError\ntry:\n    outputs = client.poll_turbo(task_id)\nexcept KlingAPIError as e:\n    raise RuntimeError(f'turbo task failed: {e} (code={e.code}, request_id={e.request_id})') from e","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\n\ndef input_media_ok(path: str) -> bool:\n    return Path(path).is_file() and Path(path).stat().st_size > 0","typeGuard":"def is_turbo_failure(exc: Exception) -> bool:\n    return isinstance(exc, KlingAPIError) and getattr(exc, 'code', None) is not None","tryCatchPattern":"try:\n    outputs = client.poll_turbo(task_id)\nexcept KlingAPIError as e:\n    logger.error('turbo failed: %s code=%s request_id=%s', e, e.code, e.request_id)\n    if is_retryable_kling_error(e):\n        outputs = client.poll_turbo(client.create_turbo(path, payload))\n    else:\n        raise","preventionTips":["Pre-validate input media files (exist, non-empty, supported codec) before creating the task","Record code/request_id from the exception for support escalation","Check quota before batch submissions"],"tags":["kling","api","turbo","async-task","generation-failed"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}