A lightweight LLM proxy with logging and admin dashboard
Project description
LLM Proxier
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
- Install from PyPI
pip install llm-proxier==0.1.4
- 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 .
- 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
- 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_USERNAMEandADMIN_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
- Install development dependencies
uv sync
- Run code formatting
ruff format
- Run linting
ruff check
- 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:
- FastAPI - High-performance web framework
- SQLAlchemy - Python SQL toolkit
- Uvicorn - Lightning-fast ASGI server
Star this repository if you find it useful! โญ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_proxier-0.2.0.tar.gz.
File metadata
- Download URL: llm_proxier-0.2.0.tar.gz
- Upload date:
- Size: 68.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14a5cc15966ccbe4eb946100f8e4a8b20bac1ab85a049bcd8b14e8faad1b2317
|
|
| MD5 |
f14a2635daf34c47ba44f20c6c20f433
|
|
| BLAKE2b-256 |
591969b8d6e6e752edb71a3d951be51173336ff6b8a05758d864042594696299
|
Provenance
The following attestation bundles were made for llm_proxier-0.2.0.tar.gz:
Publisher:
publish-to-pypi.yml on WqyJh/llm-proxier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_proxier-0.2.0.tar.gz -
Subject digest:
14a5cc15966ccbe4eb946100f8e4a8b20bac1ab85a049bcd8b14e8faad1b2317 - Sigstore transparency entry: 780712285
- Sigstore integration time:
-
Permalink:
WqyJh/llm-proxier@00c58ee49ed4f6fadd6cfb45be5ac1b705bc2dcf -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/WqyJh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@00c58ee49ed4f6fadd6cfb45be5ac1b705bc2dcf -
Trigger Event:
push
-
Statement type:
File details
Details for the file llm_proxier-0.2.0-py3-none-any.whl.
File metadata
- Download URL: llm_proxier-0.2.0-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c5ed17fa05458f5e4cd153acd2114e85829282403ad246d7d945d1b625704a4
|
|
| MD5 |
48e2139ea41fb3b86b5f793ffe663f38
|
|
| BLAKE2b-256 |
21b1ad87f613c425312c73107e430a84d1accbc5209a66d1e9fd914a8ce2a246
|
Provenance
The following attestation bundles were made for llm_proxier-0.2.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on WqyJh/llm-proxier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_proxier-0.2.0-py3-none-any.whl -
Subject digest:
9c5ed17fa05458f5e4cd153acd2114e85829282403ad246d7d945d1b625704a4 - Sigstore transparency entry: 780712287
- Sigstore integration time:
-
Permalink:
WqyJh/llm-proxier@00c58ee49ed4f6fadd6cfb45be5ac1b705bc2dcf -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/WqyJh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@00c58ee49ed4f6fadd6cfb45be5ac1b705bc2dcf -
Trigger Event:
push
-
Statement type: