whyops.openai() or whyops.anthropic() actually changes.
Quickstart
Start there first if you have not created and initialized the WhyOps client yet.
Runtime Events
Add runtime tracing after the proxy flow is already working.
Advanced Patterns
Move there for hybrid tracing, self-hosting, prompt caching, and event IDs.
Which API key goes where
After you call
whyops.openai(client) or whyops.anthropic(client), the SDK mutates the client in place so outgoing traffic authenticates to WhyOps with WHYOPS_API_KEY and X-Agent-Name.The recommended order
1
1. Store the provider credential in WhyOps
Add your OpenAI or Anthropic provider key in the WhyOps dashboard so WhyOps can forward proxied requests upstream.
2
2. Create and initialize the WhyOps client
Build the
WhyOps instance and call await whyops.initAgent() during startup.3
3. Create the provider SDK client normally
Construct the OpenAI or Anthropic SDK client using the provider library you already use.
4
4. Patch the provider client with WhyOps
Call
whyops.openai(...) or whyops.anthropic(...) immediately after creating the client.5
5. Send requests as usual
Your app code stays the same after patching. The client now routes through WhyOps.
OpenAI helper
Linking requests to users
To associate proxied requests with your application user IDs, add theX-External-User-Id header:
Anthropic helper
What the helper changes
Why explicit trace headers are recommended
The proxy route checksX-Trace-ID and X-Thread-ID before it falls back to invisible-signature extraction or auto-generated trace IDs. If your workflow includes later tool execution, manual trace() events, or multi-step orchestration, reusing the same explicit trace ID keeps everything on the same thread more reliably.
Common mistakes
- Do not change
agentNamebetween startup, proxied traffic, and runtime events. - Do not rely only on auto-generated trace IDs if your app later emits manual tool or runtime events. Set
X-Trace-IDyourself and reuse it. - Do not keep using the patched client for direct provider traffic; keep a second unpatched client if you need both paths.
- Do not skip provider configuration in the WhyOps dashboard and assume the constructor key alone is enough for proxied upstream traffic.
- Do not start with runtime events first if your real goal is proxy instrumentation. Get the proxy path working, then layer runtime events on top.