klingai-api
Unofficial Kling AI Python SDK, CLI, and MCP server.
This package serves a dual purpose: it works as a Model Context Protocol (MCP) server that gives LLMs access to Kling AI's video generation capabilities, and as a standalone Python SDK + CLI for developers who want to integrate Kling AI into their own projects.
Quick Start (MCP)
Add to your MCP client config (Claude Desktop, Cursor, etc.):
{
"mcpServers": {
"klingai": {
"command": "pipx run",
"args": ["klingai-api", "mcp"],
"env": {
"ACCESS_TOKEN": "<your-access-key>",
"SECRET_TOKEN": "<your-secret-key>"
}
}
}
}
Or run it manually:
# stdio (default)
klingai mcp
# streamable HTTP
klingai mcp --http --port 8000
Get your API keys from the Kling AI Developer Platform.
Installation
pip install klingai-api
Requires Python 3.14+.
Authentication
Credentials can be provided via environment variables or CLI flags:
# Environment variables (recommended)
export ACCESS_TOKEN="your-access-key"
export SECRET_TOKEN="your-secret-key"
# CLI flags
klingai --access-token <key> --secret-token <key> <command>
Verify your credentials:
klingai test-credentials
CLI Usage
Every API method maps to a subcommand. Run klingai --help for the full list.
Text to Video
# Create a generation task
klingai text2video --prompt "A cat walking on the beach at sunset"
# With options
klingai text2video \
--prompt "A drone shot over a mountain range" \
--model-name kling-v2-6 \
--mode pro \
--aspect-ratio 9:16 \
--duration 10
# Check task status
klingai get-text2video --task-id <task_id>
# List all tasks
klingai list-text2video --page-num 1 --page-size 10
Image to Video
# Animate an image
klingai image2video \
--image "https://example.com/photo.jpg" \
--prompt "Gentle wind blowing through the scene"
# With camera control
klingai image2video \
--image "https://example.com/photo.jpg" \
--camera-control '{"type": "simple", "config": {"zoom": 5}}'
# Check task status
klingai get-image2video --task-id <task_id>
# List all tasks
klingai list-image2video
MCP Server
# stdio transport (for MCP clients)
klingai mcp
# streamable HTTP transport
klingai mcp --http --host 0.0.0.0 --port 8000
Python SDK
from api import KlingAiAPI
api = KlingAiAPI(
access_token="your-access-key",
secret_token="your-secret-key",
)
with api:
# Text to video
task = api.text2video("A cat walking on the beach at sunset")
print(task)
# Check status
status = api.get_text2video(task["data"]["task_id"])
print(status)
# Image to video
task = api.image2video(
"https://example.com/photo.jpg",
prompt="Gentle wind blowing",
mode="pro",
)
Available Models
| Text to Video | Image to Video |
|---|---|
kling-v1 (default) |
kling-v1 (default) |
kling-v1-6 |
kling-v1-5 |
kling-v2-master |
kling-v1-6 |
kling-v2-1-master |
kling-v2-master |
kling-v2-5-turbo |
kling-v2-1 |
kling-v2-6 |
kling-v2-1-master |
kling-v2-5-turbo |
|
kling-v2-6 |
Support
If this project saved you time or helped you build something cool, consider fueling the next feature:
License
MIT
Metadata
Release files for klingai-api 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| klingai_api-0.1.0.tar.gz | 11.1 kB | Without provenance | Details for klingai_api-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| klingai_api-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for klingai_api-0.1.0-py3-none-any.whl |
Total release size: 21.9 kB
Release files / klingai_api-0.1.0.tar.gz
| Download URL | klingai_api-0.1.0.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68d941cf4ab795cbfdb8b14b5eaf086f9c455c19b6029c9ddb4bee5f636c5582
|
|
BLAKE2b-256 checksum How to use checksums |
4b324880fa968062362a00539c36362f9aef217a985084b9fa9f730ad322b2ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / klingai_api-0.1.0-py3-none-any.whl
| Download URL | klingai_api-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
daea9f5dbc35939f1acfed6644421d2e53b01da5ddb3e4aba3abc72f0c702920
|
|
BLAKE2b-256 checksum How to use checksums |
0f96d89b94f6823a70e25a4d3e658178a0dbde65145967167335078d3ac60d4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for klingai-api 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.