@whyops/vercel-ai-sdk is the companion integration for apps built on the Vercel AI SDK. It sits on top of @whyops/sdk and automatically traces generateText, streamText, embed, and embedMany.
SDK Packages
Start here if you are choosing between the language SDKs and companion integrations.
TypeScript SDK
Create and initialize the base WhyOps client first, then come back here to wrap Vercel AI SDK calls.
Runtime Events
Add manual runtime events only when your app needs coverage beyond what the wrapper captures automatically.
What this package captures
When you wrap a Vercel AI SDK call with WhyOps, it captures:user_messagellm_responsellm_thinkingwhen readable reasoning text is exposedtool_call_requesttool_call_responseerrorembedding_requestembedding_response
@whyops/vercel-ai-sdk does not replace @whyops/sdk. You still create the WhyOps client with @whyops/sdk, then register that client once and wrap your Vercel AI SDK calls with this package.Install
- npm
- pnpm
- yarn
- bun
ai >= 5.0.0.
1. Create and register the WhyOps client
registerWhyOps() once during startup. After that, you wrap each Vercel AI SDK call with withWhyOps(...).
2. Wrap generateText()
Optional whyopsCtx
Pass a reusable whyopsCtx object as the second argument only when you want request-scoped linkage such as your own user ID or a caller-supplied trace ID:
whyopsCtx is optional. If you do not pass it, the wrapper keeps generating a trace automatically and does not add externalUserId.
3. Capture multi-step tool calls
withWhyOps() captures tool loops automatically. On ai@5, it also normalizes maxSteps into stopWhen so multi-step execution continues correctly.
4. Wrap streamText()
5. Use the re-exported embedding helpers
If you want embedding traces, importembed() and embedMany() from @whyops/vercel-ai-sdk instead of directly from ai.
Provider notes
- OpenAI-compatible providers that expose nonstandard reasoning fields such as
reasoning_contentare normalized before WhyOps captures the step. - If a provider reports reasoning token usage but does not expose readable reasoning text, WhyOps does not synthesize a fake
llm_thinkingevent. - This package is designed for server-side TypeScript runtimes where you already use
@whyops/sdk.
API surface
| Export | Purpose |
|---|---|
registerWhyOps(whyops) | Stores the shared WhyOps client for later wrapped calls |
withWhyOps(options, whyopsCtx?) | Wraps generateText() and streamText() options |
embed(options, whyopsCtx?) | Drop-in embedding helper with WhyOps tracing |
embedMany(options, whyopsCtx?) | Drop-in batch embedding helper with WhyOps tracing |
whyopsCtx currently supports externalUserId?: string and traceId?: string.