Show HN: A minimalist proxy for your local LLM cluster (~1100 lines)
smol-llm-proxy is a lightweight, self-hosted API proxy designed to route requests across multiple llama-server instances with per-user token accounting and rate limiting. It supports in-memory caching (30s TTL), async SQLite-based usage logging, sliding window RPM/TPM rate limiting, and connection-pooled backend forwarding—all within ~53 MB RAM and under 1100 lines of code. The proxy enables multi-model routing via aliases, admin-managed user keys, and external TLS termination, making it ideal f
Analysis
TL;DR
- smol-llm-proxy is a lightweight, self-hosted API proxy designed to route requests across multiple llama-server instances with per-user token accounting and rate limiting.
- It supports in-memory caching (30s TTL), async SQLite-based usage logging, sliding window RPM/TPM rate limiting, and connection-pooled backend forwarding—all within ~53 MB RAM and under 1100 lines of code.
- The proxy enables multi-model routing via aliases, admin-managed user keys, and external TLS termination, making it ideal for small teams sharing local LLM resources without heavy infrastructure dependencies.
Why It Matters
This project addresses a critical gap in the open-source LLM deployment ecosystem: providing a minimal, efficient, and self-contained gateway for managing shared access to locally hosted llama.cpp servers. For researchers and practitioners running multiple models on limited hardware, smol-llm-proxy offers a low-overhead solution that balances functionality (token tracking, rate limiting, routing) with extreme resource efficiency—making it suitable for edge cases where full-scale gateways like LiteLLM are overkill or impractical.
Technical Details
- Architecture: Built as a FastAPI/Uvicorn service with async I/O, using SQLite as its sole persistent store (no Redis/Postgres required). All state (users, routes, rate limits) is loaded into memory at startup with periodic async flushes to disk every second.
- Routing & Caching: Routes requests based on model name or alias using an in-memory cache refreshed every 30 seconds. Supports model-to-GGUF file mapping via config.yaml or Admin API.
- Rate Limiting: Implements sliding window counters for RPM (requests per minute) and TPM (tokens per minute) per API key, enforced via in-memory reservations reconciled against SQLite after each request. Returns HTTP 429 + Retry-Header on quota exhaustion.
- Usage Tracking: Logs prompt/completion tokens and timing data asynchronously in batches (max 50 items or 1-second interval), retaining records for 90 days before daily purging.
- Deployment Options: Available via Docker Compose, standalone binary, or Python package (
pip install). Listens on0.0.0.0:8000by default; TLS handled externally (e.g., nginx, Cloudflare).
Industry Insight
As organizations increasingly adopt self-hosted LLMs for cost control and privacy, there’s growing demand for lightweight, modular components that can orchestrate inference workloads without introducing operational bloat. smol-llm-proxy exemplifies this trend—a focused tool that solves one problem exceptionally well compared to monolithic alternatives. Its design suggests a future where specialized, composable proxies become standard building blocks in local AI infrastructures, enabling fine-grained access control and observability even in resource-constrained environments. Teams managing heterogeneous model deployments should consider such tools before reaching for enterprise-grade gateways unless they require broader cloud-provider integration or complex billing systems.
Disclaimer: The above content is generated by AI and is for reference only.