camelCase names, async callbacks instead of context managers.
Assumes
TRULAYER_API_KEY and OPENAI_API_KEY are exported. Install: npm install @trulayer/sdk openai anthropic ai.1. Initialise the SDK
TruLayer instance at module scope and reuse it.
2. Trace a block of code
3. Add spans
4. Auto-instrument OpenAI
5. Auto-instrument Anthropic
6. Vercel AI SDK
The Vercel AI SDK has first-class support viainstrumentVercelAI(). It hooks into generateText, streamText, generateObject, and streamObject so every call is traced without further changes.
7. Next.js App Router
Instrument once ininstrumentation.ts at your app root — Next.js loads this file before any route handler runs.
8. Edge runtimes (Vercel Edge, Cloudflare Workers)
The SDK works in Edge runtimes — it uses nativefetch with no Node-specific APIs. One caveat: Edge runtimes terminate the isolate quickly, so always await tl.flush() before returning your response.
9. Group into a session
10. Attach metadata
11. Submit feedback
trace.id from your handler so the client can attach feedback to the right trace.