Skip to main content

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

  1. Your application calls an LLM API.
  2. The SDK intercepts the request.
  3. Usage data (tokens, latency, cost) is collected.
  4. Events are batched and sent to the ingest API.
  5. The backend stores telemetry and analyzes usage.
  6. 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:

  1. Verify your api_key is correct.
  2. Confirm ingest_url points to the running backend.
  3. 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


Metadata

Release files for llm-monitor-sdk 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-monitor-sdk 0.1.1
File Size Uploaded Provenance
llm_monitor_sdk-0.1.1.tar.gz 9.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-monitor-sdk 0.1.1
File Interpreter ABI Platform
llm_monitor_sdk-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / llm_monitor_sdk-0.1.1.tar.gz

Download URL llm_monitor_sdk-0.1.1.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
dd12ea89e778f21f866902826be4b4120ad504855e218a93bd711f74edd2cbd5
BLAKE2b-256 checksum
How to use checksums
f31acea7a9613988155a20e6cefd4ba60e4a8ec1762b64d464834e6d4e42f062
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / llm_monitor_sdk-0.1.1-py3-none-any.whl

Download URL llm_monitor_sdk-0.1.1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
942fdbb00bfcfc1cde64a4a26229bc4013db8c6b078f16fc9e0f48769a0afc76
BLAKE2b-256 checksum
How to use checksums
a0ae5c381b98fb9879f07eab700f1207c1848c812816774c53d0af080a2fd5c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for llm-monitor-sdk 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page