ATH-MaaS/Pixelle-Video · error · RuntimeError
可灵 API 错误: code={data.get('code')}, message={data.get('messa
Error message
可灵 API 错误: code={data.get('code')}, message={data.get('message')} What it means
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).
Source
Thrown at pixelle_video/services/api_services/video_kling.py:255
resp = self._session.post(
url,
json=body,
headers=headers,
timeout=300,
proxies=_proxy_dict(self.local_proxy),
)
if not resp.ok:
try:
err_body = resp.json()
except Exception:
err_body = resp.text
logger.error(f"KlingVideoClient: HTTP {resp.status_code}, 响应: {err_body}")
resp.raise_for_status()
data = resp.json()
if data.get("code") != 0:
raise RuntimeError(
f"可灵 API 错误: code={data.get('code')}, message={data.get('message')}"
)
task_id = data["data"]["task_id"]
logger.info(f"KlingVideoClient: 任务已提交 task_id={task_id}")
return task_id
# ─── 查询任务 ───
def _query_task(self, task_id: str, endpoint: str = "image2video") -> dict:
"""
查询单个任务状态
Returns:
API 响应中的 data 字段
"""
url = f"{self.base_url}/v1/videos/{endpoint}/{task_id}"
headers = self._auth_headers()View on GitHub (pinned to 848b054e4f)
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.
Example fix
# before
body = {"model_name": "kling-v2-5-turbo", "duration": "15", ...} # API 错误: invalid duration
# after
body = {"model_name": "kling-v3", "duration": "10", ...} # v3 支持 3~15s Defensive patterns
Strategy: validation
Validate before calling
assert api_key and api_secret, "缺少可灵 API 凭证"
assert model_name in ("kling-v3", "kling-v2-6", "kling-v2-5-turbo"), f"未知模型 {model_name}"
assert len(prompt) <= 2500, "prompt 超过 2500 字符限制"
assert duration in ("5", "10") or model_name.startswith("kling-v3"), "该模型仅支持 5/10 秒" Try / catch
try:
task_id = client.generate_video(...)
except RuntimeError as e:
if str(e).startswith("可灵 API 错误"):
code = str(e).split("code=")[1].split(",")[0]
if code in ("auth_failed", "401"):
refresh_credentials(); retry()
else:
logger.error(f"提交被拒绝: {e}") # 修正参数后重试 Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 可灵查询 API 错误: code={data.get('code')}, message={data.get('mes
- DashScope generation failed: {e}
- DashScope image generation returned no image URLs. output={g
- Image generation failed: {response.code}, {response.message}
- DashScope image edit returned no image URLs. output={getattr
AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30).
Data as JSON: /api/errors/64615cfce9428d78.
Report an issue: GitHub.