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
Use Respan Gateway instead? Only need Respan api key, easier setup.
Install packages
Set environment variables
No OPENAI_API_KEY needed — the Respan gateway handles provider authentication.
Initialize Respan
Next.js
Serverless
Create instrumentation.ts in your project root (same level as package.json). Next.js calls register() automatically at startup — no other initialization needed.
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:
Initialize and run
View your trace
Open the Traces page to see your AI calls with full input/output, token usage, and cost.
Initialize Respan
Next.js
Serverless
Create instrumentation.ts in your project root (same level as package.json). Next.js calls register() automatically at startup — no other initialization needed.
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.
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 routing LLM calls through the Respan Gateway (createOpenAI / createAnthropic / createGoogleGenerativeAI with baseURL pointing at Respan, or the Vercel AI Gateway model string). Follow Use Respan Gateway instead? in Setup above.
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 Respan is initialized — via
instrumentation.tsfor Next.js, orrespan.initialize()at your app’s entry point for other frameworks - 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: