Skip to main content
This page explains the Python proxy helper flow in the exact order users usually get stuck on: which API key belongs where, when to initialize the agent, and what sdk.openai() or sdk.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 common mistakes.

Which API key goes where

After you call sdk.openai(client) or sdk.anthropic(client), the SDK mutates the client in place so outgoing traffic authenticates to WhyOps with WHYOPS_API_KEY and X-Agent-Name.
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 sdk.init_agent_sync() or await sdk.init_agent() 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 sdk.openai(...) or sdk.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 the X-External-User-Id header:

Anthropic helper

What the helper changes

The proxy route checks X-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 agent_name between 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-ID yourself 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.

If you are not using the helper

Go to OpenAI Proxy API or Anthropic Proxy API for direct proxy configuration without the published SDK.