Lightweight LLM observability SDK
Project description
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_urlandproject_api_keyexplicitly.
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.
# 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. Usetrace()to group calls under a single workflow.
Production checklist
- Store
LLMWATCH_API_KEYin your secrets manager (do not hardcode). - Set
LLMWATCH_BACKEND_URLvia 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.
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_watch_sdk-0.1.7.tar.gz.
File metadata
- Download URL: llm_watch_sdk-0.1.7.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
503b902ce2710a37d3724a1cc307836fc66c829cba7aa39eafed75b5bfb6fe37
|
|
| MD5 |
2b70c0c2e77f2a705280b8c531e094a2
|
|
| BLAKE2b-256 |
48dda5a3033ff96390d2d029684fc15d0a3344911708909aff835efb725bf6f6
|
File details
Details for the file llm_watch_sdk-0.1.7-py3-none-any.whl.
File metadata
- Download URL: llm_watch_sdk-0.1.7-py3-none-any.whl
- Upload date:
- Size: 30.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f720a68fc05a85b1415c58e3f9740d6d6c22a254efe5d8c9a60136f1692df567
|
|
| MD5 |
620f9e2d71896f1bfb0c81c33774dee4
|
|
| BLAKE2b-256 |
bb97a348c11eea8008a4476bac96e45cd0d75e54bcbcdff3a631e2a113166675
|