Skip to Content
RiusSDKIntegrationsVercel AI SDK

Vercel AI SDK

Trace Vercel AI SDK calls in Rius, with prompts, responses, models, tool definitions, and token usage.

This integration is TypeScript only. The Python SDK has no Vercel AI SDK integration, because the library itself is JavaScript only.

Setup on ai 7

npm install @ai-sdk/otel

Since ai 7 the AI SDK no longer emits OpenTelemetry spans itself: they come from the official @ai-sdk/otel telemetry integration, and something has to register it. With @glassflow-ai/rius 0.6.0 or newer, init() does that for you. Install the package, initialize Rius, and every AI SDK call is traced, with no telemetry code in your application:

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 AI SDK integration is registered 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

@ai-sdk/otel requires Node 22 or newer, the same floor as ai 7 itself.

Each call arrives with its input and output messages, the request’s tool definitions, the resolved model, and token usage including cache reads, cache writes when the AI SDK reports them, and, since @glassflow-ai/rius 1.2.0, reasoning tokens. Since 1.1.0, streamed calls carry time to first token. An agent span (invoke_agent) wraps the steps of a tool-calling loop, with a span for each step, a chat span for each model call, and an execute_tool span for each tool execution. Cost is computed server-side from the model and tokens.

Setup on ai 5 and 6

These versions have OpenTelemetry built in but emit nothing unless a call opts in. Enable telemetry per call:

const { text } = await generateText({ model: openai('gpt-4o-mini'), prompt: 'Summarize this ticket', experimental_telemetry: { isEnabled: true }, })

There is nothing else to install, and it works on any Node version the SDK supports (18 or newer). Since @glassflow-ai/rius 1.2.0 a call stores the same data whichever ai version made it: an agent span for each generateText, streamText, generateObject, or streamObject call, a chat span for each model call with its messages, model, finish reason, and token usage including cache reads, cache writes when the AI SDK reports them, and reasoning tokens, execute_tool spans with the tool’s arguments and result, and embedding spans. A streamed call also carries time to first token.

Earlier releases needed @arizeai/openinference-vercel to translate these spans. Version 1.2.0 no longer uses it, so you can uninstall it.

The AI SDK’s image, speech, and transcription calls are not traced on ai 5 and 6: they take no telemetry settings. On ai 7 they are traced. Since @glassflow-ai/rius 1.4.0, speech, transcription, and decide spans are LLM spans, so a span-kind filter finds them. A transcription span carries the provider’s token usage when the provider reports one; a speech span carries none when the provider returns only audio, as OpenAI’s speech endpoint does. A rerank call is a RERANKER span.

Token usage

Each model call is counted once in tokens and cost, and the wrapper span around the calls, such as an agent span or an embed or embedMany span, still shows the run’s total where the AI SDK reports one (@glassflow-ai/rius 1.2.0, or 1.1.0 on ai 7). The dedup runs in the SDK, so @ai-sdk/otel spans sent to Rius without it are still counted twice.

Ordering and privacy

Everything the integration produces is covered by your privacy controls: captureContent: false and a mask apply to prompts, responses, tool definitions, the system prompt (gen_ai.system_instructions), and each tool call’s arguments and result (gen_ai.tool.call.arguments, gen_ai.tool.call.result) exactly as they apply to manual spans, on both the spans of ai 7 and the mapped spans of ai 5 and 6. Requires @glassflow-ai/rius 0.6.0 or later; earlier versions did not list the ai 7 system-prompt and tool-call keys as content.

Verify

Run one generateText call, then open the trace in the console. The model call span shows the resolved model, input and output token counts, and a cost, nested under an agent span for the call. Wrap the call in observe to see it inside your agent’s run instead of as a standalone trace.

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 at all. When the integration attached, await client.ready lists vercel-ai.

On ai 5 and 6, the usual cause is a call without experimental_telemetry: { isEnabled: true }. There is nothing to register on these versions, so client.ready does not list vercel-ai even when tracing works.

Last updated on