Skip to Content

How do I trace the Vercel AI SDK in TypeScript?

Rius traces the Vercel AI SDK in TypeScript when you install @glassflow-ai/rius, call init(), and, on ai 7, also install @ai-sdk/otel. On ai 5 and 6 you add no package and turn telemetry on for each call. Every traced call arrives with its messages, model, token usage and a cost computed by Rius. This integration is TypeScript only, because the Vercel AI SDK is a JavaScript library.

How it works

The setup depends on which version of ai you run.

  • ai 7: the AI SDK no longer emits OpenTelemetry spans itself. They come from the official @ai-sdk/otel package, and init() registers it for you when it finds it installed. No telemetry code is needed in your application. @ai-sdk/otel needs Node 22 or newer, the same floor as ai 7.
  • ai 5 and 6: the AI SDK has OpenTelemetry built in but emits nothing until a call opts in. You set isEnabled to true inside experimental_telemetry on each call. Nothing else is installed, and any Node version the SDK supports (18 or newer) works.

Either way, Rius stores the same data for a call. The SDK counts each model call once in token and cost totals, while the wrapper span around the calls still shows the run’s total. Your privacy controls apply to everything this integration produces, so captureContent: false and a mask cover prompts, responses, tool definitions and tool call arguments and results.

The Vercel AI SDK integration page covers every detail, and the Integrations page lists the other libraries and frameworks Rius traces.

Set it up

  1. Install the SDK and its peer dependency, plus @ai-sdk/otel if you use ai 7. The installation page covers the full configuration reference.

    npm install @glassflow-ai/rius @opentelemetry/api npm install @ai-sdk/otel # ai 7 only, needs Node 22 or newer
  2. On ai 7, call init() once, as early as possible, then make your call. init() is synchronous and integrations attach asynchronously, so await ready before the first call. Because a short script can exit before queued spans are sent, end with shutdown().

    import { init } from '@glassflow-ai/rius' import { openai } from '@ai-sdk/openai' import { generateText } from 'ai' const rius = init({ apiKey: 'ri_...', serviceName: 'my-agent' }) await rius.ready // the Vercel AI integration is attached before the first call const { text } = await generateText({ model: openai('gpt-4o-mini'), prompt: 'Summarize this ticket', }) await rius.shutdown() // export queued spans before the process exits
  3. On ai 5 or 6, skip @ai-sdk/otel and keep the same init() call. Add experimental_telemetry to each call you want traced:

    const { text } = await generateText({ model: openai('gpt-4o-mini'), prompt: 'Summarize this ticket', experimental_telemetry: { isEnabled: true }, })
  4. To see the call inside your agent’s run instead of as a standalone trace, wrap the surrounding function in observe and give that function a name.

  5. Run one call and open the trace in the console. On ai 7, await client.ready lists vercel-ai when the integration attached. If no spans appear on ai 7, check the process log: Rius warns at init() when it finds ai 7 without @ai-sdk/otel, because that combination produces no spans. On ai 5 and 6, ready does not list vercel-ai even when tracing works, because there is nothing to register. The usual cause of missing spans there is a call without isEnabled set to true.

What you get

Each traced call shows up in the console with:

  • Messages and model: the input and output messages, the request’s tool definitions, the resolved model and the finish reason.
  • Token usage: input and output tokens, including cache reads and reasoning tokens, with each call counted once.
  • Cost: computed by Rius from the model and tokens. It is a list-price estimate in US dollars, and you never send a cost value.
  • Time to first token: on streamed calls.
  • Run structure: an agent span wraps the steps of a tool-calling loop. Each step has its own span, each model call gets a chat span, and each tool execution gets an execute_tool span with the tool’s arguments and result. Embedding spans are recorded too.

On ai 7, image, speech and transcription calls are traced as well, and a rerank call is a RERANKER span. On ai 5 and 6 those image, speech and transcription calls take no telemetry settings and are not traced.

When something else fits

  • If you work in Python, the Vercel AI SDK has no integration there. Trace your model calls with manual generations, or pick the integration for the library you use on the Integrations page.
  • If you need image, speech or transcription calls traced, use ai 7, since ai 5 and 6 do not trace them.
  • If prompts must not leave your process, set captureContent to false and the trace keeps its structure, models, tokens and cost without the content.

Still stuck? Get help

Last updated on