OpenAI
Trace every OpenAI client call with Rius without touching your call sites.
Setup
pip install "glassflow-ai[openai]"import glassflow
from openai import OpenAI
glassflow.init(api_key="glassflow_...", service_name="my-agent")
client = OpenAI() # use the client exactly as beforeinit() detects the installed extra and instruments the client library
process-wide; every call from anywhere in your process is traced.
What gets captured
Each chat completion becomes an LLM-kind span carrying the model, token usage, and input/output messages; cost is computed server-side from the model and tokens. On streamed calls the instrumentor also records a first-token event, so time to first token works without any manual code.
Streaming and token usage
Streamed responses do not include usage by default; ask OpenAI to send it with the final chunk:
stream = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
stream=True,
stream_options={"include_usage": True},
)Without it, streamed spans have no token counts, and no tokens means no cost.
Verify
Run one call, then open the trace in the console: the span shows the
resolved model (e.g. gpt-4o-mini-2024-07-18), input/output token counts,
and a cost. Wrap the call in @observe
to see it nested inside your agent’s run instead of as a standalone trace.
Prompt and response content is subject to your
privacy controls: capture_content=False
and masking apply to instrumented calls exactly like manual ones.