Skip to main content

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

  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


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_monitor_sdk-0.1.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_monitor_sdk-0.1.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

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

Hashes for llm_monitor_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dd12ea89e778f21f866902826be4b4120ad504855e218a93bd711f74edd2cbd5
MD5 560b2c6fddec077bb5fc2d322d7f1a3b
BLAKE2b-256 f31acea7a9613988155a20e6cefd4ba60e4a8ec1762b64d464834e6d4e42f062

See more details on using hashes here.

File details

Details for the file llm_monitor_sdk-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_monitor_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 942fdbb00bfcfc1cde64a4a26229bc4013db8c6b078f16fc9e0f48769a0afc76
MD5 2a4fd0c2702cb2398313d48045cfca60
BLAKE2b-256 a0ae5c381b98fb9879f07eab700f1207c1848c812816774c53d0af080a2fd5c0

See more details on using hashes here.

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