AI observability platform for LLM applications - Python SDK
Project description
Vidar Python SDK
AI observability platform for LLM applications with automatic tracing.
Installation
pip install vidar
For full functionality including async support and LLM client integrations:
pip install vidar[full]
Quick Start
import vidar
# Initialize once (like Laminar)
vidar.initialize(api_key="your-api-key")
# All LLM calls are now automatically traced!
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
# ↑ This is automatically traced with cost, latency, tokens, etc.
Features
- Zero-code tracing: Just initialize and go
- Automatic cost tracking: Real-time cost calculation
- Performance monitoring: Latency, token usage, error rates
- Session correlation: Group related LLM calls
- Multi-provider support: OpenAI, Anthropic, and more
- Async support: Works with httpx, aiohttp
- Framework integration: FastAPI, Django, Flask examples
Usage Examples
Manual Tracing
@vidar.trace("My AI Function")
def process_text(text):
vidar.add_attribute("input_length", len(text))
# Your LLM calls here
result = client.chat.completions.create(...)
vidar.add_attribute("output_length", len(result))
return result
Session Tracking
with vidar.trace("Document Analysis"):
vidar.add_attribute("session_id", "session_123")
# Multiple related LLM calls
summary = summarize_document(doc)
questions = generate_questions(doc)
answers = answer_questions(questions, doc)
Error Handling
try:
response = client.chat.completions.create(...)
except Exception as e:
vidar.set_error(e)
raise
Direct Proxy Usage
You can also use Vidar as a proxy without the SDK:
import requests
response = requests.post(
"http://localhost:8080/proxy/openai/v1/chat/completions",
headers={"Authorization": "Bearer your-vidar-api-key"},
json={"model": "gpt-4", "messages": [...]}
)
Configuration
vidar.initialize(
api_key="your-api-key",
base_url="http://localhost:8080", # Vidar server
project_id="my-project",
timeout=30.0
)
Web Framework Integration
FastAPI
from fastapi import FastAPI
import vidar
app = FastAPI()
@app.on_event("startup")
async def startup():
vidar.initialize(api_key="your-key")
@app.post("/chat")
async def chat(message: str):
with vidar.trace("Chat API"):
# Your LLM logic here
return {"response": "..."}
Django
# settings.py
MIDDLEWARE = [
'myapp.middleware.VidarMiddleware',
# ... other middleware
]
# middleware.py
import vidar
class VidarMiddleware:
def __init__(self, get_response):
self.get_response = get_response
vidar.initialize(api_key="your-key")
def __call__(self, request):
with vidar.trace(f"{request.method} {request.path}"):
return self.get_response(request)
Documentation
License
MIT License
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
Vidar-1.0.1.tar.gz
(14.7 kB
view details)
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
Vidar-1.0.1-py3-none-any.whl
(15.7 kB
view details)
File details
Details for the file Vidar-1.0.1.tar.gz.
File metadata
- Download URL: Vidar-1.0.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc882128fb0bdf1806ce1a6f1b07d2364f93577568c3b94619300804f603ccd8
|
|
| MD5 |
70a19552ff7dd5336ef88e5946620685
|
|
| BLAKE2b-256 |
d4fb7d2a19446c0579308d78b6fa7fd21438d7cf8b6295963cb9683cfbce1f17
|
File details
Details for the file Vidar-1.0.1-py3-none-any.whl.
File metadata
- Download URL: Vidar-1.0.1-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d1744cac85ed19b18ec1c12ee4eaf4b3c4e442d4d00307c04de2604b9ea5688
|
|
| MD5 |
fdb8876523448106c51e2978b990e10f
|
|
| BLAKE2b-256 |
61d3d28f059d22be4bcd5a7ae934b9233f676c0941c5d5a7a061953e292d1ae5
|