AI Agent CLI for Image and Video Generation
ai agent toolsagentic codingimage generation apivideo generation api

AI Agent CLI for Image and Video Generation

2026-07-31

TL;DR: LinkModel CLI gives terminal-capable AI agents a controlled way to generate images and videos without teaching each agent a new HTTP integration. Install one npm package, authenticate with one LinkModel API key, and let Codex, Claude Code, Cursor, or another agent call models such as GPT Image 2 with one-line JSON output, stable exit codes, automatic downloads, and resumable asynchronous tasks.

An AI agent can already write prompts, inspect files, and run shell commands. The missing piece is often a dependable media tool: something the agent can invoke, validate, wait on, and recover when a video takes longer than one terminal session. LinkModel CLI turns that workflow into commands an agent can reason about.

This guide uses the official open-source LinkModel CLI. Generation requests consume API credits, but the installation and diagnostic checks below do not create media or spend generation credits.

Why use a CLI for AI agent image and video generation?

A raw API is flexible, but it makes every agent rebuild the same lifecycle: construct a request, validate model parameters, poll an asynchronous task, download signed assets, and recover from timeouts. A purpose-built CLI keeps those mechanics in one tested interface.

For an AI agent, the useful properties are operational rather than visual:

Agent requirementLinkModel CLI behavior
Predictable parsing--json writes one JSON line to stdout
Recoverable long jobs--no-wait returns a task ID; status --wait resumes it
Clear failure handlingStable exit codes distinguish usage, authentication, task, and timeout errors
Model-aware argumentsImage and video options are generated from bundled model schemas
Artifact handlingCompleted files download to the current directory by default
Secret hygieneSaved API keys are masked and stored in a mode-0600 config file

The result is a smaller tool contract for the agent. It can focus on the creative task while the CLI owns polling, downloads, and model-specific validation.

How do I install LinkModel CLI for an AI agent?

LinkModel CLI requires Node.js 20 or newer and npm. Check both before installing:

node -v
npm -v

Install the package globally:

npm install -g linkmodel-cli

The package installs two equivalent commands: the short lkm command used throughout this guide and the descriptive linkmodel alias.

Run the non-billing checks before you create any media:

lkm --version
lkm --help
lkm doctor --json
lkm models list --json

lkm doctor --json checks the local Node.js version, CLI version, configuration, API key source, authentication state, and npm update status. That makes it the safest first diagnostic for an agent because it returns structured information without launching a paid generation task.

If you want the agent to handle installation, copy the maintained setup prompt from the LinkModel CLI page. It points the agent to the official install runbook and explicitly tells it not to expose a key or run paid generation without permission.

How should an AI agent authenticate safely?

Create a key from the API Key dashboard, then configure it through a secure local terminal. Do not paste the full key into an AI chat, issue, repository file, screenshot, or generated skill.

For an interactive first-time setup:

lkm setup

The setup flow verifies the key before saving it and can also configure separate default image and video models.

For a secure automated environment, the direct command is:

lkm auth login --api-key YOUR_API_KEY
lkm auth status --json

The CLI stores its configuration in ~/.linkmodel/config.json with file mode 0600, and masks the key in normal human-readable and JSON output. Credential resolution follows this order:

--api-key > LINKMODEL_API_KEY > ~/.linkmodel/config.json

Use the narrowest source that fits the workflow. A one-off isolated job can use a temporary environment variable; a recurring local agent benefits from the protected config file.

How can an AI agent generate an image?

The shortest image command accepts a prompt and waits for the task to finish:

lkm image "a red panda wearing round glasses"

For agent automation, make the model and output format explicit:

lkm image \
  "a clean product photo of a white sneaker on glass" \
  --model gpt-image-2 \
  --size 1024x1024 \
  --quality high \
  --json

By default, the CLI downloads completed artifacts into the current directory using the task ID in the filename. Add --out ./artifacts to choose another directory, --no-download to return signed URLs instead, or --open when a human wants to inspect the result immediately.

Reference images are accepted as URLs and can be repeated:

