--- 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) [![Deploy on Railway](https://railway.app/button.svg)](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 [![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](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 }' ```