Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Set up Kling AI API authentication with JWT tokens. Use when starting a new Kling AI integration or troubleshooting auth issues. Trigger with phrases like 'kling ai setup', 'klingai api key', 'kling ai authentication', 'configure klingai'.
.claude/skills/jeremylongshore-klingai-install-auth/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-05 | ✗→✓ | ▲ Improved | 41% | 0% |
| case-14 | ✗→✓ | ▲ Improved | 80% | 0% |
| case-09 | ✓→✓ | = Same ✓ | 44% | 0% |
| case-19 | ✓→✓ | = Same ✓ | 33% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 122% | 0% |
Kling AI uses JWT (JSON Web Token) authentication. You generate a token from your Access Key (AK) and Secret Key (SK), then pass it as a Bearer token in every request. Tokens expire after 30 minutes.
Base URL: https://api.klingai.com/v1
PyJWT or Node.js 18+bash# .env file KLING_ACCESS_KEY="ak_your_access_key_here" KLING_SECRET_KEY="sk_your_secret_key_here"
pythonimport jwt import time import os def generate_kling_token(): """Generate a JWT token for Kling AI API authentication.""" ak = os.environ["KLING_ACCESS_KEY"] sk = os.environ["KLING_SECRET_KEY"] headers = {"alg": "HS256", "typ": "JWT"} payload = { "iss": ak, "exp": int(time.time()) + 1800, # 30 min expiry "nbf": int(time.time()) - 5, # valid 5s ago (clock skew) } return jwt.encode(payload, sk, algorithm="HS256", headers=headers) token = generate_kling_token() # Use: Authorization: Bearer <token>
javascriptimport jwt from "jsonwebtoken"; function generateKlingToken() { const ak = process.env.KLING_ACCESS_KEY; const sk = process.env.KLING_SECRET_KEY; const payload = { iss: ak, exp: Math.floor(Date.now() / 1000) + 1800, nbf: Math.floor(Date.now() / 1000) - 5, }; return jwt.sign(payload, sk, { algorithm: "HS256", header: { typ: "JWT" } }); }
pythonimport requests BASE_URL = "https://api.klingai.com/v1" token = generate_kling_token() response = requests.get( f"{BASE_URL}/videos/text2video", # any endpoint to test auth headers={"Authorization": f"Bearer {token}"}, ) if response.status_code == 401: print("Auth failed — check AK/SK values") elif response.status_code in (200, 400): print("Auth working — credentials valid")
pythonimport time class KlingAuth: """Auto-refreshing JWT token manager.""" def __init__(self, access_key: str, secret_key: str, buffer_sec: int = 300): self.ak = access_key self.sk = secret_key self.buffer = buffer_sec # refresh 5 min before expiry self._token = None self._expires_at = 0 @property def token(self) -> str: if time.time() >= (self._expires_at - self.buffer): self._refresh() return self._token def _refresh(self): now = int(time.time()) payload = {"iss": self.ak, "exp": now + 1800, "nbf": now - 5} self._token = jwt.encode(payload, self.sk, algorithm="HS256", headers={"alg": "HS256", "typ": "JWT"}) self._expires_at = now + 1800 @property def headers(self) -> dict: return { "Authorization": f"Bearer {self.token}", "Content-Type": "application/json", }
| Error | Cause | Fix | |-------|-------|-----| | 401 Unauthorized | Invalid/expired JWT | Regenerate token, check AK/SK | | 403 Forbidden | API access not enabled | Enable API in developer console | | JWT decode error | Wrong secret key | Verify SK matches the AK pair | | Token expired | >30 min since generation | Implement auto-refresh (see above) | | Clock skew error | Server time mismatch | Use nbf: now - 5 for tolerance |
.env files with .gitignore exclusionexp to 1800s max (Kling enforces this ceiling)| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-09 | pass→pass | 6,073 | 6,934 | +14% | 1 | 1 | 0% | 1,076 | 1,551 | +44% | 0 | 0 | — |
case-19 | pass→pass | 14,749 | 15,962 | +8% | 1 | 1 | 0% | 2,436 | 3,230 | +33% | 0 | 0 | — |
case-01 | pass→pass | 11,508 | 9,619 | -16% | 1 | 1 | 0% | 1,009 | 2,238 | +122% | 0 | 0 | — |
case-02 | pass→pass | 10,260 | 12,348 | +20% | 1 | 1 | 0% | 1,999 | 3,380 | +69% | 0 | 0 | — |
case-03 | pass→pass | 10,554 | 11,833 | +12% | 1 | 1 | 0% | 1,039 | 2,297 | +121% | 0 | 0 | — |
case-04 | fail→fail | 11,978 | 11,790 | -2% | 1 | 1 | 0% | 1,076 | 2,713 | +152% | 0 | 0 | — |
case-05 | fail→pass | 10,323 | 12,866 | +25% | 1 | 1 | 0% | 2,076 | 2,937 | +41% | 0 | 0 | — |
case-06 | pass→pass | 17,242 | 15,941 | -8% | 1 | 1 | 0% | 2,249 | 3,170 | +41% | 0 | 0 | — |
case-07 | pass→pass | 13,041 | 4,145 | -68% | 1 | 1 | 0% | 1,619 | 2,141 | +32% | 0 | 0 | — |
case-08 | pass→pass | 13,301 | 9,205 | -31% | 1 | 1 | 0% | 1,132 | 1,827 | +61% | 0 | 0 | — |
case-10 | pass→pass | 12,379 | 10,771 | -13% | 1 | 1 | 0% | 2,065 | 2,411 | +17% | 0 | 0 | — |
case-11 | pass→pass | 14,466 | 3,977 | -73% | 1 | 1 | 0% | 1,625 | 2,036 | +25% | 0 | 0 | — |
case-12 | pass→pass | 13,445 | 8,735 | -35% | 1 | 1 | 0% | 2,191 | 1,998 | -9% | 0 | 0 | — |
case-13 | pass→pass | 12,702 | 10,269 | -19% | 1 | 1 | 0% | 1,265 | 2,236 | +77% | 0 | 0 | — |
case-24 | pass→pass | 9,763 | 8,221 | -16% | 1 | 1 | 0% | 1,722 | 1,988 | +15% | 0 | 0 | — |
case-14 | fail→pass | 11,991 | 7,342 | -39% | 1 | 1 | 0% | 977 | 1,761 | +80% | 0 | 0 | — |
case-15 | pass→pass | 11,216 | 10,396 | -7% | 1 | 1 | 0% | 2,265 | 2,479 | +9% | 0 | 0 | — |
case-16 | pass→pass | 13,414 | 6,078 | -55% | 1 | 1 | 0% | 1,750 | 2,590 | +48% | 0 | 0 | — |
case-17 | pass→pass | 16,550 | 8,352 | -50% | 1 | 1 | 0% | 1,870 | 1,792 | -4% | 0 | 0 | — |
case-18 | pass→pass | 11,630 | 3,233 | -72% | 1 | 1 | 0% | 1,895 | 1,900 | +0% | 0 | 0 | — |
case-20 | pass→pass | 15,856 | 2,479 | -84% | 1 | 1 | 0% | 1,860 | 1,641 | -12% | 0 | 0 | — |
case-21 | pass→pass | 15,993 | 7,391 | -54% | 1 | 1 | 0% | 2,141 | 1,832 | -14% | 0 | 0 | — |
case-22 | pass→pass | 16,661 | 9,407 | -44% | 1 | 1 | 0% | 2,259 | 2,604 | +15% | 0 | 0 | — |
case-23 | pass→pass | 10,898 | 7,207 | -34% | 1 | 1 | 0% | 1,059 | 1,667 | +57% | 0 | 0 | — |
case-25 | pass→pass | 12,089 | 2,985 | -75% | 1 | 1 | 0% | 1,122 | 1,747 | +56% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 25 cases were attempted. The headline lift of +8 percentage points is the difference between those two pass rates over the 25 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.