Go from install to live trace in under 5 minutes. This guide covers everything you need to add TracePilot observability to a Vercel AI SDK project.Documentation Index
Fetch the complete documentation index at: https://docs.tracepilotai.com/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- A Next.js or Node.js project using the Vercel AI SDK (
aipackage) - An OpenAI API key (or any AI SDK-compatible provider)
- Node.js 18+
1. Install
2. Add your API key
Get your key from tracepilotai.com → Account Settings. It looks liketp_live_xxxxxxxxxxxxxxxx.
.env.local
3. Initialize
Create a single TracePilot instance and reuse it across your app.lib/tracepilot.ts
4. Trace generateText
app/api/generate/route.ts
5. Trace streamText
app/api/chat/route.ts
wrapStream does not buffer or delay the stream. Time-to-first-token is unaffected.Expected trace output
After running your app, open tracepilotai.com/dashboard. You should see:
Troubleshooting
Trace not appearing in dashboard
Trace not appearing in dashboard
- Confirm
TRACEPILOT_API_KEYis set. Runconsole.log(process.env.TRACEPILOT_API_KEY)to verify it’s loaded. - Make sure
tp.startTrace()is called before anywrapGenerateorwrapStreamcall. - Check that you’re not using
.envinstead of.env.localfor local dev.
streamText span shows empty output
streamText span shows empty output
Pass the wrapped
stream (returned by tp.wrapStream) to StreamingTextResponse — not the raw result from streamText. TracePilot reads from the stream tap; passing the raw stream skips the instrumentation.TypeError: Cannot read properties of undefined (reading 'startTrace')
TypeError: Cannot read properties of undefined (reading 'startTrace')
The
TracePilotVercel instance is undefined. This usually means TRACEPILOT_API_KEY is not set. The constructor receives undefined and throws lazily. Add a startup assertion:Spans appear in dashboard but no cost data
Spans appear in dashboard but no cost data
Cost tracking requires the model name to be recognized. Ensure you’re passing a standard OpenAI model string (
gpt-4o, gpt-4o-mini, etc.). Custom fine-tuned model names are not mapped automatically.Next steps
Debugging Vercel AI SDK
Step-by-step guide to debugging generateText, streamText, and tool calls in production.
Multi-step agents
Chain spans with parentSpanId to trace complex pipelines.
Time-travel debugging
Fork any failing span and replay it without redeploying.
Cost tracking
Monitor token spend across every AI SDK call.