A secure proxy server to call local LLMs running in Ollama, LMStudio, Llamacpp, etc. using a single endpoint. This proxy supports key management, request logging, and monitoring.
FOR DEVELOPMENT ONLY. DO NOT USE FOR PRODUCTION (NOT YET READY)
- API Key Management: Create, update, delete, and regenerate API keys
- Admin API Security: Protect management APIs with environment-configured API key
- Route Configuration: Configure multiple target URLs with path prefixes
- Secure Proxy: Forward requests to target LLM APIs with authentication
- HTTPS Support: Built-in TLS with Let's Encrypt or self-signed certificates
- Request Logging: Log all requests and responses to SQLite database
- Web UI: Beautiful admin dashboard for monitoring and management
- Swagger Documentation: Auto-generated API documentation with authentication
- Statistics: Usage statistics and analytics
- Rate Limiting: Built-in rate limiting per API key
- CORS Support: Configurable CORS policies
- Go 1.21 or higher
- SQLite 3
- Clone the repository:
git clone <repository-url>
cd go-llm-proxy- Install dependencies:
make setup- Configure security (recommended):
# Copy the example environment file
cp .env.example .env
# Generate a secure admin API key
openssl rand -base64 32
# Edit .env and set ADMIN_API_KEY with the generated key- Run the server:
make runThe proxy will start on http://localhost:8080
- Web UI: Open
http://localhost:8080in your browser - API Documentation: Visit
http://localhost:8080/swagger/index.html- Click the "Authorize" button and enter your
ADMIN_API_KEYto test endpoints
- Click the "Authorize" button and enter your
- Health Check:
GET http://localhost:8080/health
Note: If you set
ADMIN_API_KEY, all API endpoints require authentication.
For local development with HTTPS:
# Use the helper script
./scripts/run-https-local.sh
# Or manually
export TLS_ENABLED=true
export TLS_HTTPS_PORT=8443
make devThen open https://localhost:8443 (accept the security warning for self-signed certificate)
All management API endpoints (/api/*) can be protected with an admin API key:
# Generate a secure key
openssl rand -base64 32
# Set it as an environment variable
export ADMIN_API_KEY="your-generated-key"When ADMIN_API_KEY is set, all API requests must include the key:
# Using X-API-Key header
curl -H "X-API-Key: your-key" http://localhost:8080/api/keys
# Using Authorization header
curl -H "Authorization: Bearer your-key" http://localhost:8080/api/keysSwagger UI Authentication:
- Open
http://localhost:8080/swagger/index.html - Click the Authorize button (π)
- Enter your admin API key
- Test endpoints
Protected Endpoints:
- All
/api/keys/*- API key management - All
/api/logs/*- Request logs - All
/api/stats- Statistics - All
/api/route-configs/*- Route configuration - All
/api/headers/*- Header management
Public Endpoints:
/health- Health check/swagger/*- API documentation/and/ui- Web interface
β οΈ Important: For production, always set a strongADMIN_API_KEY. If not set, APIs are accessible without authentication (development mode only).
The proxy can be configured using environment variables:
SERVER_HOST: Server host (default: "0.0.0.0")SERVER_PORT: Server port (default: 8080)
DB_PATH: Path to SQLite database file (default: "./proxy.db")
LOG_LEVEL: Log level (default: "info")LOG_ENABLE_REQUEST_LOG: Enable request logging (default: true)LOG_RETENTION_DAYS: Log retention period in days (default: 30)
ADMIN_API_KEY: Admin API key for management endpoints (no default, recommended for production)CORS_ENABLED: Enable CORS (default: true)CORS_ALLOWED_ORIGINS: Allowed CORS origins (default: "*")
TLS_ENABLED: Enable HTTPS (default: false)TLS_DOMAIN: Domain for Let's Encrypt (empty = use self-signed certs)TLS_CERT_FILE: Path to certificate file for self-signed (default: "./cert.pem")TLS_KEY_FILE: Path to key file for self-signed (default: "./key.pem")TLS_CACHE_DIR: Certificate cache directory (default: "./cert-cache")TLS_HTTP_PORT: HTTP port for ACME challenge (default: 80)TLS_HTTPS_PORT: HTTPS port (default: 443)RATE_LIMITING_ENABLED: Enable rate limiting (default: true)
Use either of these methods to authenticate requests:
-
Authorization Header:
Authorization: Bearer your-api-key -
X-API-Key Header:
X-API-Key: your-api-key
After configuring routes in the Web UI, use paths like:
curl -X POST http://localhost:8080/ollama/api/generate \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{"model": "llama2", "prompt": "Hello!"}'curl -X POST http://localhost:8080/openai/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-4", "messages": [{"role": "user", "content": "Hello!"}]}'POST /api/keys- Create new API keyGET /api/keys- List all API keysGET /api/keys/{id}- Get specific API keyPUT /api/keys/{id}- Update API keyDELETE /api/keys/{id}- Delete API keyPOST /api/keys/{id}/regenerate- Regenerate API key
GET /api/logs- Get request logs with filteringGET /api/logs/{id}- Get specific request logDELETE /api/logs/cleanup- Clean old logs
GET /api/stats- Get usage statistics
GET /api/route-configs- List all route configurationsPOST /api/route-configs- Create new route configurationGET /api/route-configs/{id}- Get specific route configurationPUT /api/route-configs/{id}- Update route configurationDELETE /api/route-configs/{id}- Delete route configuration
go-llm-proxy/
βββ cmd/
β βββ server/ # Main application entry point
βββ internal/
β βββ config/ # Configuration management
β βββ database/ # Database setup and connection
β βββ handlers/ # HTTP handlers
β βββ middleware/ # HTTP middleware
β βββ models/ # Data models
β βββ services/ # Business logic services
βββ web/
β βββ static/ # Static files (CSS, JS)
β βββ templates/ # HTML templates
βββ docs/ # Swagger documentation
βββ go.mod
βββ go.sum
βββ Makefile
βββ README.md
# Run in development mode
make dev
# Run tests
make test
# Generate Swagger documentation
make generate-swagger
# Build for production
make build-prod
# Clean build artifacts
make clean- Install swag:
go install github.com/swaggo/swag/cmd/swag@latest- Generate documentation:
make generate-swaggerThe application uses SQLite with the following main tables:
- api_keys: Stores API key information
- request_logs: Stores all HTTP request/response logs
- route_configs: Stores route configuration for path-based routing
- Build the Docker image:
docker build -t go-llm-proxy .- Run the container:
docker run -p 8080:8080 -v $(pwd)/data:/app/data go-llm-proxy- Build the production binary:
make build-prod- Set environment variables:
export SERVER_HOST=0.0.0.0
export SERVER_PORT=8080
export DB_PATH=/data/proxy.db-
Configure routes through the Web UI at
http://localhost:8080 -
Run the binary:
./bin/proxy- API keys are generated using cryptographically secure random bytes
- All requests are logged for audit purposes
- CORS is configurable
- Rate limiting can be enabled per API key
- Database should be properly secured in production
The proxy provides comprehensive monitoring through:
- Web Dashboard: Real-time statistics and logs
- API Endpoints: Programmatically access statistics
- Request Logging: Detailed request/response logs
- Health Checks: Service health monitoring
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the Apache License 2.0.