Vercel AI SDK
Set up Respan
- Sign up — Create an account at platform.respan.ai
- Create an API key — Generate one on the API keys page
- Add credits or a provider key — Add credits on the Credits page or connect your own provider key on the Integrations page
Use AI
Add the Docs MCP to your AI coding tool to get help building with Respan. No API key needed.
What is AI SDK?
The AI SDK (by Vercel) is a TypeScript toolkit for building AI-powered applications with Next.js, React, and other frameworks. It provides unified APIs for text generation, streaming, tool use, and structured outputs across multiple LLM providers. Respan gives you full observability over every LLM call, tool execution, and multi-step workflow.
Setup
Create instrumentation file
Tracing
Gateway
Both
Create instrumentation.ts in your project root (same level as package.json):
Configure Next.js (Next.js only)
Skip this step if you’re not using Next.js.
Add serverExternalPackages to next.config.ts so Next.js loads OpenTelemetry packages as Node.js modules instead of bundling them:
View your trace
Open the Traces page to see your AI calls with full input/output, token usage, and cost.
This step applies to Tracing and Both setups. The Gateway-only setup logs requests on the Logs page.
Configuration
Attributes
With experimental_telemetry metadata
Pass metadata directly on each AI SDK call. The instrumentation maps these to Respan fields automatically:
With propagateAttributes
Override per-request using a context scope. All AI SDK calls within the scope inherit these attributes:
Decorators (optional)
Decorators are not required. All generateText, streamText, tool calls, and agent steps are auto-traced by the instrumentation. Use withWorkflow and withTask to add structure when you want to group AI calls into named workflows with nested tasks.
Examples
Streaming with tools
Multi-step workflow
Gateway features
The features below require the Gateway or Both setup from Step 4.
Switch models
Change the model parameter to use 250+ models from different providers through the same gateway:
See the full model list.
Troubleshooting
No traces appearing
- Verify
experimental_telemetry: { isEnabled: true }is set on every AI SDK call - Check that
instrumentation.tsis in your project root (same level aspackage.json) - Ensure
RESPAN_API_KEYis set in your environment
Next.js streaming timeout
For streaming routes (streamText), set maxDuration in your route handler:
Turbopack workspace root warning
Set the root explicitly in next.config.ts: