Skip to content

API Keys

llms.py uses environment variables to securely store API keys. Set the appropriate variables for the providers you want to use:

ProviderVariableDescriptionExample
openrouter_freeOPENROUTER_API_KEYOpenRouter FREE models API keysk-or-...
groqGROQ_API_KEYGroq API keygsk_...
google_freeGOOGLE_FREE_API_KEYGoogle FREE API keyAIza...
codestralCODESTRAL_API_KEYCodestral API key...
ollamaN/ANo API key required
ProviderVariableDescriptionExample
openrouterOPENROUTER_API_KEYOpenRouter API keysk-or-...
googleGOOGLE_API_KEYGoogle API keyAIza...
anthropicANTHROPIC_API_KEYAnthropic API keysk-ant-...
openaiOPENAI_API_KEYOpenAI API keysk-...
grokGROK_API_KEYGrok (X.AI) API keyxai-...
qwenDASHSCOPE_API_KEYQwen (Alibaba) API keysk-...
z.aiZAI_API_KEYZ.ai API keysk-...
mistralMISTRAL_API_KEYMistral API key...

Add to your ~/.bashrc, ~/.zshrc, or ~/.profile:

Terminal window
export OPENROUTER_API_KEY="sk-or-..."
export GROQ_API_KEY="gsk_..."
export GOOGLE_FREE_API_KEY="AIza..."

Then reload your shell:

Terminal window
source ~/.bashrc # or ~/.zshrc
Terminal window
$env:OPENROUTER_API_KEY="sk-or-..."
$env:GROQ_API_KEY="gsk_..."

For permanent settings, use System Properties > Environment Variables.

Pass environment variables when running the container:

Terminal window
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:latest

Or use a .env file with docker compose:

Terminal window
# .env file
OPENROUTER_API_KEY=sk-or-...
GROQ_API_KEY=gsk_...
GOOGLE_FREE_API_KEY=AIza...

Alternatively, you can set API keys directly in ~/.llms/llms.json:

{
"providers": {
"groq": {
"api_key": "gsk_your_actual_key_here"
}
}
}
  1. Visit openrouter.ai
  2. Sign up for an account
  3. Navigate to API Keys section
  4. Create a new API key
  1. Visit console.groq.com
  2. Sign up for an account
  3. Go to API Keys
  4. Generate a new key
  1. Visit aistudio.google.com
  2. Sign in with Google account
  3. Click “Get API Key”
  4. Create a new API key
  1. Visit platform.openai.com
  2. Sign up or log in
  3. Navigate to API Keys
  4. Create a new secret key
  1. Visit console.anthropic.com
  2. Sign up for an account
  3. Go to API Keys
  4. Generate a new key

After setting your API keys, verify they work:

Terminal window
# List available providers and models
llms ls
# Check specific provider
llms --check groq