Skip to main content

Lightweight SDK to capture, buffer, and report LLM calls (Only OpenAI for Now) for AI audit and monitoring.

Project description

ObservAI

PyPI License Python Versions

Lightweight SDK for capturing and buffering LLM calls (OpenAI for now) for audit, compliance, and analytics.

Why ObservAI?

LLMs like ChatGPT are powerful but opaque. ObservAI adds transparency and observability to your AI systems by:

  • Capturing every prompt/response made to OpenAI
  • Logging metadata such as latency, timestamp, route, and user
  • Supporting crash-safe local buffering with SQLite
  • Sending logs to a remote collector or local file
  • Providing optional background flushing with low overhead

Ideal for:

  • Auditing LLM usage
  • Debugging hallucinations or failure cases
  • Proving compliance (e.g., GDPR, HIPAA)
  • Generating analytics on prompt effectiveness

Features

  • Capture prompts/responses from OpenAI automatically
  • SQLite fallback for crash resilience
  • Easy integration with openai SDK
  • Local log file or remote collector
  • Optional background flushing

Installation

pip install observai

Quick Start

import observai as oai

# initialize with defaults (no background flusher)
oai.init(
    user_id="alice@example.com",
    log_path="guardianai_events.log",
    endpoint="http://localhost:9000/events/batch",
    headers={"X-Observai-Key": "dev-secret-key"},
    flush_interval=2.0,
    background=True,  # enables automatic flush
)

# optionally tag with a user id if not set above
oai.set_user("alice@example.com")

# ... then anywhere in your code, whenever you call OpenAI:
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY")
resp = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role":"user","content":"Hello"}]
)

# at process exit we auto‐flush; you can also manually:
oai.flush(final=True)

Configuration

You can override defaults in init():

Parameter Default Description
log_path "guardianai_events.log" Local fallback file for JSON-lines dumps
truncate 500 Max chars for prompt/response (None = no truncation)
flush_interval 2.0 Seconds between auto flushes
db_path "guardianai_buffer.sqlite" SQLite path for crash-safe buffering
endpoint https://collector.example.com/events/batch HTTP endpoint for batch POST’ing events
headers {} HTTP headers to include on each POST
background False Whether to spawn the background thread

Adapters

By default, ObservAI auto-detects and patches all supported SDKs (currently: OpenAI).

An adapter patches a third-party SDK (like OpenAI) to automatically intercept API calls.

To explicitly specify only the OpenAI adapter:

from observai.adapters.openai import OpenAIChatAdapter

observai.init(adapters=[OpenAIChatAdapter()])

✅ Compatible with openai>=1.0.0

Packaging & Tests

What gets captured?

For each LLM call:

  • API route (e.g. chat.completions.create)
  • Model name
  • Input prompt (truncated if configured)
  • Output response (truncated if configured)
  • Latency (ms)
  • Timestamp
  • User ID (if configured)
  • SHA256 hash of prompt + response

Flush Modes

  • flush(final=True) sends events to the configured collector endpoint.
  • flush(final=False) writes events to a local JSON-lines fallback file.
  • Auto-flush mode (enabled via background=True) periodically calls flush() in a background thread.
  • All buffered events are flushed on process exit via atexit.

Roadmap

  • Anthropic adapters ??

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

observai-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

observai-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file observai-0.1.0.tar.gz.

File metadata

  • Download URL: observai-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.7 Linux/6.11.0-24-generic

File hashes

Hashes for observai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 41584007da8434240d8d37134899a146332c7126d1d1e66db633e95e9d7c5b8b
MD5 131251e025e336db59f2d7db628b0ae8
BLAKE2b-256 69b1da5a3865accf9017a10921e73512c9082d8e79f8e02a9aaabd5b27c62b0a

See more details on using hashes here.

File details

Details for the file observai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: observai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.7 Linux/6.11.0-24-generic

File hashes

Hashes for observai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e055fc1e178193737b248c7867c5418326f415215046e3bef11c0d447ec27b1d
MD5 4976538bbd28ee6ed5e44ce6b191767a
BLAKE2b-256 8f04c68f7046608ddb8d42f5df6e091f0d91a8bf9b6ff63f5b8ec4bac449c00b

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