| --- |
| title: LiteLLM Gateway |
| emoji: π‘οΈ |
| colorFrom: blue |
| colorTo: green |
| sdk: docker |
| app_port: 8000 |
| pinned: false |
| --- |
| # π‘οΈ LiteLLM Gateway Console β Production-Ready AI Proxy |
|
|
| An enterprise-grade AI gateway with **intelligent LLM routing**, **real-time PII shielding**, and a **built-in Streamlit dashboard** β accessible from a single URL in any browser, no local setup required. |
|
|
| Built with **FastAPI**, **LiteLLM**, **DeBERTa-v3**, and **Streamlit**, deployed as a single Docker container. |
|
|
| --- |
|
|
| ## βοΈ One-Click Deploy |
|
|
| Deploy to your preferred cloud platform by clicking a button below. Set your API key secrets in the platform dashboard after deployment. |
|
|
| ### Railway (Recommended) |
| [](https://railway.app/template/new?template=https://github.com/sanvity/LiteLLM_Proxy) |
|
|
| > After deploy: Go to **Variables** β add `GROQ_API_KEY`, `CEREBRAS_API_KEY`, `TOGETHERAI_API_KEY` |
|
|
| ### Render |
| [](https://render.com/deploy?repo=https://github.com/sanvity/LiteLLM_Proxy) |
|
|
| > After deploy: Go to **Environment** β add your API keys as secret variables |
|
|
| ### Fly.io |
| ```bash |
| # Install Fly CLI, then: |
| fly launch --no-deploy |
| fly secrets set GROQ_API_KEY=gsk_... CEREBRAS_API_KEY=csk_... TOGETHERAI_API_KEY=... |
| fly deploy |
| ``` |
|
|
| --- |
|
|
| ## π Required Environment Variables |
|
|
| | Variable | Description | Required | |
| |---|---|---| |
| | `GROQ_API_KEY` | Groq API key ([console.groq.com](https://console.groq.com)) | β
| |
| | `CEREBRAS_API_KEY` | Cerebras API key ([cloud.cerebras.ai](https://cloud.cerebras.ai)) | β
| |
| | `TOGETHERAI_API_KEY` | Together AI key ([api.together.ai](https://api.together.ai)) | β
| |
| | `MISTRAL_API_KEY` | Mistral API key (optional) | β¬ | |
| | `PORT` | HTTP port (auto-set by cloud platform) | auto | |
| | `OLLAMA_API_BASE` | Local Ollama URL (local only) | β¬ | |
|
|
| See [`.env.example`](.env.example) for a full template. |
|
|
| --- |
|
|
| ## β¨ Key Features |
|
|
| | Feature | Details | |
| |---|---| |
| | π **Intelligent Routing** | `usage-based-routing` β automatically balances load across Groq, Cerebras, Together AI | |
| | π‘οΈ **PII Shield (DeBERTa-v3)** | Real-time detection of 10+ PII entity types with BLOCK / MASK / REWRITE controls per entity | |
| | π **Live Dashboard** | Streamlit UI served at `/` β no separate port, works on any cloud | |
| | β‘ **OpenAI-Compatible API** | Drop-in replacement for any OpenAI SDK client | |
| | π **Auto Fallbacks** | `primary-cluster β backup-cluster` with context-window escalation | |
| | ποΈ **Single Container** | One Docker image, one port, one URL | |
|
|
| --- |
|
|
| ## ποΈ Architecture |
|
|
| ``` |
| Browser β https://myapp.com/ (single public URL) |
| β |
| βΌ |
| βββββββββββββββββββββββ |
| β FastAPI Gateway β port $PORT (e.g. 8000) |
| β β |
| β βββββββββββββββββ β HTTP + WebSocket reverse proxy |
| β β Streamlit UI ββββΌβββ / (root) and /_stcore/* paths |
| β β (port 8501) β β |
| β βββββββββββββββββ β |
| β β |
| β βββββββββββββββββ β |
| β β LLM Router ββββΌβββ /v1/chat/completions |
| β β DeBERTa PII β β |
| β βββββββββββββββββ β |
| βββββββββββββββββββββββ |
| β |
| ββββββββββββΌβββββββββββ |
| βΌ βΌ βΌ |
| Groq Cerebras Together AI |
| ``` |
|
|
| --- |
|
|
| ## π Directory Structure |
|
|
| ```text |
| LiteLLM_Proxy/ |
| βββ Dockerfile # Multi-stage build (model pre-cache, slim runtime) |
| βββ .dockerignore # Keeps secrets out of the image |
| βββ railway.toml # Railway deployment config |
| βββ render.yaml # Render.com deployment blueprint |
| βββ fly.toml # Fly.io app configuration |
| βββ Procfile # Heroku/Railway fallback entrypoint |
| βββ .env.example # Environment variable template (safe to commit) |
| βββ config.yaml # LiteLLM routing, capacity, and fallback settings |
| βββ requirements.txt # Python production dependencies |
| βββ main.py # Unified entrypoint: spawns Streamlit + starts FastAPI |
| βββ app.py # Streamlit dashboard frontend |
| βββ test_proxy.py # Automated unit & integration test suite |
| βββ proxy/ # FastAPI package |
| βββ app.py # Routes, Streamlit reverse proxy, PII config endpoints |
| βββ router.py # Token estimation, routing, DeBERTa PII guardrail |
| βββ config.py # Pydantic config models |
| βββ guardrails/ # DeBERTa-v3 PII detection engine |
| ``` |
|
|
| --- |
|
|
| ## π₯οΈ Local Development |
|
|
| ### 1. Clone & Install |
|
|
| ```bash |
| git clone https://github.com/sanvity/LiteLLM_Proxy.git |
| cd LiteLLM_Proxy |
| |
| python3 -m venv venv |
| source venv/bin/activate |
| pip install -r requirements.txt |
| ``` |
|
|
| ### 2. Configure API Keys |
|
|
| ```bash |
| cp .env.example .env |
| # Edit .env and add your API keys |
| ``` |
|
|
| ### 3. Start the Application |
|
|
| ```bash |
| python main.py |
| ``` |
|
|
| The app will: |
| 1. Spawn the Streamlit dashboard on internal port 8501 |
| 2. Wait for Streamlit to be ready |
| 3. Start FastAPI on port 8000 |
|
|
| Then visit **http://localhost:8000** β the full UI loads in your browser. |
|
|
| --- |
|
|
| ## π³ Local Docker Build |
|
|
| ```bash |
| docker build -t litellm-gateway . |
| docker run -p 8000:8000 --env-file .env litellm-gateway |
| |
| # Visit http://localhost:8000 |
| ``` |
|
|
| --- |
|
|
| ## π§ͺ Running Tests |
|
|
| ```bash |
| python -m unittest test_proxy.py |
| ``` |
|
|
| --- |
|
|
| ## π‘ API Reference |
|
|
| | Endpoint | Method | Description | |
| |---|---|---| |
| | `/` | GET | Streamlit dashboard (proxied) | |
| | `/health` | GET | Liveness probe β returns `{"status": "healthy"}` | |
| | `/metrics` | GET | Real-time routing and token metrics | |
| | `/v1/models` | GET | List virtual and physical models | |
| | `/v1/chat/completions` | POST | OpenAI-compatible chat completion | |
| | `/ui/pii-config` | GET/POST | Read/update PII guardrail configuration | |
| | `/preference-config` | GET/POST | Read/update model preference routing | |
| | `/old-ui` | GET | Legacy HTML dashboard (debugging) | |
|
|
| ### Example Request |
|
|
| ```bash |
| curl -X POST http://localhost:8000/v1/chat/completions \ |
| -H "Content-Type: application/json" \ |
| -d '{ |
| "model": "primary-cluster", |
| "messages": [{"role": "user", "content": "Hello!"}], |
| "temperature": 0.7, |
| "max_tokens": 500 |
| }' |
| ``` |
|
|