Overview
LLM Gateway uses environment variables for provider API keys, server configuration, and logging. Create a.env file in your project root based on .env.example.
Quick Start
.env file with your configuration:
Provider API Keys
OPENROUTER_API_KEY
API key for OpenRouter provider access.Required when: Using OpenRouter harnessObtain from: openrouter.ai
ZEN_API_KEY
API key for Zen provider access.Required when: Using Zen harness (default)Obtain from: Your Zen API provider
ANTHROPIC_API_KEY
API key for Anthropic Claude models.Required when: Using Anthropic harnessObtain from: console.anthropic.com
Not in
.env.example but supported by the Anthropic harness.OPENAI_API_KEY
API key for OpenAI models.Required when: Using OpenAI harnessObtain from: platform.openai.com
Not in
.env.example but supported by the OpenAI harness.Server Configuration
DEFAULT_MODEL
Default model identifier used when clients don’t specify a model in requests.Examples:The model must be supported by your configured provider. Validate available models via the
glm-4.7- Zen modelkimi-k2.5- Kimi model for long contextclaude-3-5-sonnet-20241022- Anthropic modelgpt-4o- OpenAI model
/models endpoint.PORT
Port number for the HTTP server to listen on.Common values:
4000- Default development port3000- Alternative development port8080- Common production port80- HTTP (requires elevated permissions)443- HTTPS (requires SSL setup)
LOG_LEVEL
Controls logging verbosity for the server.Allowed values:
Example output:
| Value | Level | Description |
|---|---|---|
D | Debug | Verbose debugging information |
I | Info | General informational messages (default) |
W | Warn | Warning messages only |
E | Error | Error messages only |
Development Configuration
These variables are used by the development environment and client applications.VITE_PORT
Port number for the Vite development server (web client).Usage:Must be different from
PORT to avoid conflicts.VITE_BACKEND_URL
URL of the LLM Gateway backend server for client connections.Examples:
http://localhost:4000- Local developmenthttp://192.168.1.100:4000- LAN developmenthttps://api.yourdomain.com- Production
Environment-Specific Configurations
- Development
- Staging
- Production
Loading Environment Variables
Bun Automatic Loading
Bun automatically loads.env files:
Explicit Environment File
Specify a different environment file:CLI Development
The CLI client requires explicit environment file loading:Security Best Practices
Use Different Keys Per Environment
Maintain separate API keys for development, staging, and production.
Validation
Validate your environment configuration:Docker Configuration
When using Docker, pass environment variables via:docker-compose.yml
Docker Run
Troubleshooting
Server fails to start with auth errors
Server fails to start with auth errors
Problem: API key not found or invalidSolutions:
- Verify
.envfile exists in project root - Check API key is uncommented and has no spaces
- Validate key with provider’s API directly
- Ensure correct provider harness is configured
Wrong model being used
Wrong model being used
Problem: Requests use unexpected modelSolutions:
- Verify
DEFAULT_MODELis set correctly - Confirm model is supported:
curl http://localhost:4000/models - Check client requests include explicit model parameter
- Review server logs for model validation errors
Port already in use
Port already in use
Problem:
Error: listen EADDRINUSE: address already in useSolutions:- Change
PORTto an unused port - Kill existing process:
lsof -ti:4000 | xargs kill - Check for other services using the port
Environment variables not loading
Environment variables not loading
Problem: Variables appear undefined at runtimeSolutions:
- Verify
.envfile is in the correct directory - Check file has no syntax errors (no quotes around values)
- Use
--env-fileflag explicitly if not in project root - Confirm Bun version supports automatic .env loading
Reference
Complete .env.example
All Available Variables
| Variable | Type | Default | Required | Description |
|---|---|---|---|---|
OPENROUTER_API_KEY | string | - | Conditional | OpenRouter API key |
ZEN_API_KEY | string | - | Conditional | Zen API key |
ANTHROPIC_API_KEY | string | - | Conditional | Anthropic API key |
OPENAI_API_KEY | string | - | Conditional | OpenAI API key |
DEFAULT_MODEL | string | - | No | Default model for requests |
PORT | number | 4000 | No | Server port |
LOG_LEVEL | string | I | No | Logging verbosity (D/I/W/E) |
VITE_PORT | number | 4001 | No | Vite dev server port |
VITE_BACKEND_URL | string | http://localhost:4000 | No | Backend URL for clients |
At least one provider API key (
OPENROUTER_API_KEY, ZEN_API_KEY, ANTHROPIC_API_KEY, or OPENAI_API_KEY) is required.Next Steps
Server Setup
Learn how to set up and run the server
Configuration
Advanced configuration options
