Cascade auto-detects OpenAI clients by module name or chat.completions API structure. Wrap your client once and all calls are automatically traced.
Setup
from cascade import init_tracing, wrap_llm_client
from openai import OpenAI
init_tracing(project="my_agent")
client = wrap_llm_client(OpenAI())
Usage
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}],
)
# Automatically traced!
Streaming
Streaming is fully supported:
stream = client.chat.completions.create(
model="gpt-4",
messages=messages,
stream=True
)
for chunk in stream:
...
The wrapped client behaves identically to the original. All existing method calls, attributes, and patterns continue to work. The only difference is that LLM calls now produce spans in your Cascade traces.
If the SDK does not recognize a client type, it returns the client unwrapped with a warning. LLM calls will still work but won’t be traced.