replicate-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReplicate CLI
Replicate CLI
The Replicate CLI is a command-line tool for interacting with Replicate's AI model platform. It enables running predictions, managing models, creating deployments, and fine-tuning models directly from the terminal.
Replicate CLI是一款用于与Replicate AI模型平台交互的命令行工具,它支持直接在终端中运行预测、管理模型、创建部署以及微调模型。
Authentication
身份验证
Before using the Replicate CLI, set the API token:
bash
export REPLICATE_API_TOKEN=<token-from-replicate.com/account>Alternatively, authenticate interactively:
bash
replicate auth loginVerify authentication:
bash
replicate account current使用Replicate CLI之前,需设置API令牌:
bash
export REPLICATE_API_TOKEN=<token-from-replicate.com/account>或者,通过交互式方式进行身份验证:
bash
replicate auth login验证身份状态:
bash
replicate account currentCore Commands
核心命令
Running Predictions
运行预测
The primary use case is running predictions against hosted models.
Basic prediction:
bash
replicate run <owner/model> input_key=valueExamples:
Image generation:
bash
replicate run stability-ai/sdxl prompt="a studio photo of a rainbow colored corgi"Text generation with streaming:
bash
replicate run meta/llama-2-70b-chat --stream prompt="Tell me a joke"Prediction flags:
- - Stream output tokens in real-time (for text models)
--stream - - Submit prediction without waiting for completion
--no-wait - - Open prediction in browser
--web - - Output result as JSON
--json - - Save outputs to local directory
--save - - Specify output directory (default:
--output-directory <dir>)./{prediction-id}
主要使用场景是针对托管模型运行预测。
基础预测:
bash
replicate run <owner/model> input_key=value示例:
图像生成:
bash
replicate run stability-ai/sdxl prompt="a studio photo of a rainbow colored corgi"流式文本生成:
bash
replicate run meta/llama-2-70b-chat --stream prompt="Tell me a joke"预测参数:
- - 实时流式输出令牌(适用于文本模型)
--stream - - 提交预测后无需等待完成
--no-wait - - 在浏览器中打开预测页面
--web - - 以JSON格式输出结果
--json - - 将输出保存到本地目录
--save - - 指定输出目录(默认:
--output-directory <dir>)./{prediction-id}
Input Handling
输入处理
File uploads: Prefix local file paths with :
@bash
replicate run nightmareai/real-esrgan image=@photo.jpgOutput chaining: Use template syntax to chain predictions:
{{.output}}bash
replicate run stability-ai/sdxl prompt="a corgi" | \
replicate run nightmareai/real-esrgan image={{.output[0]}}文件上传: 本地文件路径前添加前缀:
@bash
replicate run nightmareai/real-esrgan image=@photo.jpg输出链式调用: 使用模板语法实现预测链式调用:
{{.output}}bash
replicate run stability-ai/sdxl prompt="a corgi" | \
replicate run nightmareai/real-esrgan image={{.output[0]}}Model Operations
模型操作
View model schema (see required inputs and outputs):
bash
replicate model schema <owner/model>
replicate model schema stability-ai/sdxl --jsonList models:
bash
replicate model list
replicate model list --jsonShow model details:
bash
replicate model show <owner/model>Create a new model:
bash
replicate model create <owner/name> \
--hardware gpu-a100-large \
--private \
--description "Model description"Model creation flags:
- - Hardware SKU (see
--hardware <sku>)references/hardware.md - /
--private- Visibility setting--public - - Model description
--description <text> - - Link to source repository
--github-url <url> - - License information
--license-url <url> - - Cover image for model page
--cover-image-url <url>
查看模型架构(了解必填输入与输出):
bash
replicate model schema <owner/model>
replicate model schema stability-ai/sdxl --json列出模型:
bash
replicate model list
replicate model list --json查看模型详情:
bash
replicate model show <owner/model>创建新模型:
bash
replicate model create <owner/name> \
--hardware gpu-a100-large \
--private \
--description "Model description"模型创建参数:
- - 硬件SKU(详见
--hardware <sku>)references/hardware.md - /
--private- 可见性设置--public - - 模型描述
--description <text> - - 源代码仓库链接
--github-url <url> - - 许可证信息
--license-url <url> - - 模型页面封面图
--cover-image-url <url>
Training (Fine-tuning)
训练(微调)
Fine-tune models using the training command:
bash
replicate train <base-model> \
--destination <owner/new-model> \
input_key=valueExample - Fine-tune SDXL with DreamBooth:
bash
replicate train stability-ai/sdxl \
--destination myuser/custom-sdxl \
--web \
input_images=@training-images.zip \
use_face_detection_instead=trueList trainings:
bash
replicate training listShow training details:
bash
replicate training show <training-id>使用训练命令微调模型:
bash
replicate train <base-model> \
--destination <owner/new-model> \
input_key=value示例 - 使用DreamBooth微调SDXL:
bash
replicate train stability-ai/sdxl \
--destination myuser/custom-sdxl \
--web \
input_images=@training-images.zip \
use_face_detection_instead=true列出训练任务:
bash
replicate training list查看训练任务详情:
bash
replicate training show <training-id>Deployments
部署
Deployments provide dedicated, always-on inference endpoints with predictable performance.
Create deployment:
bash
replicate deployments create <name> \
--model <owner/model> \
--hardware <sku> \
--min-instances 1 \
--max-instances 3Example:
bash
replicate deployments create text-to-image \
--model stability-ai/sdxl \
--hardware gpu-a100-large \
--min-instances 1 \
--max-instances 5Update deployment:
bash
replicate deployments update <name> \
--max-instances 10 \
--version <version-id>List deployments:
bash
replicate deployments listShow deployment details and schema:
bash
replicate deployments show <name>
replicate deployments schema <name>部署功能提供专用的、始终在线的推理端点,性能可预测。
创建部署:
bash
replicate deployments create <name> \
--model <owner/model> \
--hardware <sku> \
--min-instances 1 \
--max-instances 3示例:
bash
replicate deployments create text-to-image \
--model stability-ai/sdxl \
--hardware gpu-a100-large \
--min-instances 1 \
--max-instances 5更新部署:
bash
replicate deployments update <name> \
--max-instances 10 \
--version <version-id>列出部署:
bash
replicate deployments list查看部署详情与架构:
bash
replicate deployments show <name>
replicate deployments schema <name>Hardware
硬件
List available hardware options:
bash
replicate hardware listSee for detailed hardware information and selection guidelines.
references/hardware.md列出可用的硬件选项:
bash
replicate hardware list详见获取硬件详细信息与选型指南。
references/hardware.mdScaffolding
脚手架
Create a local development environment from an existing prediction:
bash
replicate scaffold <prediction-id-or-url> --template=<node|python>This generates a project with the prediction's model and inputs pre-configured.
从现有预测创建本地开发环境:
bash
replicate scaffold <prediction-id-or-url> --template=<node|python>该命令会生成一个预配置好预测模型与输入参数的项目。
Command Aliases
命令别名
For convenience, these aliases are available:
| Alias | Equivalent Command |
|---|---|
| |
| |
| |
Short aliases for subcommands:
- =
replicate mreplicate model - =
replicate preplicate prediction - =
replicate treplicate training - =
replicate dreplicate deployments - =
replicate hwreplicate hardware - =
replicate areplicate account
为方便使用,提供以下命令别名:
| 别名 | 等效命令 |
|---|---|
| |
| |
| |
子命令的短别名:
- =
replicate mreplicate model - =
replicate preplicate prediction - =
replicate treplicate training - =
replicate dreplicate deployments - =
replicate hwreplicate hardware - =
replicate areplicate account
Common Workflows
常见工作流
Image Generation Pipeline
图像生成流水线
Generate an image and upscale it:
bash
replicate run stability-ai/sdxl \
prompt="professional photo of a sunset" \
negative_prompt="blurry, low quality" | \
replicate run nightmareai/real-esrgan \
image={{.output[0]}} \
--save生成图像并进行超分辨率处理:
bash
replicate run stability-ai/sdxl \
prompt="professional photo of a sunset" \
negative_prompt="blurry, low quality" | \
replicate run nightmareai/real-esrgan \
image={{.output[0]}} \
--saveCheck Model Inputs Before Running
运行前检查模型输入
Always check the model schema to understand required inputs:
bash
replicate model schema owner/model-name运行前务必查看模型架构,了解必填输入:
bash
replicate model schema owner/model-nameBatch Processing
批量处理
Run predictions and save outputs:
bash
for prompt in "cat" "dog" "bird"; do
replicate run stability-ai/sdxl prompt="$prompt" --save --output-directory "./outputs/$prompt"
done运行预测并保存输出:
bash
for prompt in "cat" "dog" "bird"; do
replicate run stability-ai/sdxl prompt="$prompt" --save --output-directory "./outputs/$prompt"
doneMonitor Long-Running Tasks
监控长时间运行的任务
Submit without waiting, then check status:
bash
undefined提交任务后无需等待,后续再检查状态:
bash
undefinedSubmit
提交任务
replicate run owner/model input=value --no-wait --json > prediction.json
replicate run owner/model input=value --no-wait --json > prediction.json
Check status later
后续检查状态
replicate prediction show $(jq -r '.id' prediction.json)
undefinedreplicate prediction show $(jq -r '.id' prediction.json)
undefinedBest Practices
最佳实践
-
Always check schema first - Runto understand required and optional inputs before running predictions.
replicate model schema <model> -
Use streaming for text models - Addflag when running language models to see output in real-time.
--stream -
Save outputs explicitly - Useand
--saveto organize prediction outputs.--output-directory -
Use JSON output for automation - Addflag when parsing outputs programmatically.
--json -
Open in web for debugging - Addflag to view predictions in the Replicate dashboard for detailed logs.
--web -
Chain predictions efficiently - Use thesyntax to pass outputs between models without intermediate saves.
{{.output}}
-
务必先查看架构 - 运行以了解运行预测前需要的必填与可选输入。
replicate model schema <model> -
文本模型使用流式输出 - 运行语言模型时添加参数,实时查看输出内容。
--stream -
显式保存输出 - 使用与
--save参数来整理预测输出文件。--output-directory -
自动化场景使用JSON输出 - 当需要以编程方式解析输出时,添加参数。
--json -
调试时使用网页查看 - 添加参数,在Replicate控制台中查看预测的详细日志。
--web -
高效实现链式预测 - 使用语法在模型间传递输出,无需中间保存文件。
{{.output}}
Troubleshooting
故障排查
Authentication errors:
- Verify is set correctly
REPLICATE_API_TOKEN - Run to test authentication
replicate account current
Model not found:
- Check model name format:
owner/model-name - Verify model exists at replicate.com
Input validation errors:
- Run to see required inputs
replicate model schema <model> - Check input types (string, number, file)
File upload issues:
- Ensure prefix is used for local files
@ - Verify file path is correct and file exists
身份验证错误:
- 确认已正确设置
REPLICATE_API_TOKEN - 运行测试身份验证状态
replicate account current
模型未找到:
- 检查模型名称格式:
owner/model-name - 确认模型在replicate.com上存在
输入验证错误:
- 运行查看必填输入
replicate model schema <model> - 检查输入类型(字符串、数字、文件)
文件上传问题:
- 确保本地文件路径前添加了前缀
@ - 确认文件路径正确且文件存在
Additional Resources
额外资源
- Replicate documentation: https://replicate.com/docs
- Model explorer: https://replicate.com/explore
- API reference: https://replicate.com/docs/reference/http
- GitHub repository: https://github.com/replicate/cli
- Replicate官方文档:https://replicate.com/docs
- 模型探索器:https://replicate.com/explore
- API参考:https://replicate.com/docs/reference/http
- GitHub仓库:https://github.com/replicate/cli