Lightweight SDK for LLM cost & latency monitoring
Project description
LLM Monitor SDK
Lightweight SDK for monitoring LLM cost, latency, and token usage.
The LLM Monitor SDK automatically intercepts LLM API calls (OpenAI, Anthropic, etc.), collects usage telemetry, and sends it to the monitoring backend so you can analyze:
- Token usage
- Cost per feature
- Latency metrics
- Model usage distribution
- Optimization suggestions
Once telemetry is sent, metrics can be viewed on the dashboard:
https://ai-operations-optimizer.vercel.app
Installation
Install the SDK using pip:
pip install llm-monitor-sdk
Quick Start
Import the SDK and wrap your OpenAI client.
import openai
from llm_monitor import LLMMonitor, feature_tag
monitor = LLMMonitor(
api_key="YOUR_PROJECT_API_KEY",
ingest_url="https://your-backend-domain/api/v1/ingest"
)
client = monitor.wrap_openai(openai.OpenAI())
Now every LLM request will automatically be monitored.
Basic Example
import openai
from llm_monitor import LLMMonitor, feature_tag
monitor = LLMMonitor(
api_key="YOUR_PROJECT_API_KEY",
ingest_url="https://your-backend-domain/api/v1/ingest"
)
client = monitor.wrap_openai(openai.OpenAI())
with feature_tag("summarization"):
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content": "Summarize the importance of AI monitoring."}
]
)
print(response.choices[0].message.content)
The SDK will automatically capture:
- model used
- input tokens
- output tokens
- latency
- estimated cost
- feature tag
Telemetry is sent asynchronously to the monitoring backend.
View Metrics Dashboard
After running your application, view metrics at:
https://ai-operations-optimizer.vercel.app
The dashboard provides:
- Real-time LLM usage metrics
- Cost analysis
- Latency monitoring
- Feature-level hotspots
- Automated optimization suggestions
Feature Tagging
Feature tags allow you to track which part of your application generated LLM calls.
Example:
from llm_monitor import feature_tag
with feature_tag("chatbot"):
client.chat.completions.create(...)
with feature_tag("classification"):
client.chat.completions.create(...)
In the dashboard, metrics will appear grouped by feature.
How It Works
- Your application calls an LLM API.
- The SDK intercepts the request.
- Usage data (tokens, latency, cost) is collected.
- Events are batched and sent to the ingest API.
- The backend stores telemetry and analyzes usage.
- Metrics appear on the dashboard.
All telemetry shipping happens in a background thread to avoid blocking your application.
Configuration
Initialize the SDK with the following parameters:
LLMMonitor(
api_key="PROJECT_API_KEY",
ingest_url="https://your-backend-domain/api/v1/ingest"
)
| Parameter | Description |
|---|---|
| api_key | Project API key used to authenticate telemetry ingestion |
| ingest_url | Backend endpoint receiving LLM usage events |
Privacy
The SDK does not store prompt or response content by default. Only metadata is collected:
- token counts
- latency
- model name
- feature tag
- estimated cost
This ensures safe monitoring without exposing sensitive data.
Requirements
- Python 3.9+
- OpenAI Python SDK or compatible LLM client
Dependencies installed automatically:
- httpx
- wrapt
- tiktoken
Troubleshooting
If metrics do not appear:
- Verify your
api_keyis correct. - Confirm
ingest_urlpoints to the running backend. - Ensure your application executed at least one LLM request.
License
MIT License
Dashboard
View LLM usage analytics and optimization suggestions:
https://ai-operations-optimizer.vercel.app
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_monitor_sdk-0.1.1.tar.gz.
File metadata
- Download URL: llm_monitor_sdk-0.1.1.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd12ea89e778f21f866902826be4b4120ad504855e218a93bd711f74edd2cbd5
|
|
| MD5 |
560b2c6fddec077bb5fc2d322d7f1a3b
|
|
| BLAKE2b-256 |
f31acea7a9613988155a20e6cefd4ba60e4a8ec1762b64d464834e6d4e42f062
|
File details
Details for the file llm_monitor_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: llm_monitor_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
942fdbb00bfcfc1cde64a4a26229bc4013db8c6b078f16fc9e0f48769a0afc76
|
|
| MD5 |
2a4fd0c2702cb2398313d48045cfca60
|
|
| BLAKE2b-256 |
a0ae5c381b98fb9879f07eab700f1207c1848c812816774c53d0af080a2fd5c0
|