/docs/integrations/wrap_openai
OpenAI
Drop-in wrapper for the OpenAI SDK. Every chat or completion call becomes an llm step with full token usage and stop reason.
Setup
from openai import OpenAI
from theta_observability import TraceClient
from theta_observability.integrations import wrap_openai
client = TraceClient()
oai = wrap_openai(OpenAI(), client)
with client.trace(name="answer-question") as t:
oai.chat.completions.create(
model="gpt-4.1-mini",
messages=[{"role": "user", "content": "Hi"}],
)What gets captured
- Provider, model, and request parameters (temperature, top_p, max_tokens, tool definitions).
- Full message history sent to the model.
- Response text and tool calls.
- Token usage (prompt, completion, total) and stop reason.
- Latency, request ID, and any error.
Streaming
Streaming responses are captured incrementally — each chunk extends the step output. The step finalizes when the stream closes.