{"record":{"id":"64615cfce9428d78","repo":"ATH-MaaS/Pixelle-Video","slug":"api-code-data-get-code-message-data","errorCode":null,"errorMessage":"可灵 API 错误: code={data.get('code')}, message={data.get('message')}","messagePattern":"可灵 API 错误: code=(.+?), message=(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"pixelle_video/services/api_services/video_kling.py","lineNumber":255,"sourceCode":"\n        resp = self._session.post(\n            url,\n            json=body,\n            headers=headers,\n            timeout=300,\n            proxies=_proxy_dict(self.local_proxy),\n        )\n        if not resp.ok:\n            try:\n                err_body = resp.json()\n            except Exception:\n                err_body = resp.text\n            logger.error(f\"KlingVideoClient: HTTP {resp.status_code}, 响应: {err_body}\")\n            resp.raise_for_status()\n        data = resp.json()\n\n        if data.get(\"code\") != 0:\n            raise RuntimeError(\n                f\"可灵 API 错误: code={data.get('code')}, message={data.get('message')}\"\n            )\n\n        task_id = data[\"data\"][\"task_id\"]\n        logger.info(f\"KlingVideoClient: 任务已提交 task_id={task_id}\")\n        return task_id\n\n    # ─── 查询任务 ───\n\n    def _query_task(self, task_id: str, endpoint: str = \"image2video\") -> dict:\n        \"\"\"\n        查询单个任务状态\n\n        Returns:\n            API 响应中的 data 字段\n        \"\"\"\n        url = f\"{self.base_url}/v1/videos/{endpoint}/{task_id}\"\n        headers = self._auth_headers()","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/api_services/video_kling.py#L237-L273","documentation":"Kling's submit endpoint returned HTTP 200 but the JSON body carries a non-zero business code, meaning task submission was rejected at the API level. The client raises RuntimeError with the API's code and message fields (data.code != 0).","triggerScenarios":"POST /v1/videos/{image2video|text2video} returns {\"code\": <non-zero>, \"message\": ...} in video_kling.py:254-257 — typically invalid api key/jwt, exceeded quota, invalid model_name/mode/duration combination, prompt too long (>2500 chars), or account suspension.","commonSituations":"Expired Kling access key/secret producing auth codes, using kling-v2-5-turbo with duration=\"15\" (only v3 supports 3-15s), sending sound=on with a model that doesn't support it, or free-tier rate/quota limits hit.","solutions":["Read the message in the exception; it states the exact API-side rejection reason (auth, quota, or invalid parameter).","Check/regenerate Kling API credentials and ensure the JWT (from _auth_headers) is fresh and not expired.","Align parameters with the model: v3 supports duration 3-15, v2.x only 5/10; kling-v2-5-turbo ignores sound; v2-6 sound=on requires pro mode (the client auto-switches this).","Trim prompt/negative_prompt to <=2500 characters and verify model_name is an exact Kling model id.","If the code indicates throttling/quota, wait or top up the account, then retry."],"exampleFix":"# before\nbody = {\"model_name\": \"kling-v2-5-turbo\", \"duration\": \"15\", ...}  # API 错误: invalid duration\n# after\nbody = {\"model_name\": \"kling-v3\", \"duration\": \"10\", ...}  # v3 支持 3~15s","handlingStrategy":"validation","validationCode":"assert api_key and api_secret, \"缺少可灵 API 凭证\"\nassert model_name in (\"kling-v3\", \"kling-v2-6\", \"kling-v2-5-turbo\"), f\"未知模型 {model_name}\"\nassert len(prompt) <= 2500, \"prompt 超过 2500 字符限制\"\nassert duration in (\"5\", \"10\") or model_name.startswith(\"kling-v3\"), \"该模型仅支持 5/10 秒\"","typeGuard":null,"tryCatchPattern":"try:\n    task_id = client.generate_video(...)\nexcept RuntimeError as e:\n    if str(e).startswith(\"可灵 API 错误\"):\n        code = str(e).split(\"code=\")[1].split(\",\")[0]\n        if code in (\"auth_failed\", \"401\"):\n            refresh_credentials(); retry()\n        else:\n            logger.error(f\"提交被拒绝: {e}\")  # 修正参数后重试","preventionTips":["Refresh Kling access keys/JWT before long batch runs","Match duration/mode/sound to the model family (v3: 3-15s; v2.x: 5/10; v2-5-turbo: no sound)","Keep prompt and negative_prompt <= 2500 characters","Monitor account quota/rate limits before large submissions"],"tags":["kling","api-error","auth","task-submission"],"backgroundTag":"api-business-error","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}