OpenAI
Trace every OpenAI client call with Rius without touching your call sites.
Setup
Python
pip install "glassflow-rius[openai]" openaiThe extra installs the instrumentation, not openai itself, so the
package is named here for a fresh environment. A project that already
calls OpenAI has it, and pip leaves it untouched. Without it, init()
logs a DependencyConflict and this integration stays off.
import rius
from openai import OpenAI
rius.init(api_key="gf_...", 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 Python 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:
Python
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
(captureContent: false in TypeScript) and masking apply to instrumented
calls exactly like manual ones.