// Package cli implements the ollama-proxy command-line interface: account // management subcommands and the `serve` subcommand that starts the proxy. package cli import ( "fmt" "os" ) // Run dispatches to a subcommand based on args[1]. It returns the process exit // code, or an error that the caller should print before exiting 1. func Run(args []string) int { if len(args) < 2 { printRootUsage() return 1 } switch args[1] { case "serve": return RunServe(args[2:]) case "accounts": return RunAccounts(args[2:]) case "version": fmt.Println("ollama-proxy", Version) return 0 case "-h", "--help", "help": printRootUsage() return 0 default: fmt.Fprintf(os.Stderr, "unknown subcommand: %s\n\n", args[1]) printRootUsage() return 2 } } // Version is overwritten at build time via -ldflags "-X .../cli.Version=...". var Version = "dev" func printRootUsage() { fmt.Print(`ollama-proxy — multi-account Ollama Cloud reverse proxy Usage: ollama-proxy serve [flags] Start the proxy server ollama-proxy accounts Manage Ollama Cloud API keys ollama-proxy version Print version Accounts subcommands: accounts add [API_KEY] [--name ] Add an account (prompts for key if not given) accounts list List configured accounts accounts remove Remove an account accounts set-base-url Set the default upstream URL Environment variables (serve): OLLAMA_PROXY_ADDR listen address (default 127.0.0.1:11435) OLLAMA_PROXY_BASE_URL upstream root (default https://ollama.com) OLLAMA_PROXY_COOLDOWN 429 cooldown window (default 60s) OLLAMA_PROXY_RETRIES max failover attempts (default 3) OLLAMA_PROXY_LOG_LEVEL debug|info|warn|error (default info) `) }