lkm image \
  "turn this product photo into a clean studio campaign image" \
  --image https://example.com/product-front.png \
  --image https://example.com/product-side.png \
  --json

The CLI validates image size constraints before sending the request, so an agent receives a local usage error instead of spending time on a request the selected model cannot accept.

How can an AI agent generate and resume video?

Video generation often lasts longer than an agent should block one terminal command. Start the job with --no-wait:

lkm video \
  "a cinematic product orbit around a brushed aluminum speaker" \
  --model kling-v3 \
  --no-wait \
  --json

The response includes a task ID. Store that ID in the agent state, then resume polling when the workflow is ready:

lkm video status TASK_ID --wait --json

When the task succeeds, the CLI downloads the video by default. Use --no-download if another system will collect the temporary signed URL.

Server-side generation continues after a local timeout or Ctrl-C. The relevant exit codes are:

Exit codeAgent action
0Continue; the command succeeded
1Inspect the task, network, API, or download error
2Correct invalid parameters, a missing key, or command usage
3Repair authentication before retrying
4Resume the running task with status --wait
130The local process was interrupted; preserve the task ID and resume

This separation matters for autonomous workflows. A timeout is not the same as a failed generation, and blindly submitting a second paid task can create duplicate output and duplicate cost.

Why should agents prefer JSON output?

Human terminal output can contain spinners, colors, progress messages, and explanatory text. Agents need a stable contract.

With --json, LinkModel CLI writes exactly one JSON line to stdout. Human-readable logs go to stderr, and failures include an ok: false value with a readable error. That lets an agent branch on structured output without scraping terminal decoration.

lkm auth status --json
lkm models show kling-v3 --json
lkm image "a monochrome editorial portrait" --json
lkm video status TASK_ID --wait --json

For plain automation logs, set NO_COLOR=1. For long-running jobs, persist the task ID before starting another step.

What security boundaries should the agent follow?

The CLI can protect a stored credential, but the agent still controls how the key enters the machine and how commands are recorded. Give it explicit rules:

  1. Never print, log, commit, or include the full API key in a response.
  2. Never ask the user to paste a key into chat.
  3. Authenticate only through a secure local channel.
  4. Run lkm doctor --json and lkm auth status --json before paid generation.
  5. Do not generate images or video until the user explicitly approves the credit-consuming action.
  6. Treat artifact URLs as temporary signed links and download important results promptly.

The final rule is especially important. A capable agent should validate its tooling without silently consuming generation credits.

Frequently asked questions

Can Codex, Claude Code, and Cursor use LinkModel CLI?
Yes. Any AI agent that can run terminal commands and read stdout can use LinkModel CLI, including Codex, Claude Code, Cursor, and similar coding agents.

Does installing or validating LinkModel CLI consume API credits?
No. Installation, lkm --help, lkm doctor --json, authentication checks, and model inspection do not create media or consume generation credits. Image and video generation does consume LinkModel API credits.

Which image and video models does LinkModel CLI use by default?
The built-in defaults are GPT Image 2 for images and Kling 3 for videos. An agent can override either model per command or configure separate defaults for each modality.

Can an AI agent resume a video after a timeout or interruption?
Yes. The server-side task continues after a local polling timeout or Ctrl-C; preserve the task ID and run lkm video status TASK_ID --wait --json to resume.

Where does LinkModel CLI store the API key?
The CLI stores saved credentials in ~/.linkmodel/config.json with file mode 0600 and masks keys in normal output. The full key should never be pasted into chat, logs, screenshots, or repository files.

The bottom line

An AI agent does not need another custom media integration. It needs a small, inspectable tool contract that can validate locally, return structured output, preserve task state, and keep credentials out of conversation history.

Start with the LinkModel CLI page, create a scoped API key, and let the agent run the non-billing checks before you approve its first image or video.

Sources: LinkModel CLI on GitHub, official AI install guide, and linkmodel-cli on npm.

Agent-ready media generation

Give your AI agent a real media tool

Copy the maintained setup prompt, create a scoped API key, and generate images or videos from the same terminal workflow.

Related Posts