/klingai-pack:klingai-common-errorsfrom klingai-pack
Diagnoses and fixes common Kling AI API errors including HTTP status codes, task failures, JWT issues, and generation-specific problems. Useful when troubleshooting failed video generation or API issues.
Ships in klingai-pack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Complete error reference for the Kling AI API. Covers HTTP status codes, task-level failures, JWT issues, and generation-specific problems with tested solutions.
| Code | Error | Cause | Solution |
|---|---|---|---|
400 | Bad Request | Invalid parameters, malformed JSON | Validate all required fields; check model_name is valid |
401 | Unauthorized | Invalid/expired JWT token | Regenerate JWT; verify AK/SK; check exp claim |
402 | Payment Required | Insufficient credits | Top up API resource pack or subscription |
403 | Forbidden | Content policy violation or API disabled | Review prompt against content policy; enable API access |
404 | Not Found | Invalid task_id or wrong endpoint | Verify task_id; check endpoint path spelling |
429 | Too Many Requests | Rate limit exceeded | Implement exponential backoff (see pattern below) |
500 | Internal Server Error | Kling platform issue | Retry after 30s; if persistent, check status page |
502 | Bad Gateway | Upstream service unavailable | Retry with backoff; typically transient |
503 | Service Unavailable | System maintenance | Wait and retry; check announcements |
When HTTP returns 200 but task_status is "failed":
task_status_msg | Cause | Solution |
|---|---|---|
| Content policy violation | Prompt contains restricted content | Remove violent, adult, or copyrighted references |
| Image quality too low | Source image is blurry or too small | Use image >= 300x300px, clear and sharp |
| Prompt too complex | Too many scene elements | Simplify to 1-2 subjects, clear action |
| Generation timeout | Internal processing exceeded limit | Retry; reduce duration from 10s to 5s |
| Invalid image format | Unsupported file type | Use JPG, PNG, or WebP |
| Mask dimension mismatch | Mask size differs from source | Ensure mask matches source image dimensions exactly |
401 on every request# WRONG — missing headers parameter
token = jwt.encode(payload, sk, algorithm="HS256")
# CORRECT — include explicit headers
token = jwt.encode(payload, sk, algorithm="HS256",
headers={"alg": "HS256", "typ": "JWT"})
# WRONG — token generated once at import time
TOKEN = generate_token()
# CORRECT — refresh before expiry
class TokenManager:
def __init__(self, ak, sk):
self.ak, self.sk = ak, sk
self._token = None
self._exp = 0
@property
def token(self):
if time.time() >= self._exp - 300: # 5 min buffer
payload = {"iss": self.ak, "exp": int(time.time()) + 1800,
"nbf": int(time.time()) - 5}
self._token = jwt.encode(payload, self.sk, algorithm="HS256",
headers={"alg": "HS256", "typ": "JWT"})
self._exp = int(time.time()) + 1800
return self._token
import time
import requests
def request_with_backoff(method, url, headers, json=None, max_retries=5):
"""Retry with exponential backoff on 429 and 5xx errors."""
for attempt in range(max_retries):
response = method(url, headers=headers, json=json)
if response.status_code == 429:
retry_after = int(response.headers.get("Retry-After", 2 ** attempt))
print(f"Rate limited. Retrying in {retry_after}s...")
time.sleep(retry_after)
continue
elif response.status_code >= 500:
wait = 2 ** attempt
print(f"Server error {response.status_code}. Retrying in {wait}s...")
time.sleep(wait)
continue
response.raise_for_status()
return response
raise RuntimeError(f"Max retries ({max_retries}) exceeded")
When a generation fails, check in order:
model_name matches catalog exactlyduration must be "5" or "10" (string, not int)image_tail, dynamic_masks, and camera_control are mutually exclusiveimport logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("kling")
def debug_request(method, url, headers, json=None):
"""Log request/response for debugging."""
logger.debug(f"→ {method.__name__.upper()} {url}")
logger.debug(f"→ Body: {json}")
r = method(url, headers=headers, json=json)
logger.debug(f"← Status: {r.status_code}")
logger.debug(f"← Body: {r.text[:500]}")
return r
Produce an error-triage receipt with environment, fixture classification, error class, aggregate status/credit signal, policy/rights/draft-only checks, incident owner, cleanup proof, and rollback reference. Exclude prompts, assets, identities, and credentials.
| Condition | Response |
|---|---|
| Sensitive material appears in diagnostics | Stop collection, delete the artifact, correct redaction, and rotate/revoke access as needed. |
| Policy, rights, budget, or retention drift | Cancel tasks, remove drafts, and require owner review before retrying. |
env=ci-sandbox; error=429; retries=backoff; budget=within-cap; policy=pass; destination=draft-only; cleanup=verified is a valid triage record.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
kling-ai, api-errors, video-generation, jwt-authentication, debugging
30 skills in this plugin
/klingai-async-workflowsBuild async video generation workflows with Kling AI using queues, state machines, and
event-driven patterns. Trigger with phrases like 'klingai async', 'kling ai workflow',
'klingai pipeline', 'async video generation'.
/klingai-audit-loggingImplement audit logging for Kling AI operations for compliance and security. Use when tracking
API usage or preparing for audits. Trigger with phrases like 'klingai audit', 'kling ai audit log',
'klingai compliance log', 'video generation audit trail'.
/klingai-batch-processingProcess multiple video generation requests efficiently with Kling AI. Use when generating
batches of videos or building content pipelines. Trigger with phrases like 'klingai batch',
'kling ai bulk', 'multiple videos klingai', 'klingai parallel generation'.
/klingai-camera-controlControl camera movements in Kling AI video generation. Use when creating cinematic shots,
pans, tilts, zooms, or dolly moves. Trigger with phrases like 'klingai camera',
'kling ai camera motion', 'klingai cinematic', 'klingai pan zoom'.
/klingai-ci-integrationIntegrate Kling AI video generation into CI/CD pipelines. Use when automating video content
in GitHub Actions or GitLab CI. Trigger with phrases like 'klingai ci', 'kling ai github actions',
'klingai automation', 'automated video generation'.
/klingai-compliance-reviewSecurity and compliance review framework for Kling AI integrations. Use when preparing for
audits or reviewing security posture. Trigger with phrases like 'klingai compliance',
'kling ai security review', 'klingai audit prep', 'video generation compliance'.
npx claudepluginhub jeremylongshore/tons-of-skills-marketplace --plugin klingai-packOther plugins' skills for the same job