Skip to main content

A lightweight LLM proxy with logging and admin dashboard

Project description

LLM Proxier

License Python FastAPI

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.4
  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.3.0.tar.gz (82.0 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.3.0-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llm_proxier-0.3.0.tar.gz
  • Upload date:
  • Size: 82.0 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.3.0.tar.gz
Algorithm Hash digest
SHA256 7eba20aded1e373a75f5c31886fe2f5c2d7c716b372086241bbb08562722f105
MD5 0ee8f9969ca0a949989288780ff6fe4b
BLAKE2b-256 973311a8257490bec2c3a0d095de24cb3e768a92e79c9b8e5b299afcf4bc39f0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: llm_proxier-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 32.2 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0947522926008d533bdd4d208ece593c22fdcef919c0d4d41f4835c69476efb7
MD5 c7d6fd177eff7562b6f56edbbecc3d96
BLAKE2b-256 7e3027e48c836f46c278909df90a5de1b0ba7914fe78640453e7c78bc852772b

See more details on using hashes here.

Provenance

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