Tutorials

How to Get a Kling API Key: A Step-by-Step Guide

On this page

In this guide, you'll learn how to get your Kling API key. You'll create a Kling AI account, generate your access key and secret key, and make your first video generation API call. We'll also show you a simpler alternative if you want text-to-video without managing API keys or billing.

Prerequisites

  • A Google, Apple, or email account for signing up
  • Basic familiarity with code (we'll show simple JavaScript examples)

Step 1: Create Your Kling AI Account

Go to app.klingai.com/global/dev. You'll see a login or sign-up page — create your account using your Google account, Apple account, or email.

Kling AI sign-up page

Step 2: Generate Your API Key

Once signed in, you'll land directly on the API keys page. Click Create a new API Key to generate a new key.

Kling AI API keys page

Give your key a descriptive name so you can identify it later.

Kling AI name your API key

After creation, you'll see both your Access Key and Secret Key. Important: Your secret key is only shown once, so make sure to copy and store it somewhere safe — a password manager, an .env file, or your platform's secrets manager. Never commit API keys to a public repository.

Kling AI access key and secret key

Step 3: Make Your First API Call

Kling doesn't have an official SDK, but you can use community-built wrappers. The kling-api package on npm handles JWT generation, auto-polling, and retry logic automatically.

Install it:

npm install kling-api

Then make a text-to-video request:

import { KlingAPI } from 'kling-api';

const api = new KlingAPI({
  accessKey: 'your-access-key',
  secretKey: 'your-secret-key'
});

const task = await api.textToVideo({
  prompt: 'A cat playing piano in a cozy room',
  model_name: 'kling-v2-master',
  duration: '5'
});

const result = await api.waitForVideoResult(task.data.task_id);
console.log('Video URL:', result.data.task_result.videos[0].url);

If you get a video URL back, everything is working. You can explore different models and parameters in the Kling AI documentation.

A Simpler Alternative with Puter.js

Kling gives you powerful video generation — but you still need to manage billing, JWT tokens, and API keys yourself.

Puter.js offers a simpler approach with the User-Pays model: your app's users cover their own AI costs. You don't need an API key at all, and you pay nothing for AI usage no matter how many users you have.

Puter.js gives you access to more text-to-video models beyond just Kling. Just add the Puter.js script tag and start generating videos:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.txt2vid(
            "A sunrise drone shot flying over a calm ocean",
            {model: "ByteDance/Seedance-1.0-lite"}
        ).then((video) => {
            document.body.appendChild(video);
        }).catch(console.error);
    </script>
</body>
</html>

No API key, no backend, no billing setup. Puter.js supports text-to-video models from multiple providers through a single puter.ai.txt2vid() function — giving you more flexibility for your video generation app.

Conclusion

You now know how to create a Kling AI account, generate your API keys, and make your first video generation API call. For more details, check out Kling AI's developer console. If you'd rather skip managing API keys and billing entirely, Puter.js gives you access to text-to-video from multiple providers through a single JavaScript library with no API keys required.

Free, Serverless AI and Cloud

Start creating powerful web applications with Puter.js in seconds!

Get Started Now

Read the Docs Try the Playground