DEV Community

diwushennian4955
diwushennian4955

Posted on

Kling 3.0 API: Generate Cinematic AI Videos in 3 Lines of Python Code

Kling 3.0 just launched and it's genuinely impressive — multi-shot cinematic control, native audio, 1080p output. But if you've been using PiAPI or fal.ai to access it, you're probably overpaying.

This is a complete tutorial for using the Kling 3.0 API through NexaAPI, which is 2.4x cheaper than PiAPI and 3x cheaper than fal.ai.

Setup

pip install nexaapi
# or
npm install nexaapi
Enter fullscreen mode Exit fullscreen mode

Get your free API key at nexa-api.com — no credit card.

Part 1: Text-to-Video

from nexaapi import NexaAPI
import time

client = NexaAPI(api_key='YOUR_API_KEY')

response = client.video.generate(
    model='kling-v3-pro',
    prompt='A lone astronaut walks across a red Martian landscape',
    duration=5,
    aspect_ratio='16:9',
    quality='high'
)

job_id = response['job_id']

while True:
    status = client.video.get_status(job_id)
    if status['status'] == 'completed':
        print(f"Video: {status['video_url']}")
        break
    time.sleep(5)
Enter fullscreen mode Exit fullscreen mode

Part 2: Image-to-Video

response = client.video.generate(
    model='kling-v3-pro',
    image_url='https://your-image.com/photo.jpg',
    prompt='Gentle camera zoom with parallax depth effect',
    duration=5,
    aspect_ratio='16:9'
)
Enter fullscreen mode Exit fullscreen mode

Part 3: Multi-Shot Cinematic (Kling 3.0 Exclusive)

This is the feature that makes Kling 3.0 special:

response = client.video.generate(
    model='kling-v3-pro',
    prompt='Luxury perfume commercial',
    shots=[
        {'description': 'Macro close-up of bottle', 'camera': 'zoom_out', 'duration': 2},
        {'description': 'Slow pan across vanity', 'camera': 'pan_right', 'duration': 2},
        {'description': 'Wide dramatic shot', 'camera': 'dolly_in', 'duration': 3}
    ],
    audio=True  # Native audio!
)
Enter fullscreen mode Exit fullscreen mode

JavaScript Version

import NexaAPI from 'nexaapi'; // npm install nexaapi

const client = new NexaAPI({ apiKey: 'YOUR_API_KEY' });

const response = await client.video.generate({
  model: 'kling-v3-pro',
  prompt: 'A lone astronaut on Mars',
  duration: 5,
  aspectRatio: '16:9'
});
Enter fullscreen mode Exit fullscreen mode

Pricing Comparison

Provider Kling V3 Pro 100 videos (5s)
NexaAPI $0.0333/sec $16.65
PiAPI ~$0.08/sec ~$40.00
fal.ai $0.1/sec $50.00

Links


Questions? Drop them in the comments. Happy building!

Top comments (0)