Skip to main content

A lightweight LLM proxy with logging and admin dashboard

Project description

LLM Proxier

License Python FastAPI Gradio

A lightweight LLM (Large Language Model) proxy with comprehensive request logging and admin dashboard. This proxy allows you to intercept, log, and monitor all API requests to OpenAI-compatible services while maintaining full compatibility with the original API.

Features

๐Ÿš€ Key Features:

  • Transparent Proxy: Seamlessly forwards requests to OpenAI-compatible APIs without modification
  • Comprehensive Logging: Records all API requests and responses with metadata
  • Admin Dashboard: Web-based interface for viewing and analyzing request logs
  • Authentication: Secure API key authentication for both proxy and upstream services
  • Streaming Support: Full support for streaming responses
  • Database Integration: Persistent storage using SQLite with async SQLAlchemy

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Client App    โ”‚โ”€โ”€โ”€โ–ถโ”‚    LLM Proxy      โ”‚โ”€โ”€โ”€โ–ถโ”‚   OpenAI API      โ”‚
โ”‚                 โ”‚    โ”‚                   โ”‚    โ”‚                   โ”‚
โ”‚ - API Requests  โ”‚    โ”‚ - Authentication  โ”‚    โ”‚ - GPT Models      โ”‚
โ”‚ - Streaming     โ”‚    โ”‚ - Request Logging โ”‚    โ”‚ - Embeddings      โ”‚
โ”‚ - Non-Streaming โ”‚    โ”‚ - Response Relay  โ”‚    โ”‚ - Other Services  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚ - Admin Dashboard โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                       โ”‚   SQLite DB      โ”‚
                       โ”‚                  โ”‚
                       โ”‚ - Request Logs   โ”‚
                       โ”‚ - Metadata       โ”‚
                       โ”‚ - Analytics      โ”‚
                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Quick Start

Prerequisites

  • Python 3.12+
  • pip or uv package manager
  • SQLite (included with Python)

Installation

  1. Install from PyPI
pip install llm-proxier==0.1.1
  1. Or install from source
# Clone the repository
git clone https://github.com/WqyJh/llm-proxier.git
cd llm-proxier

# Install with pip
pip install -e .
  1. Configure environment variables
cp .env.example .env

Edit .env file with your configuration:

# Proxy Configuration
PROXY_API_KEY=your-proxy-api-key
UPSTREAM_BASE_URL=https://api.openai.com/v1
UPSTREAM_API_KEY=your-upstream-api-key

# Admin Dashboard
ADMIN_USERNAME=admin
ADMIN_PASSWORD=password

# Database
AUTO_MIGRATE_DB=true
  1. Run the application
# Using the CLI command
llm-proxier

# Or directly
python -m llm_proxier.main

# With custom host and port
llm-proxier --host 0.0.0.0 --port 8000

Usage

API Requests

All requests are proxied to the upstream OpenAI-compatible API with the same format:

# Chat completion
curl -X POST http://localhost:8000/v1/chat/completions \
  -H "Authorization: Bearer your-proxy-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "Hello!"}],
    "stream": true
  }'

Admin Dashboard

Access the admin dashboard at http://localhost:8000/admin:

  • Login: Use credentials from ADMIN_USERNAME and ADMIN_PASSWORD
  • View Logs: Browse all API requests with filtering and search
  • Real-time Updates: Live request monitoring

Request Logging

The proxy automatically logs:

  • Request method and path
  • Request body (JSON)
  • Response body
  • HTTP status code
  • Timestamp
  • Success/failure status

Configuration

Environment Variables

Variable Description Default
PROXY_API_KEY API key for proxy authentication Required
UPSTREAM_BASE_URL Upstream OpenAI API URL https://api.openai.com/v1
UPSTREAM_API_KEY API key for upstream service Required
ADMIN_USERNAME Admin dashboard username admin
ADMIN_PASSWORD Admin dashboard password password
AUTO_MIGRATE_DB Auto-run database migrations true

Database

The application uses SQLite for data persistence. Database files are stored in the application directory. For production use, consider:

  • Regular database backups
  • Database optimization for large log volumes
  • Migration to PostgreSQL/MySQL for scalability

Development

Project Structure

llm-proxier/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ llm_proxier/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ admin.py          # Admin dashboard interface
โ”‚       โ”œโ”€โ”€ config.py         # Configuration management
โ”‚       โ”œโ”€โ”€ database.py       # Database models and operations
โ”‚       โ”œโ”€โ”€ main.py          # Application entry point
โ”‚       โ”œโ”€โ”€ proxy.py         # Proxy routing and logic
โ”‚       โ””โ”€โ”€ assets/          # Static assets
โ”‚           โ””โ”€โ”€ icon.svg
โ”œโ”€โ”€ .env.example
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ uv.lock

Development Setup

  1. Install development dependencies
uv sync
  1. Run code formatting
ruff format
  1. Run linting
ruff check
  1. Pre-commit hooks
pre-commit install
pre-commit run --all-files

Testing

# Run tests (when available)
pytest

# Run with coverage
pytest --cov=src/llm_proxier

API Compatibility

This proxy is compatible with OpenAI API specifications:

  • โœ… Chat Completions
  • โœ… Streaming responses

Performance Considerations

  • Database Indexing: Automatic indexing on request logs for fast queries
  • Async I/O: Full async/await implementation for high concurrency
  • Streaming Support: Efficient streaming without buffering entire responses
  • Connection Pooling: HTTP connection reuse for upstream services

Security

  • API Key Validation: All requests require valid proxy API key
  • Authentication Proxying: Upstream API keys are securely passed through
  • Input Validation: JSON parsing with error handling
  • Admin Protection: Separate authentication for admin dashboard

Acknowledgments

Built with:


Star this repository if you find it useful! โญ

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_proxier-0.1.1.tar.gz (90.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_proxier-0.1.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file llm_proxier-0.1.1.tar.gz.

File metadata

  • Download URL: llm_proxier-0.1.1.tar.gz
  • Upload date:
  • Size: 90.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for llm_proxier-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1df42f8d8ffea4ebd6b312d052d86191b896ce765db40d8d9cad24b826e0d183
MD5 47877a4a88c1b77524f33f4fe5bde7c0
BLAKE2b-256 5dc9530ccb1ef138afe1beb47898d8d991a8816d28f11aa0b0f52b9ff3da9dc7

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_proxier-0.1.1.tar.gz:

Publisher: publish-to-pypi.yml on WqyJh/llm-proxier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llm_proxier-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: llm_proxier-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for llm_proxier-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6150b467efda72940db94f4e8806ff93a9853c7187aa09351a50e32fffb61f6c
MD5 659256d9436aa5df1fb9551e605a3e85
BLAKE2b-256 f4f18a100bdc07d5ba2d2a7bb36b1ddd682610c567f780ca2f7969e987b9735b

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_proxier-0.1.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on WqyJh/llm-proxier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page