🚀 LLM Model Gateway
A lightweight, OpenAI-compatible API gateway for simonw's llm cli. This gateway provides a unified interface for model interactions with robust logging and metrics.
✨ Features
- 🔄 OpenAI API Compatibility: Seamless integration with existing tools
- 🌊 Streaming Responses: Real-time, chunked responses
- 📊 Comprehensive Metrics: Track model performance and usage
- 🎯 Model Agnostic: Support for all LLM models
- 📝 Persistent Logging: SQLite-based metrics tracking and prompt response logging.
🚀 Installation
pip install llm
llm install llm-model-gateway
🔧 Quick Start
Starting the Server
# Serve all available models
llm serve
# Serve specific model
llm serve -m gpt-4
# Custom host and port
llm serve -h 0.0.0.0 -p 8080 --reload
1. List Models
curl http://localhost:8000/v1/models
2. Chat Completions
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-pro",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": false
}'
Example response:
{
"id": "chatcmpl-8c96c0cf-f166-4cdf-8132-d6ddefaed27c",
"object": "chat.completion",
"created": 1735505968,
"model": "gemini-pro",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "Hi there! How can I help you today?"
},
"finish_reason": "stop"
}]
}
API Usage
The gateway provides two main endpoints:
1. Chat Completions
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="dummy" # API key not checked
)
# Non-streaming request
response = client.chat.completions.create(
messages=[{"role": "user", "content": "Hello!"}],
model="gpt-4"
)
print(response.choices[0].message.content)
# Streaming request
for chunk in client.chat.completions.create(
messages=[{"role": "user", "content": "Hello!"}],
model="gpt-4",
stream=True
):
print(chunk.choices[0].delta.content or "", end="")
⚙️ Configuration
Environment Variables
LLM_USER_PATH: Custom directory for logs and data- Default: System-specific app directory
- Logs Generated:
llm_model_gateway.log: Event logginglogs.db: SQLite metrics database
📊 Metrics
Every request is logged with:
- 🆔 Unique request ID
- 🕒 Timestamp
- 🤖 Model used
- ⏱️ Processing duration
- 🔢 Token count
- ✅ Success/failure status
- ❌ Error details (if any)
🛠️ Development
# Clone repository
git clone https://github.com/irthomasthomas/llm-model-gateway
cd llm-model-gateway
# Set up environment
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
🚨 Troubleshooting
Common issues and solutions:
- Connection refused: Check host/port settings
- Model not found: Verify model is registered with LLM
- Streaming issues: Confirm client streaming compatibility
🤝 Contributing
Contributions welcome! Please feel free to submit:
- Bug reports
- Feature requests
- Pull requests
- Documentation improvements
⚖️ License
Apache License 2.0 - See LICENSE for details.
Metadata
Release files for llm-model-gateway 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llm_model_gateway-0.1.0.tar.gz | 5.4 kB | Without provenance | Details for llm_model_gateway-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llm_model_gateway-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for llm_model_gateway-0.1.0-py3-none-any.whl |
Total release size: 11.2 kB
Release files / llm_model_gateway-0.1.0.tar.gz
| Download URL | llm_model_gateway-0.1.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
030cd83fd5936fb134c0ec6b7c6d082ada8b99fe5e730c132cddce727a47ab21
|
|
BLAKE2b-256 checksum How to use checksums |
26e471611cffd6008ff1a3ffd0e5b5d9df9851883cb7e4501b3eb5afe5723d19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Release files / llm_model_gateway-0.1.0-py3-none-any.whl
| Download URL | llm_model_gateway-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3fe698fa9642ce0ddbfd14dcd04ac6b151fd4f5b16b474ac09046da48d10b4ee
|
|
BLAKE2b-256 checksum How to use checksums |
641774f76b91db41ca7222effab374e9ec89764bd8459f6fc0ca3073bf6b691a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.13.1
|
Security for llm-model-gateway 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.