@klingai/cli-global
v0.1.1
Published
Kling AI CLI for text-to-image, image-to-image, text-to-video, and image-to-video generation (thin MCP client)
Downloads
527
Readme
Kling CLI
Official Kling AI command-line tool for text-to-image, image-to-image, text-to-video, and image-to-video generation.
- Thin MCP client: CLI commands map 1:1 to backend MCP tools such as
text_to_imageandquery_tasks. The CLI handles argument translation, login, polling, and file upload. - Cross-platform: macOS, Linux, and Windows. Requires Node.js 18+.
- Agent-friendly: stdout is JSON by default, and non-interactive environments never block on prompts.
Installation
Kling has separate packages for different account regions. Both install the same kling command.
# Global site
npm i -g @klingai/cli-global
kling <command>Use @klingai/cli-cn instead if your account belongs to the China site.
Upgrade
npm i -g @klingai/cli-global@latest
kling --versionQuick Start
# 1. Log in with OAuth in your browser.
kling login
# 2. Discover identity, models, and parameter specs.
kling who_am_i
# 3. Generate an image and wait up to 60 seconds for the result.
kling text_to_image "a shiba inu sitting by a cafe window" --poll 60
# 4. Or submit first, then query with the returned generation_id.
kling text_to_image "a shiba inu sitting by a cafe window"
kling query_tasks <generationId> --pollGenerated assets are returned in works[].url. Watermark-free URLs, when available, are returned in works[].url_without_watermark.
Commands
Generation and query commands use the same names as the backend MCP tools. There are no aliases.
| Command | Description |
|---|---|
| who_am_i | Return current identity plus available models and parameter specs. |
| text_to_image <prompt> | Submit text-to-image generation. |
| image_to_image --image <url\|path> <prompt> | Generate from one or more reference images. |
| text_to_video <prompt> | Submit text-to-video generation. |
| image_to_video --image <url\|path> <prompt> | Submit image-to-video generation. |
| query_tasks <generationId> | Query generation status and result URLs. |
| file_upload <filePath> | Upload a local file and return a public URL. |
| account | Query membership and available credits. |
| tool_list | List tools advertised by the backend MCP server. |
| login | Browser OAuth login. |
| logout | Revoke and clear saved login state. |
Global flags:
| Flag | Description |
|---|---|
| --model <name> | Select a model from who_am_i (required unless --omni). |
| --omni | Pick the omni-family model for generation commands. |
| --skill-name <n> / --skill-version <v> | Optional telemetry: identify the calling skill (forwarded to the server; never changes behavior). |
| --poll [N] | Poll for up to N seconds. Bare --poll defaults to 60. |
| --quiet, -q | Output compact single-line JSON. |
| --help, -h | Show top-level or per-command help. |
| --version, -v | Print CLI version. |
Run kling <command> --help for command-specific usage. For MCP-backed commands, per-command help tries to fetch the live tools/list declaration (description + input schema) and falls back to local static usage when offline or not logged in.
Models And Parameters
Available models, required arguments, defaults, and allowed values are declared by the server. Run kling who_am_i for the authoritative spec. Generation commands require an explicit --model <name> unless you use --omni. Other parameters you omit are filled by the server. Unknown parameters or invalid values are rejected before billing.
Examples
Text To Image
kling text_to_image --model kling-image-v3_0 "cyberpunk city at night" \
--aspectRatio 16:9 --imgResolution 2k --imageCount 4 --poll 120
kling text_to_image --model kling-image-v3_0 "Mount Fuji in watercolor style" --poll
kling text_to_image --omni "Mount Fuji in watercolor style" --pollImage To Image
kling image_to_image --model kling-image-v3_0 --image ./cat.jpg --image ./style.png \
"Turn the cat in image 1 into the style of image 2" --poll 120Text To Video
kling text_to_video --model kling-video-v1 "drone shot flying over a snowy mountain peak" \
--duration 10 --aspectRatio 16:9 --poll 300Image To Video
kling image_to_video --model kling-video-v1 --image ./first.jpg --tailImage ./last.jpg \
"slow camera push-in" --duration 6 --poll 300Task Query And Upload
kling query_tasks <generationId>
kling query_tasks <generationId> --poll 120
kling file_upload ./photo.jpg
kling accountOutput And Exit Codes
stdout is formatted JSON by default. --quiet prints compact single-line JSON. Progress and diagnostics are written to stderr.
Exit codes: 0 for success, 1 for failure, and 130 for user cancellation.
Credentials are saved locally under ~/.kling/. The CLI never prints tokens or secrets.
License
See LICENSE in the package.
