ai-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ai-cli

ai-cli

Generate text, images, and video from the terminal using AI models.
通过AI模型从终端生成文本、图片和视频。

When to Use

使用场景

Use when you need to:
  • Generate images from text prompts or existing images
  • Generate video from text prompts or images
  • Generate text (summaries, explanations, code reviews) from prompts or piped content
  • Compare outputs across multiple models side-by-side
  • Build composable media pipelines by chaining commands via stdin/stdout
适用于以下需求:
  • 从文本提示词或现有图片生成图片
  • 从文本提示词或图片生成视频
  • 从提示词或管道输入内容生成文本(摘要、解释、代码评审)
  • 同时对比多个模型的输出结果
  • 通过标准输入/输出链式调用命令,构建可组合的媒体处理流程

Prerequisites

前置条件

Requires
AI_GATEWAY_API_KEY
or a provider-specific key (e.g.
OPENAI_API_KEY
) in the environment.
需要在环境变量中配置
AI_GATEWAY_API_KEY
或特定服务商的密钥(例如
OPENAI_API_KEY
)。

Commands

命令

bash
ai text "explain this code"              # generate text
ai image "a sunset over mountains"       # generate an image
ai video "a spinning triangle"           # generate a video
ai models --type image                   # list available models
bash
ai text "explain this code"              # generate text
ai image "a sunset over mountains"       # generate an image
ai video "a spinning triangle"           # generate a video
ai models --type image                   # list available models

Key Flags

关键参数

-m, --model <id>       Model ID (provider/name or short name), comma-separated for multi-model
-o, --output <path>    Output file or directory
-n, --count <n>        Number of generations per model
-q, --quiet            Suppress progress output
--json                 Output structured metadata as JSON (paths, timing, success/failure)
-m, --model <id>       Model ID (provider/name or short name), comma-separated for multi-model
-o, --output <path>    Output file or directory
-n, --count <n>        Number of generations per model
-q, --quiet            Suppress progress output
--json                 Output structured metadata as JSON (paths, timing, success/failure)

Piping Patterns

管道使用模式

Chain commands for agent workflows:
bash
undefined
通过链式命令构建Agent工作流:
bash
undefined

Pipe content in for summarization

管道输入内容进行摘要

cat file.txt | ai text "summarize this" git diff | ai text "write a commit message"
cat file.txt | ai text "summarize this" git diff | ai text "write a commit message"

Image-to-video pipeline

图片转视频流程

ai image "a dragon" | ai video "animate this"
ai image "a dragon" | ai video "animate this"

Image editing via stdin

通过标准输入编辑图片

cat photo.png | ai image "make it a watercolor"
undefined
cat photo.png | ai image "make it a watercolor"
undefined

Structured Output

结构化输出

Use
--json
to get machine-readable results:
bash
ai image "a sunset" --json
Returns:
json
{
  "elapsed_ms": 3420,
  "count": 1,
  "results": [
    {
      "index": 1,
      "model": "openai/gpt-image-2",
      "elapsed_ms": 3420,
      "success": true,
      "file": "/path/to/output.png"
    }
  ]
}
使用
--json
参数获取机器可读的结果:
bash
ai image "a sunset" --json
返回结果:
json
{
  "elapsed_ms": 3420,
  "count": 1,
  "results": [
    {
      "index": 1,
      "model": "openai/gpt-image-2",
      "elapsed_ms": 3420,
      "success": true,
      "file": "/path/to/output.png"
    }
  ]
}

Multi-Model Comparison

多模型对比

bash
ai image "a sunset" -m "openai/gpt-image-1,bfl/flux-2-pro,xai/grok-imagine-image"
bash
ai image "a sunset" -m "openai/gpt-image-1,bfl/flux-2-pro,xai/grok-imagine-image"

Output Behavior

输出行为

  • Interactive (TTY): saves to file, prints path to stderr
  • Piped (non-TTY): writes raw content to stdout for chaining
  • -o <dir>
    : saves inside directory with auto-generated names
  • 交互式(TTY): 保存到文件,在标准错误输出中打印路径
  • 管道模式(非TTY): 将原始内容写入标准输出,用于链式调用
  • -o <dir>
    : 将文件保存到指定目录,文件名自动生成

Timeouts

超时设置

  • text/image: 120 seconds
  • video: 300 seconds
  • 文本/图片:120秒
  • 视频:300秒

Exit Codes

退出码

  • 0
    — success
  • 1
    — all generations failed
  • 2
    — partial failure (some succeeded)
  • 0
    — 成功
  • 1
    — 所有生成任务失败
  • 2
    — 部分失败(部分任务成功)