Skip to main content

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


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.2.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

observ_sdk-0.1.2-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file observ_sdk-0.1.2.tar.gz.

File metadata

  • Download URL: observ_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for observ_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 165438d18cf8a267365d5568416cb0f3e440360d354a085f4100949df934d53a
MD5 c6d3d39e30a7c60ba6d06afb262cc451
BLAKE2b-256 04ac4fc9e88f06e633ea0f316ba3fc0329e0dd98e4c0f4b5531a4bd97f75c515

See more details on using hashes here.

File details

Details for the file observ_sdk-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: observ_sdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for observ_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 22e35626590f56d0a8e31f4363ca47912ef3c98bb63bf4aee758314196ed01b0
MD5 ac73a10a6dd6db9f95bb63196ab7dc2b
BLAKE2b-256 c305e1c8afe93b2e2f2c8f750f8de8f9ffe3b7c0a1a29d68f7a53677e12ec0a9

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