LLM Proxy

A lightweight OpenAI-compatible API proxy that sits between your AI clients and any number of LLM backends — rewriting model names, tracking token usage and cost, and providing automatic fallback between fast ↔ smart models.

# What is LLM Proxy?

A Flask-based proxy that presents an OpenAI-compatible API endpoint while managing multiple LLM backends behind the scenes. Add models through the web UI, tag them as fast or smart, and the proxy handles auto-fallback, usage tracking, and cost calculation — no config files to hand-edit after initial setup.

🔄 How it works

Your AI client sends requests to the proxy's /v1/chat/completions endpoint. The proxy rewrites the model name, forwards to the right backend, tracks token usage, and returns the response — all transparently.

🏷 Tag-based routing

Tag one model as fast, one as smart. Request "model": "fast" to hit your cheap model automatically. If it fails, the proxy falls back to smart — and vice versa.

# Features

Everything you need to manage LLM backends from a single endpoint.

🌐 Web UI

Add, edit, and delete model backends through your browser. Manage fast/smart/local tags, view the dashboard at a glance. No config file wrangling.

Flask

🔌 OpenAI-compatible API

Drop-in replacement at /v1/chat/completions and /v1/models. Works with any OpenAI-compatible client — just point it at the proxy URL.

🔄 Auto-fallback

If a fast-tagged model fails (server error / timeout / rate limit), the proxy automatically retries on the smart model, and vice versa.

💰 Cost tracking

Per-model, per-day token counts and dollar costs. Remote models use per-million-token pricing. Local models use wattage × electricity price.

Charts

⚡ Streaming

SSE streaming works out of the box. Streamed responses are cost-tracked too — the proxy adds stream_options: {"include_usage": true} for token reporting.

💾 MooFile storage

All config and usage data lives in data/*.bson via MooFile. Persistent, portable, and easy to back up.

MooFile
LLM Proxy screenshot
LLM Proxy web dashboard — model management and usage overview

# API Usage

Once running, point any OpenAI-compatible client at the proxy.

POST /v1/chat/completions
OpenAI-compatible chat completions. Use "model": "fast", "smart", or any specific model name.
GET /v1/models
List available models configured in the proxy.
GET /
Web dashboard for managing models, viewing costs, tweaking settings.
GET /reports
Cost charts: daily/monthly spend, per-model breakdown, token volume.
# Use the fast model (auto-fallback to smart on error)
curl http://localhost:8086/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "fast",
    "messages": [{"role": "user", "content": "Tell me a joke!"}]
  }'

# Use the smart model for heavier tasks
curl http://localhost:8086/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "smart",
    "messages": [{"role": "user", "content": "Write a detailed analysis..."}]
  }'

# Use a specific model by its configured name
curl http://localhost:8086/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-flash",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

# List available models
curl http://localhost:8086/v1/models

# Quick Start

Get the proxy running in under a minute.

# 1. Install dependencies
./ubuntu-install.sh
# or manually: pip install -r requirements.txt

# 2. Configure
cp .env.example .env
# Edit .env — set PROXY_PORT, BIND_HOST, and FLASK_SECRET_KEY

# 3. Run
./start.sh

# 4. Open the web UI
open http://localhost:8086/

# 5. Add your first model through the browser
# No manual config file editing — just fill in the form!

Configuration

VariableDefaultDescription
PROXY_PORT8086Port for proxy + web UI
BIND_HOST0.0.0.0IP to bind to
PROXY_THREADS32Max concurrent requests
FLASK_SECRET_KEYFlask session cookie secret

# Model Configuration

All model management is done through the web UI — no config files to hand-edit.

📋 Model fields

FieldDescription
NameUnique identifier (used as "model" in API)
Display NameHuman-readable label
Providere.g. fireworks, openai, local
Typeremote (token pricing) or local (electricity pricing)
Tagfast, smart, or local
Base URLBackend base URL
API KeyAuth key for the backend
API Model NameModel name sent to backend
PricingPer-million-token prices
EnabledToggle on/off without deleting

🏷 Tag behavior

fast — your cheap/quick model. Falls back to smart on error.

smart — your capable/slow model. Falls back to fast on error.

local — a model on your own hardware. No fallback.

At most one model per tag. If you only have one model, tag it fast — fallback is automatically disabled.

# Usage Reports

Visit /reports for matplotlib-powered cost and usage charts.

📊 Daily token spend

Bar chart of cost per day for the last 30 days — see where your budget is going at a glance.

📈 Monthly token spend

Monthly cost bar chart for longer-term trend analysis.

💰 Cost per model

Horizontal bar chart breaking down costs by individual model.

📦 Token volume

Stacked bar chart of input vs output tokens per day.

📋 Summary tables

Today / this week / this month totals with per-model breakdown.

⚙️ Settings

Configure electricity cost ($/kWh) and max wattage for local model cost calculations.