A powerful CLI tool for interacting with the Replicate API. List models, create predictions, and manage your AI workflows directly from the terminal.
npm install -g @r-cli/replicate-
Install dependencies:
npm install
-
Build the project:
npm run build
-
Link globally (for development):
npm link
This makes the
replicatecommand available globally on your system.
The CLI will automatically prompt you for your API token on first use. Get your token from replicate.com/account/api-tokens.
Simply run any command, and you'll be prompted to enter your API token:
replicate models:list
# π No API token found.
# Get your API token from: https://replicate.com/account/api-tokens
#
# Enter your API token: ********
# β Token saved successfully!Your token is securely stored at ~/.config/replicate/config and automatically used for all future commands.
You can also authenticate explicitly using:
replicate auth:loginThe CLI checks for your API token in this order:
- Config file (recommended):
~/.config/replicate/config - Environment variable:
REPLICATE_API_TOKEN - dotenv file:
.env.localor.envin current directory
To use environment variables:
export REPLICATE_API_TOKEN=your_api_token_here
replicate models:listOr create a .env.local file:
# .env.local
REPLICATE_API_TOKEN=your_api_token_hereView current authentication status:
replicate auth:whoamiManually set or update your token:
replicate auth:login
# or
replicate config:set token r8_your_token_hereView your configuration:
replicate config:get
# or view specific value
replicate config:get tokenLogout (remove stored token):
replicate auth:logoutreplicate models:listSearch for models:
replicate models:list --search "text-to-image"Output as JSON:
replicate models:list --jsonView model information and input schema:
replicate models:show owner/model-nameExample:
replicate models:show stability-ai/stable-diffusionCreate a prediction with inline arguments:
replicate predictions:create owner/model-name --key1=value1 --key2=value2Example:
replicate predictions:create stability-ai/stable-diffusion --prompt="A beautiful sunset" --num_outputs=2Using a JSON input file:
replicate predictions:create owner/model-name --input-file=input.jsonCombining file and inline arguments (inline arguments override file values):
replicate predictions:create owner/model-name --input-file=input.json --override_key=valueArgument Types:
- Strings:
--prompt="Hello world" - Numbers:
--width=512 - Booleans:
--enable_flag=trueor--enable_flag=false - JSON arrays/objects: Use a JSON input file
Find required arguments:
Use models:show to see what arguments a model accepts:
replicate models:show owner/model-namereplicate predictions:get <prediction-id>Watch until completion:
replicate predictions:get <prediction-id> --watchOutput as JSON:
replicate predictions:get <prediction-id> --jsonView your prediction history:
replicate predictions:listLimit results:
replicate predictions:list --limit 10-
Find a model:
replicate models:list --search "image generation" -
Check model requirements:
replicate models:show stability-ai/stable-diffusion
-
Create a prediction:
replicate predictions:create stability-ai/stable-diffusion \ --prompt="A futuristic city at sunset" \ --width=1024 \ --height=1024 \ --num_outputs=1 -
Check status:
replicate predictions:get <prediction-id> --watch
-
View history:
replicate predictions:list
.
βββ src/
β βββ commands/ # CLI commands
β β βββ models/ # Model-related commands
β β βββ predictions/ # Prediction-related commands
β βββ utils/ # Shared utilities
βββ bin/ # Executable entry point
βββ lib/ # Compiled JavaScript (generated)
βββ package.json
npm run buildAfter linking with npm link, test commands:
replicate --help
replicate models:listAuthentication Issues
- Run
replicate auth:whoamito verify your authentication status - If you see "Invalid or expired API token", run
replicate auth:loginto re-authenticate - Your token is stored at
~/.config/replicate/config
Command not found after npm link
- Make sure your shell has the npm bin directory in PATH
- Try:
export PATH="$(npm config get prefix)/bin:$PATH"
Invalid argument errors
- Use
models:showto check the model's input schema - Ensure required fields are provided
- Check argument types match the schema (string, number, boolean)
This package uses automated publishing via GitHub Actions.
-
Create npm token:
- Go to https://www.npmjs.com/settings/YOUR_USERNAME/tokens
- Create a new "Automation" token
- Copy the token
-
Add npm token to GitHub:
- Go to your repository settings β Secrets and variables β Actions
- Create a new secret named
NPM_TOKEN - Paste your npm token
On every push to main:
- Version automatically bumps based on commit messages:
major: breaking changeβ bumps major version (1.0.0 β 2.0.0)feat: new featureβ bumps minor version (1.0.0 β 1.1.0)- Any other commit β bumps patch version (1.0.0 β 1.0.1)
- Creates a git tag
To publish to npm:
- Go to GitHub β Releases β Create a new release
- Create a tag matching the version (e.g.,
v1.2.3) - Publish the release
- GitHub Actions will automatically:
- Update package.json version
- Build the project
- Publish to npm
- Commit version changes back to main
If you prefer manual control:
# Bump version
npm version patch # or minor/major
# Publish to npm
npm publish
# Push changes
git push --follow-tagsMIT