Jan CLI - Complete Guide
Jan CLI - Complete Guide
Last Updated: January 2025 Status: Production Ready OK Version: 1.0.0
Complete documentation for the Jan CLI tool - installation, usage, commands, and technical details.
Table of Contents
- Overview
- Quick Start
- Installation
- Commands Reference
- Configuration Management
- Service Operations
- Development Tools
- Troubleshooting
- Shell Completion
- Technical Details
Overview
Jan CLI is the official command-line interface for Jan Server, providing unified access to:
- Configuration Management - Validate, export, and inspect configuration
- Service Operations - List services, view logs, check status
- Development Tools - Setup environment, scaffold services
- Shell Completion - Auto-completion for all major shells
Built with Cobra framework, the industry standard used by kubectl, docker, and github CLI.
Key Features
- OK Unified Interface - Single command for all Jan Server operations
- OK Professional Structure - Industry-standard Cobra framework
- OK Extensible - Easy to add new commands
- OK Well-Documented - Comprehensive help and examples
- OK Cross-Platform - Works on Windows, Linux, macOS
- OK Shell Completion - Bash, Zsh, Fish, PowerShell support
Quick Start
Install Globally (Recommended)
# From project root
make cli-installThis will:
- Build the
jan-clibinary - Install to your user's local bin directory
- Display PATH setup instructions
Installation Locations:
- Linux/macOS:
~/bin/jan-cli - Windows:
%USERPROFILE%\bin\jan-cli.exe
Add to PATH
Windows (PowerShell):
# Temporary (current session)
$env:PATH += ";$env:USERPROFILE\bin"
# Permanent (add to PowerShell profile)
notepad $PROFILE
# Add this line:
$env:PATH += ";$env:USERPROFILE\bin"Linux/macOS (Bash/Zsh):
# Add to ~/.bashrc or ~/.zshrc
export PATH="$PATH:$HOME/bin"
# Reload your shell
source ~/.bashrc # or source ~/.zshrcVerify Installation
jan-cli --version
# Output: jan-cli version 1.0.0
jan-cli --help
# Output: Full help text with all commandsFirst Commands
# List all services
jan-cli service list
# Validate configuration
jan-cli config validate
# Show help for any command
jan-cli config --helpInstallation
Method 1: Global Installation (Recommended)
Use the Makefile target to build and install jan-cli:
# From project root
make cli-installWhat it does:
- Builds the binary with
go build - Creates
~/binor%USERPROFILE%\binif needed - Copies binary to bin directory
- Sets execute permissions (Unix)
- Checks if bin is in PATH
- Shows PATH setup instructions if needed
After installation:
# Add to PATH (see instructions from install output)
# Then use from anywhere
jan-cli --version
jan-cli config validate
jan-cli service listMethod 2: Wrapper Scripts (No Installation)
Run directly from project root using wrapper scripts:
# Linux/macOS
./jan-cli.sh config validate
./jan-cli.sh service list
# Windows PowerShell
.\jan-cli.ps1 config validate
.\jan-cli.ps1 service listAdvantages:
- No installation needed
- Auto-builds if binary missing or outdated
- Always uses latest code
- Good for development
Disadvantages:
- Must be run from project root
- Requires file extension (.sh or.ps1)
Method 3: Manual Build
# Navigate to CLI directory
cd cmd/jan-cli
# Build
go build
# Run
./jan-cli --help # Linux/macOS
.\jan-cli.exe --help # Windows
# Optional: Copy to a location in your PATH
cp jan-cli ~/bin/ # Linux/macOS
copy jan-cli.exe %USERPROFILE%\bin\ # WindowsMakefile Targets
make cli-build # Build the binary
make cli-install # Build and install to local bin
make cli-clean # Remove the binarycli-build - Builds binary in tools/jan-cli/:
- Linux/macOS:
tools/jan-cli/jan-cli - Windows:
tools/jan-cli/jan-cli.exe
cli-install - Builds and installs:
- Calls
cli-build - Creates bin directory if needed
- Copies binary
- Shows PATH instructions
cli-clean - Removes binary:
- Useful for clean rebuilds
- Frees disk space
Commands Reference
Command Hierarchy
jan-cli (root)
+-- config (configuration management)
| +-- validate - Validate configuration files
| +-- export - Export configuration
| +-- show - Display configuration values
| +-- generate - Generate schemas and defaults
+-- service (service operations)
| +-- list - List all services
| +-- logs - Show service logs
| +-- status - Check service status
+-- dev (development tools)
| +-- setup - Initialize development environment
| +-- scaffold - Generate new service from template
+-- swagger (API documentation)
| +-- generate - Generate OpenAPI documentation
+-- completion (shell completions)
+-- bash
+-- zsh
+-- fish
+-- powershellGlobal Flags
Available on all commands:
-v, --verbose- Enable verbose output--config-dir <path>- Configuration directory (default: "config")-h, --help- Show help--version- Show version
Configuration Management
The config subcommand manages Jan Server configuration files.
config validate
Validate configuration files against schema:
# Validate with default environment
jan-cli config validate
# Validate specific environment
jan-cli config validate --env production
jan-cli config validate --env development
# Verbose validation
jan-cli config validate --verboseOutput:
- OK Configuration valid
- Validation errors with details
config export
Export configuration in various formats:
# Export as environment variables
jan-cli config export --format env
# Export as Docker env file
jan-cli config export --format docker-env --output.env
# Export as JSON
jan-cli config export --format json --output config.json
# Export as YAML
jan-cli config export --format yaml --output config.yaml
# Export for specific environment
jan-cli config export --env production --format envFormats:
env- Shell environment variables (KEY=value)docker-env- Docker Compose env filejson- JSON formatyaml- YAML format
Flags:
--format <format>- Output format (required)--output <file>- Output file (default: stdout)--env <environment>- Environment to export
config show
Display configuration values with path navigation:
# Show all configuration
jan-cli config show
# Show specific service
jan-cli config show llm-api
jan-cli config show media-api
# Show as JSON
jan-cli config show llm-api --format json
# Show with specific environment
jan-cli config show llm-api --env productionFlags:
<service>- Service name (optional)--format <format>- Output format (yaml, json)--env <environment>- Environment
config generate
Generate JSON schemas and defaults.yaml:
# Generate all schemas
jan-cli config generate
# Generates:
# - config/schema/config.schema.json
# - config/schema/inference.schema.json
# - config/schema/infrastructure.schema.json
# - config/schema/monitoring.schema.json
# - config/schema/services.schema.json
# - config/defaults.yamlService Operations
The service subcommand manages Jan Server services.
service list
List all available services:
jan-cli service listOutput:
Available services:
llm-api:8080 LLM API - OpenAI-compatible chat completions
media-api:8285 Media API - File upload and management
response-api:8082 Response API - Multi-step orchestration
mcp-tools:8091 MCP Tools - Model Context Protocol toolsservice logs
Show Docker Compose logs for a specific service:
# View logs for a service
jan-cli service logs llm-api
# Follow logs
jan-cli service logs llm-api --follow
# Show last N lines
jan-cli service logs llm-api --tail 50jan-cli service logs wraps docker compose logs, so it works on every platform where Docker Desktop is installed.
service status
Check container status (and optionally health endpoints):
# Check all services via Makefile health check
jan-cli service status
# Check specific service
jan-cli service status llm-apijan-cli service statuswithout arguments runsmake health-check- With a service argument it shows
docker compose ps <service>and invokes the service-specific/healthzendpoint (PowerShellInvoke-WebRequeston Windows orcurlon macOS/Linux)
Development Tools
The dev subcommand provides development utilities.
dev setup
Initialize development environment:
jan-cli dev setupWhat it does:
- Creates required directories (logs/, tmp/, uploads/)
- Creates Docker networks (jan-network, jan-dev)
- Generates.env file from templates
- Optional: Sets up Docker environment
Features:
- OK Cross-platform (Windows, Linux, macOS)
- OK Docker optional (warns if not available)
- OK Idempotent (safe to run multiple times)
dev scaffold
Generate a new service from services/template-api:
# Create new API service
jan-cli dev scaffold my-service
# Specify template/port (future templates can be added later)
jan-cli dev scaffold worker-service --template api --port 8999What it does today:
- Copies
services/template-apitoservices/<name> - Replaces placeholders (module import paths, README text, comments)
- Prints next steps (run
go mod tidy, update docker-compose, add Kong routes)
If the destination already exists the command aborts without touching files.
Swagger Documentation
The swagger subcommand generates OpenAPI documentation.
swagger generate
Generate OpenAPI/Swagger documentation for services:
# Generate for specific service
jan-cli swagger generate --service llm-api
jan-cli swagger generate --service media-api
# Generates:
# - services/llm-api/docs/swagger.yaml
# - services/llm-api/docs/swagger.jsonRequirements:
- Service must have Swagger annotations in code
swagCLI tool must be installed (go install github.com/swaggo/swag/cmd/swag@latest)
Troubleshooting
"jan-cli: command not found" (Linux/macOS)
Problem: The bin directory is not in your PATH.
Solution:
- Check if
~/binexists:
ls ~/bin/jan-cli- Add to PATH:
export PATH="$PATH:$HOME/bin"- Make permanent by adding to
~/.bashrcor~/.zshrc:
echo 'export PATH="$PATH:$HOME/bin"' >> ~/.bashrc
source ~/.bashrc"jan-cli is not recognized" (Windows)
Problem: The bin directory is not in your PATH.
Solution:
- Check if file exists:
Test-Path $env:USERPROFILE\bin\jan-cli.exe- Add to PATH (temporary):
$env:PATH += ";$env:USERPROFILE\bin"- Make permanent:
notepad $PROFILE
# Add this line:
$env:PATH += ";$env:USERPROFILE\bin"- Restart PowerShell
"Permission denied" (Linux/macOS)
Problem: The binary is not executable.
Solution:
chmod +x ~/bin/jan-cliThe make cli-install target handles this automatically, but if you installed manually, you may need to set execute permissions.
Binary Not Updated After Code Changes
Problem: Installed binary is outdated after modifying source code.
Solution:
# Rebuild and reinstall
make cli-install
# Or clean and rebuild
make cli-clean
make cli-installWrapper Scripts Don't Work
Problem: Wrapper script shows errors or doesn't build.
Solution:
- Ensure Go is installed:
go version- Ensure in project root:
pwd # Should show jan-server directory- Check script is executable (Linux/macOS):
chmod +x jan-cli.sh- Try manual build:
cd tools/jan-cli && go build
---
## Shell Completion
Jan CLI supports shell completion for bash, zsh, fish, and PowerShell.
### Generate Completion Script
```bash
# Bash
jan-cli completion bash > /etc/bash_completion.d/jan-cli
# Zsh
jan-cli completion zsh > "${fpath[1]}/_jan-cli"
# Fish
jan-cli completion fish > ~/.config/fish/completions/jan-cli.fish
# PowerShell
jan-cli completion powershell > jan-cli.ps1
# Then source it in your profileEnable Completion
Bash:
# Add to ~/.bashrc
source /etc/bash_completion.d/jan-cliZsh:
# Add to ~/.zshrc
autoload -U compinit
compinitFish:
# Completion is auto-loaded from ~/.config/fish/completions/PowerShell:
# Add to $PROFILE
. /path/to/jan-cli.ps1Technical Details
Framework: Cobra
Jan CLI uses spf13/cobra v1.8.1, the industry-standard CLI framework.
Why Cobra:
- Used by kubectl, docker, gh, helm
- Auto-generated help text
- Built-in completion generation
- Nested subcommand support
- Flag parsing and validation
- POSIX-compliant
Dependencies:
require (
github.com/spf13/cobra v1.8.1
gopkg.in/yaml.v3 v3.0.1
)Project Structure
tools/jan-cli/
+-- main.go # Root command and initialization
+-- cmd_config.go # Configuration management
+-- cmd_service.go # Service operations
+-- cmd_dev.go # Development tools
+-- cmd_setup.go # Interactive setup wizard
+-- cmd_swagger.go # Swagger generation
+-- utils.go # Utility functions
+-- go.mod # Go module dependencies
+-- README.md # CLI documentationBuild Details
Build Command:
cd tools/jan-cli
go build -o jan-cliCross-Platform Builds:
# Linux
GOOS=linux GOARCH=amd64 go build -o jan-cli-linux
# macOS
GOOS=darwin GOARCH=amd64 go build -o jan-cli-darwin
# Windows
GOOS=windows GOARCH=amd64 go build -o jan-cli.exeBinary Size: ~10MB (includes dependencies)
Wrapper Scripts
PowerShell (jan-cli.ps1):
- Auto-builds if binary missing or outdated
- Checks all
*.gofiles for changes - Supports all jan-cli commands
- Works on Windows PowerShell 5.1+
Bash (jan-cli.sh):
- Auto-builds if binary missing or outdated
- Checks all
*.gofiles for changes - Supports all jan-cli commands
- Works on Linux/macOS with Bash 3.2+
Examples
Configuration Workflow
# Generate schemas and defaults
jan-cli config generate
# Validate configuration
jan-cli config validate --env production
# Export as environment variables
jan-cli config export --format env --env production >.env.production
# Show specific service config
jan-cli config show llm-api --format jsonService Management
# List all services
jan-cli service list
# View logs
jan-cli service logs llm-api --follow
# Check health
jan-cli service statusDevelopment Setup
# Setup environment
jan-cli dev setup
# Create new service from template
jan-cli dev scaffold worker-service --template api
# Generate API documentation
jan-cli swagger generate --service llm-apiBest Practices
For Daily Use
- Install globally with
make cli-install - Add to PATH once
- Use
jan-clifrom anywhere - Run
make cli-installafter pulling updates
For Development
- Use wrapper scripts (
./jan-cli.shor.\jan-cli.ps1) - Always uses latest code
- Auto-builds if needed
- Good for testing changes
For CI/CD
- Use wrapper scripts (no installation needed)
- Or install and add to PATH
- Verify with
jan-cli --version - Run commands directly
Summary
Quick Reference:
- Build:
make cli-build - Install:
make cli-install - Clean:
make cli-clean - Use:
jan-cli <command>
Recommended Workflow:
- Run
make cli-installonce - Add to PATH as instructed
- Use
jan-clifrom anywhere - Run
make cli-installagain after updates
Key Commands:
jan-cli config validate- Validate configurationjan-cli config generate- Generate schemasjan-cli service list- List servicesjan-cli dev setup- Setup environmentjan-cli swagger generate --service <name>- Generate API docs
Related Documentation
- Testing Guide - Cross-platform testing procedures
- Configuration System - Configuration management
- Development Guide - Local development setup
- Architecture Overview - System design
Status: Production Ready OK Version: 1.0.0 Cross-Platform: Windows, Linux, macOS