Skip to main content

LLM Watch SDK

Lightweight SDK to send LLM usage telemetry to the LLM Watch backend.

Install

pip install llm-watch-sdk

Quickstart

LLM Watch reads config from env by default:

LLMWATCH_BACKEND_URL=http://127.0.0.1:8000
LLMWATCH_API_KEY=YOUR_PROJECT_KEY
from llm_watch import LLMWatch

watch = LLMWatch()  # reads env

You can still pass backend_url and project_api_key explicitly.

from openai import OpenAI

client = OpenAI(api_key="OPENAI_KEY")
llm = watch.instrument_openai(client, model="gpt-4o-mini")

# trace() is optional; it groups related calls
with watch.trace(actor_id="user-42"):
    resp = llm.invoke({
        "messages": [{"role": "user", "content": "hello"}],
    })

Providers

Instrument a provider client, then use the same .invoke(...) pattern across providers.

Pattern When to use Example
Instrument + invoke Recommended for new integrations llm = watch.instrument_openai(client, model="gpt-4o-mini"); llm.invoke({...})
Drop-in wrapper Keep existing call sites client = watch.wrap_openai(client, model="gpt-4o-mini")
# OpenAI (recommended unified invoke)
from openai import OpenAI

client = OpenAI(api_key="...")
llm = watch.instrument_openai(client, model="gpt-4o-mini")

with watch.trace(actor_id="user-42"):
    resp = llm.invoke({
        "messages": [{"role": "user", "content": "hello"}],
    })
# Gemini (google.genai)
from google import genai

client = genai.Client(api_key="...")
llm = watch.instrument_gemini(client, model="models/gemini-pro-latest")

with watch.trace(actor_id="user-42"):
    resp = llm.invoke({"contents": "hello"})
# Bedrock (create or wrap a client)
llm = watch.instrument_bedrock(region="eu-north-1", model_id="arn:aws:bedrock:...")

with watch.trace(actor_id="user-42"):
    resp = llm.invoke({
        "messages": [{"role": "user", "content": [{"text": "hello"}]}],
        "inferenceConfig": {"maxTokens": 64},
    })

Optional drop-in wrappers

If you prefer to keep your existing call sites, you can use drop-in wrappers:

# OpenAI drop-in (keeps .chat.completions.create)
client = OpenAI(api_key="...")
client = watch.wrap_openai(client, model="gpt-4o-mini")
client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "hello"}],
)
# Bedrock drop-in (wrap existing boto3 client)
import boto3
br = boto3.client("bedrock-runtime", region_name="eu-north-1")
br = watch.instrument_bedrock(client=br, model_id="arn:aws:bedrock:...")
br.invoke_model(
    modelId="arn:aws:bedrock:...",
    body=b'{"messages":[{"role":"user","content":[{"text":"hello"}]}]}',
    contentType="application/json",
    accept="application/json",
)

Manual logging (if you prefer)

watch.log_llm_call(
    provider="openai",
    model="gpt-4o-mini",
    input_tokens=120,
    output_tokens=320,
    total_tokens=440,
    latency_ms=780,
    actor_id="user-42",
)

watch.trace() is optional. If you don’t create a trace, LLM Watch auto-creates one per call. Use trace() to group calls under a single workflow.

Production checklist

  • Store LLMWATCH_API_KEY in your secrets manager (do not hardcode).
  • Set LLMWATCH_BACKEND_URL via environment (per‑environment endpoint).
  • If you skip trace(), each call still logs with an auto trace/span.
  • Add request timeouts and retry policies to your LLM client (SDK never blocks your app).
  • Capture actor context (actor_id, actor_type, actor_name) for accountability.
  • Use one key per project/workspace for clean separation of data.

Metadata

Release files for llm-watch-sdk 0.1.8

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-watch-sdk 0.1.8
File Size Uploaded Provenance
llm_watch_sdk-0.1.8.tar.gz 21.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-watch-sdk 0.1.8
File Interpreter ABI Platform
llm_watch_sdk-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 52.2 kB

Release files / llm_watch_sdk-0.1.8.tar.gz

Download URL llm_watch_sdk-0.1.8.tar.gz
Size 21.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6ddf9eb51a03582869537da2bd72770c1e0434152bc74ab6263d2ea128f2e43a
BLAKE2b-256 checksum
How to use checksums
c09e51999a7aafe7979d376c01885ced64317040da17468a88e6fabb86887142
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Release files / llm_watch_sdk-0.1.8-py3-none-any.whl

Download URL llm_watch_sdk-0.1.8-py3-none-any.whl
Size 30.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad314ac736de762d62f8b5a7196276e7e98e9db667936548bedc23f85174d269
BLAKE2b-256 checksum
How to use checksums
f76accd5f04ce5a1aa6fa4cf489911a5f156f3a323139b9bd59ad48def91226c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Security for llm-watch-sdk 0.1.8

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.

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