Vercel AI SDK

Vercel AI SDK Integration

Call instrumentVercelAI() at startup, then pass the telemetry object to any AI call. Works with generateText, streamText, generateObject, and streamObject — TypeScript only.

Vercel AI SDK is a TypeScript library for building AI-powered applications with Next.js, supporting multiple LLM providers through a unified interface.

zespan.com — vercel ai sdk trace
Zespan trace showing a Vercel AI SDK generateText call with token usage and latency

Getting Started

1

Install the SDK

Install @zespan/sdk alongside your existing Vercel AI SDK setup.

bash
npm install @zespan/sdk ai
2

Instrument and trace AI calls

Call instrumentVercelAI() at startup to get a telemetry settings object, then pass it to any AI function via experimental_telemetry.

typescript
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { Zespan, instrumentVercelAI } from '@zespan/sdk';

Zespan.init({ apiKey: process.env.ZESPAN_API_KEY });
const telemetry = instrumentVercelAI();

const result = await generateText({
  model: openai('gpt-4o'),
  prompt: 'Explain quantum entanglement simply',
  experimental_telemetry: telemetry,
});
3

View traces in Zespan

Open Trace Explorer. Vercel AI SDK calls appear with provider, model, token usage, cost, and latency.

What's captured automatically

  • Works with generateText, streamText, generateObject, streamObject, embed, and embedMany
  • All Vercel AI SDK providers: OpenAI, Anthropic, Google, Groq, and more
  • Next.js App Router and Pages Router compatible
  • Streaming: time-to-first-token tracked accurately
  • Tool calls: function call arguments and results captured as child spans
  • Alternative: use getZespanVercelTelemetry() if you prefer not to call instrumentVercelAI()

FAQ

Does this work in Next.js Server Actions?

Yes. instrumentVercelAI() works in API routes, Server Actions, and edge functions.

Is this TypeScript only?

Yes. The Vercel AI SDK is TypeScript-only, so this integration is TypeScript only as well.

Start free — 10K traces a month, no card needed

Vercel AI SDK integration works on all plans including the free tier.

← All integrations