from glass import init, trace, interactionfrom openai import OpenAI# Initialize Glassinit(api_key="your-glass-api-key")# Your AI calls are now automatically tracedclient = OpenAI()@trace()def generate_response(prompt: str) -> str: response = client.chat.completions.create( model="gpt-4", messages=[{"role": "user", "content": prompt}] ) return response.choices[0].message.content# Track user interactionswith interaction(user_id="user_123", session_id="sess_abc") as ctx: result = generate_response("What is the meaning of life?") ctx.finish(output={"response": result})
That’s it. All your OpenAI, Anthropic, and Google Generative AI calls are now traced automatically.
API Reference
init()
Initializes the Glass SDK. Call this once at application startup.
from glass import init# Basic initializationinit(api_key="your-api-key")# With debug mode (logs traces to console)init(api_key="your-api-key", debug=True)
string
Your Glass API key. Falls back to GLASS_API_KEY environment variable if not provided.
boolean
default:"False"
Enable console output for local development.
boolean
default:"False"
Disable automatic tracing of AI providers. See Instrumentations for details.
list
Custom OpenTelemetry instrumentors. See Instrumentations for details.
@trace()
Decorator that wraps any function with tracing. Automatically records arguments, return values, and exceptions.