KL

klingai-install-auth

Step-by-step guide to configuring authentication for Kling AI, including credential storage and JWT token generation.

Install

mkdir -p .claude/skills/klingai-install-auth && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/5339" && unzip -o skill.zip -d .claude/skills/klingai-install-auth && rm skill.zip

Installs to .claude/skills/klingai-install-auth

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Set up Kling AI API authentication with JWT tokens. Use when starting
69 chars✓ has a “when” trigger
Intermediate

Key capabilities

  • Generate short-lived JWT tokens for API authentication
  • Configure environment variables for API credentials
  • Implement auto-refreshing token management
  • Verify API connectivity and authentication status
  • Handle clock skew in token generation

How it works

The authentication process generates a JWT signed with the Secret Key, including an expiration time, which is then passed in the Authorization header of API requests.

Inputs & outputs

You give it
Access Key and Secret Key
You get back
JWT Bearer token

When to use klingai-install-auth

  • Configuring environment variables for API keys
  • Generating short-lived JWT tokens
  • Troubleshooting authentication issues
  • Setting up initial API credentials

About this skill

Kling AI Install & Auth

Overview

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

Prerequisites

  • Kling AI account at klingai.com
  • API access enabled (self-service, no waitlist)
  • Python 3.8+ with PyJWT or Node.js 18+

Step 1 — Get Credentials

  1. Sign in at app.klingai.com/global/dev
  2. Navigate to API Keys in the developer console
  3. Click Create API Key to generate an Access Key + Secret Key pair
  4. Store both values securely — the Secret Key is shown only once
# .env file
KLING_ACCESS_KEY="ak_your_access_key_here"
KLING_SECRET_KEY="sk_your_secret_key_here"

Step 2 — Generate JWT Token

Python

import 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>

Node.js

import 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" } });
}

Step 3 — Verify Authentication

import 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")

Token Management Pattern

import 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 Handling

ErrorCauseFix
401 UnauthorizedInvalid/expired JWTRegenerate token, check AK/SK
403 ForbiddenAPI access not enabledEnable API in developer console
JWT decode errorWrong secret keyVerify SK matches the AK pair
Token expired>30 min since generationImplement auto-refresh (see above)
Clock skew errorServer time mismatchUse nbf: now - 5 for tolerance

Security Checklist

  • Never commit AK/SK to version control
  • Use .env files with .gitignore exclusion
  • Rotate keys quarterly via the developer console
  • Use separate keys per environment (dev/staging/prod)
  • Set exp to 1800s max (Kling enforces this ceiling)

Resources

When not to use it

  • Committing API keys to version control
  • Using tokens with an expiration longer than 30 minutes

Prerequisites

Kling AI accountPython 3.8+ or Node.js 18+

Limitations

  • Tokens expire after 30 minutes
  • Secret Key is only displayed once upon creation

How it compares

This workflow implements dynamic token generation and management instead of using static, long-lived API keys.

Compared to similar skills

klingai-install-auth side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
klingai-install-auth (this skill)127dCautionIntermediate
lindy-install-auth427dCautionBeginner
evernote-install-auth127dReviewBeginner
instantly-install-auth127dCautionBeginner

Try saying

Example prompts that trigger this skill in your AI assistant.

More by jeremylongshore

View all by jeremylongshore

analyzing-logs

jeremylongshore

Analyze application logs to detect performance issues, identify error patterns, and improve stability by extracting key insights.

14123

ollama-setup

jeremylongshore

Configure auto-configure Ollama when user needs local LLM deployment, free AI alternatives, or wants to eliminate hosted API costs. Trigger phrases: "install ollama", "local AI", "free LLM", "self-hosted AI", "replace OpenAI", "no API costs". Use when appropriate context detected. Trigger with relevant phrases based on skill purpose.

1167

backtesting-trading-strategies

jeremylongshore

Backtest crypto and traditional trading strategies against historical data. Calculates performance metrics (Sharpe, Sortino, max drawdown), generates equity curves, and optimizes strategy parameters. Use when user wants to test a trading strategy, validate signals, or compare approaches. Trigger with phrases like "backtest strategy", "test trading strategy", "historical performance", "simulate trades", "optimize parameters", or "validate signals".

1071

generating-database-seed-data

jeremylongshore

Process this skill enables AI assistant to generate realistic test data and database seed scripts for development and testing environments. it uses faker libraries to create realistic data, maintains relational integrity, and allows configurable data volumes. u... Use when working with databases or data models. Trigger with phrases like 'database', 'query', or 'schema'.

1033

cursor-codebase-indexing

jeremylongshore

Execute set up and optimize Cursor codebase indexing. Triggers on "cursor index setup", "codebase indexing", "index codebase", "cursor semantic search". Use when working with cursor codebase indexing functionality. Trigger with phrases like "cursor codebase indexing", "cursor indexing", "cursor".

885

testing-mobile-apps

jeremylongshore

Execute mobile app testing on iOS and Android devices/simulators. Use when performing specialized testing. Trigger with phrases like "test mobile app", "run iOS tests", or "validate Android functionality".

810

You might also like

lindy-install-auth

jeremylongshore

Install and configure Lindy AI SDK/CLI authentication. Use when setting up a new Lindy integration, configuring API keys, or initializing Lindy in your project. Trigger with phrases like "install lindy", "setup lindy", "lindy auth", "configure lindy API key".

410

evernote-install-auth

jeremylongshore

Install and configure Evernote SDK and OAuth authentication. Use when setting up a new Evernote integration, configuring API keys, or initializing Evernote in your project. Trigger with phrases like "install evernote", "setup evernote", "evernote auth", "configure evernote API", "evernote oauth".

14

instantly-install-auth

jeremylongshore

Install and configure Instantly SDK/CLI authentication. Use when setting up a new Instantly integration, configuring API keys, or initializing Instantly in your project. Trigger with phrases like "install instantly", "setup instantly", "instantly auth", "configure instantly API key".

12

documenso-install-auth

jeremylongshore

Install and configure Documenso SDK/API authentication. Use when setting up a new Documenso integration, configuring API keys, or initializing Documenso in your project. Trigger with phrases like "install documenso", "setup documenso", "documenso auth", "configure documenso API key".

11

deepgram-install-auth

jeremylongshore

Install and configure Deepgram SDK/CLI authentication. Use when setting up a new Deepgram integration, configuring API keys, or initializing Deepgram in your project. Trigger with phrases like "install deepgram", "setup deepgram", "deepgram auth", "configure deepgram API key".

10

fireflies-install-auth

jeremylongshore

Install and configure Fireflies.ai SDK/CLI authentication. Use when setting up a new Fireflies.ai integration, configuring API keys, or initializing Fireflies.ai in your project. Trigger with phrases like "install fireflies", "setup fireflies", "fireflies auth", "configure fireflies API key".

01

Search skills

Search the agent skills registry