LLM Gateway can be self-hosted on your own infrastructure, giving you complete control over your data, configuration, and deployment environment. This guide covers deployment options and setup instructions.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/theopenco/llmgateway/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before deploying LLM Gateway, ensure you have:- Docker (version 20.10 or later) and Docker Compose
- PostgreSQL (version 14 or later)
- Redis (version 6 or later)
- Node.js (version 20 or later) - for building from source
- pnpm (version 8 or later) - for package management
For production deployments, we recommend at least 2 CPU cores and 4GB RAM for the gateway service, plus resources for PostgreSQL and Redis.
Quick start with Docker Compose
The fastest way to self-host LLM Gateway is using Docker Compose, which sets up all required services automatically.Configure environment variables
Copy the example environment file and configure your settings:Edit
.env and set at least these required variables:View all available environment variables
View all available environment variables
See the environment variables reference for a complete list of configuration options, including provider API keys, feature flags, and performance tuning settings.
Start services with Docker Compose
Start all services (PostgreSQL, Redis, Gateway, API, UI):This will start:
- PostgreSQL on
localhost:5432 - Redis on
localhost:6379 - Gateway API on
localhost:4001 - Management API on
localhost:4002 - UI Dashboard on
localhost:3002
Initialize the database
Run database migrations and seed initial data:This creates the necessary database tables and adds initial configuration.
Docker Compose configuration
The includeddocker-compose.yml defines the following services:
docker-compose.yml
For production deployments, see the Docker deployment guide for advanced configuration, including SSL, health checks, and resource limits.
Building from source
To build and run LLM Gateway from source:Set up the database
Ensure PostgreSQL and Redis are running, then initialize the database:This command:
- Pushes the database schema to PostgreSQL
- Seeds initial data
- Validates the configuration
Production deployment
For production environments, consider these deployment options:Docker deployment
Deploy with Docker using health checks, resource limits, and SSL configuration
Kubernetes deployment
Deploy to Kubernetes with Helm charts, auto-scaling, and high availability
Configuration
Database
LLM Gateway uses PostgreSQL for persistent storage. Configure the connection string:Redis
Redis is used for response caching and session storage:Provider API keys
Add API keys for the LLM providers you want to use:Authentication
Configure Better Auth for user authentication:Health checks
Monitor the health of your deployment using these endpoints:Monitoring
Prometheus metrics
LLM Gateway exposes Prometheus metrics at/metrics:
- Request counts and durations
- Token usage by model and provider
- Cache hit/miss rates
- Error rates
- Database connection pool stats
OpenTelemetry
Enable distributed tracing with OpenTelemetry:Backup and restore
Database backup
Back up the PostgreSQL database regularly:Redis backup
Redis persistence is optional but recommended for production. Enable AOF or RDB snapshots in your Redis configuration.Troubleshooting
Database connection errors
If you see database connection errors:- Verify PostgreSQL is running:
docker compose ps postgres - Check the connection string in
.env - Ensure the database exists:
docker compose exec postgres psql -U postgres -l - Check database logs:
docker compose logs postgres
Redis connection errors
If Redis is unavailable:- Verify Redis is running:
docker compose ps redis - Check the connection string in
.env - Test connectivity:
docker compose exec redis redis-cli ping
Provider API errors
If LLM requests fail:- Verify provider API keys are set correctly in
.env - Check provider key status in the UI dashboard
- Review request logs:
docker compose logs gateway - Test directly with the provider’s API to rule out key issues
Build errors
If build fails:- Ensure Node.js version is 20 or later:
node --version - Clear build cache:
pnpm clean - Reinstall dependencies:
rm -rf node_modules && pnpm install - Check for TypeScript errors:
pnpm build:core
Next steps
Environment variables
Complete reference for all configuration options
Docker deployment
Production-ready Docker configuration
Kubernetes deployment
Deploy to Kubernetes with Helm charts
Security best practices
Secure your deployment for production use