Integration with the Observ AI platform for Python projects.
Project description
Observ Python SDK
AI tracing and semantic caching SDK for Observ.
Installation
pip install observ-sdk
Install provider-specific SDKs as needed:
# For Anthropic
pip install observ-sdk[anthropic]
# For OpenAI (also used by xAI and OpenRouter)
pip install observ-sdk[openai]
# For Google Gemini
pip install observ-sdk[gemini]
# For Mistral
pip install observ-sdk[mistral]
# Install all providers
pip install observ-sdk[all]
Quick Start
Anthropic
import anthropic
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True, # Enable semantic caching
)
client = anthropic.Anthropic(api_key="your-anthropic-key")
client = ob.anthropic(client)
# Use normally - all calls are automatically traced
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.content[0].text)
OpenAI
import openai
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True,
)
client = openai.OpenAI(api_key="your-openai-key")
client = ob.openai(client)
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
Google Gemini
import google.generativeai as genai
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True,
)
genai.configure(api_key="your-gemini-key")
model = genai.GenerativeModel("gemini-pro")
model = ob.gemini(model)
response = model.generate_content("Hello!")
print(response.text)
Mistral
from mistralai import Mistral
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True,
)
client = Mistral(api_key="your-mistral-key")
client = ob.mistral(client)
response = client.chat.completions.create(
model="mistral-large-latest",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
xAI (Grok)
import openai
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True,
)
client = openai.OpenAI(
api_key="your-xai-key",
base_url="https://api.x.ai/v1"
)
client = ob.xai(client)
response = client.chat.completions.create(
model="grok-beta",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
OpenRouter
import openai
from observ import Observ
ob = Observ(
api_key="your-observ-api-key",
recall=True,
)
client = openai.OpenAI(
api_key="your-openrouter-key",
base_url="https://openrouter.ai/api/v1"
)
client = ob.openrouter(client)
response = client.chat.completions.create(
model="openai/gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
Configuration
ob = Observ(
api_key="your-observ-api-key", # Required
recall=True, # Enable semantic caching (default: False)
environment="production", # Environment tag (default: "production")
endpoint="https://api.observ.dev", # Custom endpoint (optional)
debug=False, # Enable debug logging (default: False)
)
Features
- Automatic Tracing: All LLM calls are automatically traced
- Semantic Caching: Cache similar prompts to reduce costs and latency
- Multi-Provider: Support for Anthropic, OpenAI, Gemini, Mistral, xAI, and OpenRouter
- Session Tracking: Group related calls with session IDs
- Metadata: Attach custom metadata to traces
Metadata and Sessions
All wrapped clients support metadata and session ID chaining:
# Add metadata to a request
response = client.messages.with_metadata({"user_id": "123", "feature": "chat"}).create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "Hello!"}]
)
# Track conversation sessions
response = client.messages.with_session_id("conversation-abc").create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "Hello!"}]
)
# Combine both
response = client.messages.with_metadata({"user_id": "123"}).with_session_id("session-abc").create(
model="claude-sonnet-4-20250514",
messages=[{"role": "user", "content": "Hello!"}]
)
License
MIT
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
observ_sdk-0.1.0.tar.gz
(7.8 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
File details
Details for the file observ_sdk-0.1.0.tar.gz.
File metadata
- Download URL: observ_sdk-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddcfbd39a24ef86b265a95718dddae271561f507a1a5d253eb331f2f9eb0649e
|
|
| MD5 |
3fc4cf13a02789e08c6e1dbd1f123174
|
|
| BLAKE2b-256 |
0d3861f7a66b2b8cf7c3358c41e69e8917b89631a6b6af17accd703209e67162
|
File details
Details for the file observ_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: observ_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34cd2bb1e4ee3094948957cb8bd4f2b7be50b0aa6f7613b7c99a1308b6acef0a
|
|
| MD5 |
6d7e45524794b423a50010afb67fbff3
|
|
| BLAKE2b-256 |
2971a0d1bac82372f5ee5472f69033a5159a71cf7489b0668ecd85f7d9fea2fd
|