Skip to content
// authentication [ 3.01 ]

Authentication

API key setup and provider configuration.


Authentication

// Setup via CLI

Run the interactive setup:

bashcopy
elith init

This creates ~/.elith/config.toml with your provider configuration.

// Manual Setup

Create or edit ~/.elith/config.toml:

[providers.claude]
api_key = "sk-ant-api03-..."
model = "claude-3-5-sonnet-20241022"
enabled = true

[providers.lmstudio]
base_url = "http://localhost:1234/v1"
model = "local-model"
enabled = false

[providers.openrouter]
api_key = "sk-or-..."
model = "anthropic/claude-3.5-sonnet"
enabled = false

// Provider-Specific Setup

Claude (Anthropic)

  1. Go to https://console.anthropic.com/
  2. Navigate to API Keys
  3. Create a new key
  4. Add to config:
[providers.claude]
api_key = "sk-ant-api03-..."
model = "claude-3-5-sonnet-20241022"
enabled = true

Available models:

  • claude-3-5-sonnet-20241022 (recommended)
  • claude-3-opus-20240229
  • claude-3-sonnet-20240229
  • claude-3-haiku-20240307

OpenRouter

  1. Go to https://openrouter.ai/keys
  2. Create an API key
  3. Add to config:
[providers.openrouter]
api_key = "sk-or-..."
model = "anthropic/claude-3.5-sonnet"
enabled = true

Available models:

  • anthropic/claude-3.5-sonnet
  • anthropic/claude-3-opus
  • openai/gpt-4-turbo
  • google/gemini-pro-1.5

LM Studio (Local)

  1. Download and install LM Studio
  2. Load a model (e.g., CodeLlama, DeepSeek Coder)
  3. Start the local server (default: http://localhost:1234)
  4. Add to config:
[providers.lmstudio]
base_url = "http://localhost:1234/v1"
model = "local-model"  # Use the model name from LM Studio
enabled = true

No API key required for local models.

// Environment Variables

You can also use environment variables instead of config file:

# Claude
export ANTHROPIC_API_KEY="sk-ant-api03-..."
export ANTHROPIC_MODEL="claude-3-5-sonnet-20241022"

# OpenRouter
export OPENROUTER_API_KEY="sk-or-..."

# Google (if using Gemini via OpenRouter)
export GOOGLE_API_KEY="AIza..."

Environment variables take precedence over config file.

// Key Rotation

To rotate your API key:

  1. Update ~/.elith/config.toml with new key
  2. Restart backend:
bashcopy
elith service restart

Or use environment variables for one-time use:

ANTHROPIC_API_KEY=new-key elith explain src/app.ts

// Verification

Test your authentication:

bashcopy
elith explain README.md

If authentication fails, you'll see:

[error] Authentication failed: Invalid API key
[error] Check your configuration in ~/.elith/config.toml

// Multiple Providers

You can configure multiple providers and switch between them:

[providers.claude]
api_key = "sk-ant-..."
model = "claude-3-5-sonnet-20241022"
enabled = true  # Currently active

[providers.openrouter]
api_key = "sk-or-..."
model = "anthropic/claude-3.5-sonnet"
enabled = false  # Disabled

[providers.lmstudio]
base_url = "http://localhost:1234/v1"
model = "local-model"
enabled = false  # Disabled

Only one provider can be enabled at a time. To switch:

  1. Set enabled = false for current provider
  2. Set enabled = true for new provider
  3. Restart backend: elith service restart

// Security Best Practices

  1. Never commit API keys to version control
  2. Use environment variables in CI/CD
  3. Rotate keys regularly (every 90 days)
  4. Use separate keys for development and production
  5. Monitor usage via provider dashboards

// Troubleshooting

"Invalid API key" error

  • Check key format (should start with sk-ant- for Claude, sk-or- for OpenRouter)
  • Verify key is active in provider dashboard
  • Check for extra spaces or newlines in config

"Provider not found" error

  • Ensure provider is enabled in config
  • Restart backend: elith service restart
  • Check config file syntax: cat ~/.elith/config.toml

"Connection refused" error (LM Studio)

  • Ensure LM Studio server is running
  • Check base_url matches LM Studio port
  • Verify model is loaded in LM Studio

// Next Steps