ai-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseai-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 or a provider-specific key (e.g. ) in the environment.
AI_GATEWAY_API_KEYOPENAI_API_KEY需要在环境变量中配置或特定服务商的密钥(例如)。
AI_GATEWAY_API_KEYOPENAI_API_KEYCommands
命令
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 modelsbash
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 modelsKey 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
undefinedPipe 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"
undefinedcat photo.png | ai image "make it a watercolor"
undefinedStructured Output
结构化输出
Use to get machine-readable results:
--jsonbash
ai image "a sunset" --jsonReturns:
json
{
"elapsed_ms": 3420,
"count": 1,
"results": [
{
"index": 1,
"model": "openai/gpt-image-2",
"elapsed_ms": 3420,
"success": true,
"file": "/path/to/output.png"
}
]
}使用参数获取机器可读的结果:
--jsonbash
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
- : saves inside directory with auto-generated names
-o <dir>
- 交互式(TTY): 保存到文件,在标准错误输出中打印路径
- 管道模式(非TTY): 将原始内容写入标准输出,用于链式调用
- : 将文件保存到指定目录,文件名自动生成
-o <dir>
Timeouts
超时设置
- text/image: 120 seconds
- video: 300 seconds
- 文本/图片:120秒
- 视频:300秒
Exit Codes
退出码
- — success
0 - — all generations failed
1 - — partial failure (some succeeded)
2
- — 成功
0 - — 所有生成任务失败
1 - — 部分失败(部分任务成功)
2