Limited-Time Offer: Save up to 55% and Enjoy Seedance from Just $0.02/sec.Try Now
← Back to blog

Free Kling 4.0 API Guide: Create Your First Video with SeeGen AI

Grace7 min read
Free Kling 4.0 API Guide: Create Your First Video with SeeGen AI
Contents

A few reference images can give a video a clear starting point, a sequence of movements, and a final pose. With the Kling 4.0 API on SeeGen AI, you can send those images from a local project and retrieve the finished video through code.

This tutorial walks through a 10-second, 720p music video featuring five adult performers. We use ten keyframe images to guide their choreography, with a text prompt describing movement, camera work, and sound.

The example runs in VS Code with Node.js. Its script uploads your images, submits the generation request, checks progress, and downloads the MP4. You can follow the same workflow with your own characters and scenes.

Kling 4.0 API Guide

What you need before you start

seegen ai
seegen ai

Prepare a SeeGen AI account, an API key, Node.js 22 or later, and the sample project accompanying this guide. You also need ten JPG or PNG keyframe images and enough account credits for generation.

This guide uses SeeGen AI's consumer platform, where the website and API share an account credit balance. The enterprise platform has separate pricing and setup instructions.

Our example costs 540 credits at 720p. If you are using complimentary credits, check your balance before submitting the full request.

How to use the Kling 4.0 API on SeeGen AI

Step 1: Create your API key

seegen api key
seegen api key

Sign in to SeeGen AI and open Account Settings to create an API key. Copy it when it appears and store it in a local .env file inside the tutorial project:

API_KEY=your_seegen_api_key

Replace the placeholder with your own key. The script reads this value when you run it and includes it in the request's authorization header.

Keep .env out of your public GitHub repository. If you record your screen, close the file before recording. The sample project includes a .gitignore file to help exclude credentials and generated files.

Step 2: Prepare your keyframes and prompt

Put ten numbered images in the project's multi-keyframe folder. Use filenames such as 01.png, 02.png, and 10.png so their order is easy to check.

keyframes
keyframes

The script sorts filenames numerically and assigns their roles:

  • The first image becomes first_frame.
  • Images two through nine become middle_frame.
  • The final image becomes last_frame.

This sample requires exactly ten images. That is a requirement of this particular script, rather than a requirement for every Kling workflow.

For the music video, choose frames that show the same performers, outfits, and stage. Each image should contribute a useful change in pose or formation. Similar framing also makes the sequence easier to plan.

Write your instructions in prompt.txt. For example:

Create a 10-second music video with the five adult performers shown in @Image1 through @Image10. Follow the keyframe sequence. Keep their faces, hairstyles, outfits, and silver-blue stage consistent. Use coordinated footwork, shoulder movements, and flowing formation changes. Keep the dancers' full bodies visible. Add original electronic dance-pop music and clear female vocals singing "We light it up" and "Watch us shine." No subtitles.
prompt
prompt

Describe what happens between poses. The images establish visual references; the prompt gives the movement its direction.

Step 3: Open the project in VS Code

Open the tutorial folder in VS Code. Its main files should look like this:

seegen-api/
multi-keyframe/
01.png ... 10.png
.env
.env.example
.gitignore
generate.mjs
package.json
prompt.txt

Open VS Code's terminal in this folder and check Node.js:

node --version

The project uses Node's built-in features and has no additional npm dependencies. Run the local check before uploading:

npm run check

This prints the image order and prepared request. It checks the image count, file sizes, PNG dimensions, and whether your prompt is empty. JPG dimensions are checked by the API. The local check makes no network requests and spends no credits.

Step 4: Upload the images and submit your request

Start the workflow:

npm start

The script uploads each image to:

POST https://seegen.ai/api/v1/assets/upload?model=kling-4.0

It waits for the uploaded assets to become usable, then inserts their returned URLs into the generation request. You do not need to upload files manually or copy URLs between tools.

The request settings in generate.mjs are:

{
model: "kling-4.0",
inputs: {
videoWorkflowTab: "multi-keyframe",
duration: "10s",
outputResolution: "720p",
prompt,
media
}
}

Here, prompt comes from prompt.txt, and media contains the uploaded URLs, image IDs, and frame roles. These variables are prepared by the full script; this snippet shows the request structure.

The script submits it to /api/v1/jobs/createTask. A successful submission returns a task ID, which it saves in last-task.json.

For field definitions and other workflows, see the Kling 4.0 multi-keyframe API documentation.

Step 5: Check progress and download the video

After submission, the script checks the task every five seconds using /api/v1/jobs/queryTask. Leave the terminal open while generation runs.

When the task completes, the script saves the response in result.json and downloads the video as kling-TASK_ID.mp4 in your project folder.

If you close the terminal, running npm start again resumes the saved task. You can also check a specific task:

npm start -- YOUR_TASK_ID

To generate a new video after changing your images or prompt, run:

npm start -- --new

That command submits a new, separately charged generation. A local waiting timeout does not mean the server task has stopped, so check the existing task before starting another.

How much does this Kling 4.0 API example cost?

Keyframe images use the pricing tier without reference-video input. At 720p, the rate is 54 credits per output second, so this example uses:

10 seconds × 54 credits = 540 credits.

At 1080p, the same duration costs 800 credits. With the $500 package containing 125,000 base credits, 540 credits works out to $2.16 before any applicable top-up bonus. Other packages can have a different dollar cost per credit.

Check current API pricing before running a batch of videos.

Common problems and what to check

If the script reports a missing key, check that .env sits beside package.json and contains API_KEY with your actual value.

An insufficient-credit response means you need to fund the account before submitting again. For image errors, check the file type, size, and dimensions. Kling accepts JPG or PNG images up to 30 MB, with both dimensions at least 300 pixels.

If generation completes but the download fails, use the result URL saved in result.json or query the existing task again. You do not need another generation just to download the completed video.

FAQs about Kling 4.0 API

Do I need to upload keyframe images manually?

No. Place your images in the project's multi-keyframe folder. The script uploads them to SeeGen AI, waits until they are ready, and adds their URLs to the video request automatically.

How do I control the order of the keyframes?

Number your files in the intended sequence, such as 01.png through 10.png. The script sorts them numerically, uses the first image as the starting frame, and assigns the last image as the ending frame. The remaining images become middle frames in that order.

Does using keyframe images count as video input?

No. Keyframes are image inputs, so this tutorial uses the pricing tier without reference-video input. A 10-second video costs 540 credits at 720p or 800 credits at 1080p. Reference-video pricing applies when you include an actual video as input.

Can I use the same credits for the web interface and API?

Yes. On SeeGen AI's consumer platform, the web interface and API use the same account credit balance. Create your API key under the account holding your credits. The enterprise platform uses a separate billing system.

Can I test the Kling 4.0 API with free credits?

Yes. Register with SeeGen AI and join the Discord community to claim 200 complimentary credits. A three-second 720p video without reference-video input costs 162 credits. To try that shorter version, change the script's duration and simplify the prompt. The full 10-second example requires 540 credits.

Final thoughts

Once you have completed your first generation, you can reuse this project with new images and prompts. The script handles uploads, task submission, progress checks, and downloading, so most of your changes will happen in the keyframe folder and prompt.txt.

Start with a short sequence to check the character, movement, and visual style before spending credits on a longer video. When you are ready to submit another generation, use npm start -- --new.

You can find the request fields in the Kling 4.0 API documentation. For help with a specific task, contact [email protected] or share the task ID and error message in Discord.

Related articles