Skip to main content

Unofficial Kling AI API client, CLI and MCP server

Project description

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:

Buy Me A Coffee

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

klingai_api-0.1.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

klingai_api-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file klingai_api-0.1.0.tar.gz.

File metadata

  • Download URL: klingai_api-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for klingai_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 68d941cf4ab795cbfdb8b14b5eaf086f9c455c19b6029c9ddb4bee5f636c5582
MD5 e15e0742ab5542ef188b22fc25ce7404
BLAKE2b-256 4b324880fa968062362a00539c36362f9aef217a985084b9fa9f730ad322b2ba

See more details on using hashes here.

File details

Details for the file klingai_api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: klingai_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for klingai_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 daea9f5dbc35939f1acfed6644421d2e53b01da5ddb3e4aba3abc72f0c702920
MD5 e8dbaefb43be046678c1663940fb32ff
BLAKE2b-256 0f96d89b94f6823a70e25a4d3e658178a0dbde65145967167335078d3ac60d4f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page