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.0
  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.0.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.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llm_proxier-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 4de22d076d0dac0b04c3f932a708ffa9a6104cb4f4bc1691bd669c784fca5792
MD5 c8cbc189b4041cb69bca3b2d171a00d4
BLAKE2b-256 b84c4754b8af7dcd318fa14ac2eb16256a083e5ae61ca95d7b4d103b3fbd50fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_proxier-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: llm_proxier-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1dcccf94765cfb1943552ed856b8898f464157dffa446aec2217b7abba1ca260
MD5 4d87168e942810f09ed84955cefed3a8
BLAKE2b-256 a1bc16396d5660e7a554178900c167c02ea197fdd51f2cec4acdb740308ec991

See more details on using hashes here.

Provenance

The following attestation bundles were made for llm_proxier-0.1.0-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