Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Provides production Python client patterns for the Kling AI API: auto-refreshing JWT auth, retry and async polling, and error handling.
36% 77%+41 ptsof test cases passed
Passed 17 of 22 test cases with the skill, and 8 of 22 without it.
What is the standard root API endpoint URL that should be configured in KlingConfig for production Kling AI API calls?
Configures base URL as https://api.klingai.com/v1.
This test ran on v1. v2 is the current version and hasn’t been tested on gemini-3.6-flash yet.
3 of 3 safety checks passed
Production-ready client patterns for the Kling AI API. Covers auto-refreshing JWT, typed request/response models, exponential backoff polling, async batch submission, and structured error handling.
import jwt
import time
import os
import requests
from dataclasses import dataclass, field
from typing import Optional
@dataclass
class KlingConfig:
access_key: str = field(default_factory=lambda: os.environ["KLING_ACCESS_KEY"])
secret_key: str = field(default_factory=lambda: os.environ["KLING_SECRET_KEY"])
base_url: str = "https://api.klingai.com/v1"
token_buffer_sec: int = 300
poll_interval_sec: int = 10
max_poll_attempts: int = 120 # 20 minutes max
timeout_sec: int = 30
class KlingClient:
"""Production Kling AI client with auto-refreshing JWT."""
def __init__(self, config: Optional[KlingConfig] = None):
self.config = config or KlingConfig()
self._token = None
self._token_expires = 0
@property
def _headers(self) -> dict:
now = int(time.time())
if now >= (self._token_expires - self.config.token_buffer_sec):
payload = {"iss": self.config.access_key, "exp": now + 1800, "nbf": now - 5}
self._token = jwt.encode(payload, self.config.secret_key,
Next to this one in the catalogue, plus more from the same author.