This page explains the TypeScript proxy helper flow in the exact order users usually get stuck on: which API key belongs where, when to initialize the agent, and whatDocumentation Index
Fetch the complete documentation index at: https://whyops.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
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
| Credential | Where it lives | What it is used for |
|---|---|---|
WHYOPS_API_KEY | Your app environment | Authenticates agent init, manual events, and the patched provider client talking to WhyOps |
WHYOPS_API_KEY in the provider client constructor | Your app environment | The simplest constructor value when you are routing through WhyOps and storing the real provider credential in WhyOps |
| Provider credential in the WhyOps dashboard | WhyOps provider settings | Lets WhyOps authenticate upstream when it forwards the proxied request |
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. 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. Create and initialize the WhyOps client
Build the
WhyOps instance and call await whyops.initAgent() during startup.3. Create the provider SDK client normally
Construct the OpenAI or Anthropic SDK client using the provider library you already use.
4. Patch the provider client with WhyOps
Call
whyops.openai(...) or whyops.anthropic(...) immediately after creating the client.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.