Skip to main content

Auto-capture OpenAI and Anthropic LLM calls for warehousing and observability

Project description

LLM Warehouse

🏠 Auto-capture OpenAI and Anthropic LLM calls for warehousing

A lightweight Python library that automatically logs all your OpenAI and Anthropic API calls to various storage backends, including your own Flask app, Supabase, or local files.

🚀 Quick Start

Installation

pip install llm-warehouse

Or for the latest development version:

pip install git+https://github.com/sinanozdemir/llm-warehouse.git

Basic Usage

import llm_warehouse

# Option 1: Use with your own warehouse
llm_warehouse.patch(
    warehouse_url="https://your-warehouse.com",
    api_key="your-warehouse-api-key"
)

# Option 2: Use with Supabase
llm_warehouse.patch(
    supabase_url="https://your-project.supabase.co",
    supabase_key="your-supabase-anon-key"
)

# Option 3: Save to local file
llm_warehouse.patch(log_file="llm_calls.jsonl")

# Now use OpenAI/Anthropic normally - all calls are automatically logged!
import openai
client = openai.Client()
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello!"}]
)

🎯 Automatic Setup (Recommended)

For automatic patching on import, set environment variables:

export LLM_WAREHOUSE_API_KEY="your-warehouse-api-key"
export LLM_WAREHOUSE_URL="https://your-warehouse.com"

Then just import any LLM library AFTER importing this package - logging happens automatically:

import llm_warehouse  # BEFORE openai or anthropic

import openai  # Automatically patched!
# or
import anthropic  # Automatically patched!

📊 What Gets Logged

  • Request data: Model, messages, parameters
  • Response data: Completions, token usage, timing
  • Metadata: Timestamps, SDK method, streaming info
  • Errors: API errors and exceptions

🔧 Configuration Options

🛡️ Environment Variables

Variable Description
LLM_WAREHOUSE_API_KEY Your warehouse API token (enables auto-patching)
LLM_WAREHOUSE_URL Your warehouse URL

🔄 Programmatic Control

import llm_warehouse

# Enable logging
llm_warehouse.patch(warehouse_url="...", api_key="...")

# Disable logging
llm_warehouse.unpatch()

# Check status
if llm_warehouse.is_patched():
    print("LLM calls are being logged")

🏗️ Backend Options

Flask Warehouse Backend

Use with the included Flask app for full control:

llm_warehouse.patch(
    warehouse_url="https://your-warehouse.com",
    api_key="your-warehouse-api-key"
)

Supabase Backend

Direct integration with Supabase:

llm_warehouse.patch(
    supabase_url="https://your-project.supabase.co",
    supabase_key="your-supabase-anon-key"
)

Local File Backend

For development and testing:

llm_warehouse.patch(log_file="llm_calls.jsonl")

📦 Features

  • Zero-configuration: Works out of the box with environment variables
  • Multiple backends: Flask warehouse, Supabase, local files
  • Async support: Full async/await compatibility
  • Streaming support: Captures streaming responses
  • Error handling: Logs API errors and exceptions
  • Minimal overhead: Designed for production use
  • Thread-safe: Works in multi-threaded applications

🧪 Development

git clone https://github.com/sinanozdemir/llm-warehouse.git
cd llm-warehouse/llm-warehouse-package
pip install -e ".[dev]"

Run tests:

pytest

Format code:

black llm_warehouse/
isort llm_warehouse/

📝 License

MIT License - see LICENSE file for details.

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_warehouse-0.1.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

llm_warehouse-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llm_warehouse-0.1.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for llm_warehouse-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9140e445fdd5c87796f66d0dadf52269748d005a1335df2dd9b55fbcf68b5fd3
MD5 1552da16fb4ad3ae3f7a4fcc27d15477
BLAKE2b-256 c6ad1ce7df3d0fe6417a9a69f1e3361793231c4ea7d45d9ad1fd84de8d781066

See more details on using hashes here.

File details

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

File metadata

  • Download URL: llm_warehouse-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for llm_warehouse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85e12b6a4060e2e2c53e137fa04e765667e9e6834b3ab232aed2ab70d59d46ef
MD5 f7e3e38601a03458eae8152f0e1149ee
BLAKE2b-256 db28a4c78b7290fcddaf78b4f70ead8880214a3cea72798c81d1ddbaffdf781b

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