hobokenchicken 3f76a544e0
Some checks failed
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled
fix: improve analytics accuracy and cost calculation
Refined CalculateCost to correctly handle cached token discounts. Added fuzzy matching to model lookup. Robustified SQL date extraction using SUBSTR and LIKE for better SQLite compatibility.
2026-03-19 12:58:08 -04:00
2026-03-19 10:30:05 -04:00
2026-03-19 10:30:05 -04:00

LLM Proxy Gateway

A unified, high-performance LLM proxy gateway built in Go. It provides a single OpenAI-compatible API to access multiple providers (OpenAI, Gemini, DeepSeek, Grok, Ollama) with built-in token tracking, real-time cost calculation, multi-user authentication, and a management dashboard.

Features

  • Unified API: OpenAI-compatible /v1/chat/completions and /v1/models endpoints.
  • Multi-Provider Support:
    • OpenAI: GPT-4o, GPT-4o Mini, o1, o3 reasoning models.
    • Google Gemini: Gemini 2.0 Flash, Pro, and vision models (with native CoT support).
    • DeepSeek: DeepSeek Chat and Reasoner (R1) models.
    • xAI Grok: Grok-2 models.
    • Ollama: Local LLMs running on your network.
  • Observability & Tracking:
    • Asynchronous Logging: Non-blocking request logging to SQLite using background workers.
    • Token Counting: Precise estimation and tracking of prompt, completion, and reasoning tokens.
    • Database Persistence: Every request logged to SQLite for historical analysis and dashboard analytics.
    • Streaming Support: Full SSE (Server-Sent Events) support for all providers.
  • Multimodal (Vision): Image processing (Base64 and remote URLs) across compatible providers.
  • Multi-User Access Control:
    • Admin Role: Full access to all dashboard features, user management, and system configuration.
    • Viewer Role: Read-only access to usage analytics, costs, and monitoring.
    • Client API Keys: Create and manage multiple client tokens for external integrations.
  • Reliability:
    • Circuit Breaking: Automatically protects when providers are down (coming soon).
    • Rate Limiting: Per-client and global rate limits (coming soon).

Security

LLM Proxy is designed with security in mind:

  • Signed Session Tokens: Management dashboard sessions are secured using HMAC-SHA256 signed tokens.
  • Encrypted Storage: Support for encrypted provider API keys in the database.
  • Auth Middleware: Secure client authentication via database-backed API keys.

Note: You must define an LLM_PROXY__ENCRYPTION_KEY in your .env file for secure session signing and encryption.

Tech Stack

  • Runtime: Go 1.22+
  • Web Framework: Gin Gonic
  • Database: sqlx with SQLite (CGO-free via modernc.org/sqlite)
  • Frontend: Vanilla JS/CSS with Chart.js for visualizations

Getting Started

Prerequisites

  • Go (1.22+)
  • SQLite3 (optional, driver is built-in)
  • Docker (optional, for containerized deployment)

Quick Start

  1. Clone and build:

    git clone <repository-url>
    cd llm-proxy
    go build -o llm-proxy ./cmd/llm-proxy
    
  2. Configure environment:

    cp .env.example .env
    # Edit .env and add your configuration:
    # LLM_PROXY__ENCRYPTION_KEY=... (32-byte hex or base64 string)
    # OPENAI_API_KEY=sk-...
    # GEMINI_API_KEY=AIza...
    
  3. Run the proxy:

    ./llm-proxy
    

The server starts on http://0.0.0.0:8080 by default.

Deployment (Docker)

# Build the container
docker build -t llm-proxy .

# Run the container
docker run -p 8080:8080 \
  -e LLM_PROXY__ENCRYPTION_KEY=your-secure-key \
  -v ./data:/app/data \
  llm-proxy

Management Dashboard

Access the dashboard at http://localhost:8080.

  • Auth: Login, session management, and status tracking.
  • Usage: Summary stats, time-series analytics, and provider breakdown.
  • Clients: API key management and per-client usage tracking.
  • Providers: Provider configuration and status monitoring.
  • Users: Admin-only user management for dashboard access.
  • Monitoring: Live request stream via WebSocket.

Default Credentials

  • Username: admin
  • Password: admin (You will be prompted to change this or should change it manually in the dashboard)

API Usage

The proxy is a drop-in replacement for OpenAI. Configure your client:

Python

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8080/v1",
    api_key="YOUR_CLIENT_API_KEY"  # Create in dashboard
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

License

MIT

Description
No description provided
Readme 3.2 GiB
Languages
JavaScript 54.7%
Go 34.6%
CSS 8.3%
HTML 2.2%
Dockerfile 0.2%