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.
ai7: the AI SDK no longer emits OpenTelemetry spans itself. They come from the official@ai-sdk/otelpackage, andinit()registers it for you when it finds it installed. No telemetry code is needed in your application.@ai-sdk/otelneeds Node 22 or newer, the same floor asai7.ai5 and 6: the AI SDK has OpenTelemetry built in but emits nothing until a call opts in. You setisEnabledto true insideexperimental_telemetryon 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
-
Install the SDK and its peer dependency, plus
@ai-sdk/otelif you useai7. 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 -
On
ai7, callinit()once, as early as possible, then make your call.init()is synchronous and integrations attach asynchronously, so awaitreadybefore the first call. Because a short script can exit before queued spans are sent, end withshutdown().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 -
On
ai5 or 6, skip@ai-sdk/oteland keep the sameinit()call. Addexperimental_telemetryto each call you want traced:const { text } = await generateText({ model: openai('gpt-4o-mini'), prompt: 'Summarize this ticket', experimental_telemetry: { isEnabled: true }, }) -
To see the call inside your agent’s run instead of as a standalone trace, wrap the surrounding function in
observeand give that function a name. -
Run one call and open the trace in the console. On
ai7,await client.readylistsvercel-aiwhen the integration attached. If no spans appear onai7, check the process log: Rius warns atinit()when it findsai7 without@ai-sdk/otel, because that combination produces no spans. Onai5 and 6,readydoes not listvercel-aieven when tracing works, because there is nothing to register. The usual cause of missing spans there is a call withoutisEnabledset 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
chatspan, and each tool execution gets anexecute_toolspan 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
ai7, sinceai5 and 6 do not trace them. - If prompts must not leave your process, set
captureContentto false and the trace keeps its structure, models, tokens and cost without the content.