API Keys
Environment Variables
Section titled “Environment Variables”llms.py uses environment variables to securely store API keys. Set the appropriate variables for the providers you want to use:
Free Tier Providers
Section titled “Free Tier Providers”| Provider | Variable | Description | Example |
|---|---|---|---|
| openrouter_free | OPENROUTER_API_KEY | OpenRouter FREE models API key | sk-or-... |
| groq | GROQ_API_KEY | Groq API key | gsk_... |
| google_free | GOOGLE_FREE_API_KEY | Google FREE API key | AIza... |
| codestral | CODESTRAL_API_KEY | Codestral API key | ... |
| ollama | N/A | No API key required |
Premium Providers
Section titled “Premium Providers”| Provider | Variable | Description | Example |
|---|---|---|---|
| openrouter | OPENROUTER_API_KEY | OpenRouter API key | sk-or-... |
GOOGLE_API_KEY | Google API key | AIza... | |
| anthropic | ANTHROPIC_API_KEY | Anthropic API key | sk-ant-... |
| openai | OPENAI_API_KEY | OpenAI API key | sk-... |
| grok | GROK_API_KEY | Grok (X.AI) API key | xai-... |
| qwen | DASHSCOPE_API_KEY | Qwen (Alibaba) API key | sk-... |
| z.ai | ZAI_API_KEY | Z.ai API key | sk-... |
| mistral | MISTRAL_API_KEY | Mistral API key | ... |
Setting Environment Variables
Section titled “Setting Environment Variables”Linux/macOS
Section titled “Linux/macOS”Add to your ~/.bashrc, ~/.zshrc, or ~/.profile:
export OPENROUTER_API_KEY="sk-or-..."export GROQ_API_KEY="gsk_..."export GOOGLE_FREE_API_KEY="AIza..."Then reload your shell:
source ~/.bashrc # or ~/.zshrcWindows (PowerShell)
Section titled “Windows (PowerShell)”$env:OPENROUTER_API_KEY="sk-or-..."$env:GROQ_API_KEY="gsk_..."For permanent settings, use System Properties > Environment Variables.
Docker
Section titled “Docker”Pass environment variables when running the container:
docker run -p 8000:8000 \ -e OPENROUTER_API_KEY="sk-or-..." \ -e GROQ_API_KEY="gsk_..." \ -e GOOGLE_FREE_API_KEY="AIza..." \ ghcr.io/servicestack/llms:latestOr use a .env file with docker compose:
# .env fileOPENROUTER_API_KEY=sk-or-...GROQ_API_KEY=gsk_...GOOGLE_FREE_API_KEY=AIza...Direct Configuration
Section titled “Direct Configuration”Alternatively, you can set API keys directly in ~/.llms/llms.json:
{ "providers": { "groq": { "api_key": "gsk_your_actual_key_here" } }}Obtaining API Keys
Section titled “Obtaining API Keys”OpenRouter
Section titled “OpenRouter”- Visit openrouter.ai
- Sign up for an account
- Navigate to API Keys section
- Create a new API key
- Visit console.groq.com
- Sign up for an account
- Go to API Keys
- Generate a new key
Google AI Studio
Section titled “Google AI Studio”- Visit aistudio.google.com
- Sign in with Google account
- Click “Get API Key”
- Create a new API key
OpenAI
Section titled “OpenAI”- Visit platform.openai.com
- Sign up or log in
- Navigate to API Keys
- Create a new secret key
Anthropic
Section titled “Anthropic”- Visit console.anthropic.com
- Sign up for an account
- Go to API Keys
- Generate a new key
Verifying API Keys
Section titled “Verifying API Keys”After setting your API keys, verify they work:
# List available providers and modelsllms ls
# Check specific providerllms --check groqNext Steps
Section titled “Next Steps”- Configuration - Configure providers and models
- Providers - Learn about supported providers