Start free

Vercel AI SDK integration

Observability for Vercel AI SDK

Trace generateText, streamText, model steps, and tool calls in production. Inspect streaming latency and errors, find recurring failures across sessions, and turn real traces into evals.

ADD TRACING TO YOUR AI SDK APP

import { Latitude, capture } from "@latitude-data/telemetry"
import { generateText, registerTelemetry } from "ai"
import { OpenTelemetry } from "@ai-sdk/otel"
import { openai } from "@ai-sdk/openai"

const latitude = new Latitude({
  apiKey: process.env.LATITUDE_API_KEY!,
  project: process.env.LATITUDE_PROJECT_SLUG!,
})

await latitude.ready
registerTelemetry(new OpenTelemetry())

await capture(
  "support-agent-turn",
  async () => {
    const { text } = await generateText({
      model: openai("gpt-4o"),
      instructions: "You are a helpful support agent.",
      prompt: userMessage,
      telemetry: { functionId: "support-agent" },
    })
    return text
  },
  { sessionId: conversationId, userId },
)

AI SDK 7 emits OpenTelemetry GenAI spans after one global registration. AI SDK 6 uses per-call experimental_telemetry. Latitude ingests both formats.

What your Vercel AI SDK traces turn into

Complete generation and tool workflows you can follow end to end, with streaming performance and recurring failures grouped for you.

  • Complete AI SDK operationsEach generateText or streamText call becomes one operation with every model step and tool execution nested beneath it.
  • Model steps and tool executionEach provider call and execute_tool operation appears as its own span with messages, arguments, results, finish reason, and status.
  • Streaming performance and errorsInspect response time, time to first output, time between chunks, aborted streams, and error events in the workflow that produced them.
  • Cost, usage, and metadataToken usage, model, provider, function id, tags, users, and release metadata remain filterable across traces.

Three steps to your first trace

Register the AI SDK OpenTelemetry integration once, then run generateText or streamText as usual. Latitude receives standard OpenTelemetry GenAI spans.

1

Install telemetry

Vercel AI SDK observability is TypeScript only. Use the setup that matches your installed ai major version.

2

Register and capture

For AI SDK 7, initialize Latitude first and register @ai-sdk/otel once. Telemetry is then enabled by default for AI SDK calls. Wrap each request or job in capture() to attach a session id, user id, tags, and metadata.

3

Run one request

Open Traces. The AI SDK operation, provider calls, tool executions, messages, token usage, finish reasons, and streaming performance appear in one execution tree.

Send your first trace in minutes. AI SDK 7 telemetry is opt-out after global registration. Put system instructions in the top-level instructions field so they appear correctly in traces. Use telemetry recordInputs and recordOutputs controls for sensitive content. Vercel AI SDK 7 integration guide →

Debug Vercel AI SDK failures in production

The production failures created by streaming responses, multi-step tool loops, provider differences, and structured output.

Stream errors hidden inside the response

streamText starts streaming immediately, and many provider failures arrive as error parts inside the response. A rejected provider call records an exception on the model span. A failure that arrives mid-stream ends the operation with the error finish reason, so add onError for the error itself and keep telemetry on to hold the request, model, user, and release around it.

Trace errors →Vercel streamText docs

Tool input or execution failures

A model emits invalid arguments, a provider ignores unsupported strict mode, or the tool throws during execute. Tool spans preserve the schema-driven call, its arguments, duration, and either the result or the recorded exception.

Tool-call spans →AI SDK tool calling

Multi-step loops waste tokens

The model keeps calling tools until stopWhen ends the run, or a denied tool is requested again. The trace shows every step and the Thrashing flagger detects repeated tool use without progress.

Flaggers →

Structured output breaks downstream code

A generated object fails its schema, a response ends with length or content-filter, or a partial stream reaches the UI. Output Schema Validation and Empty Response flaggers surface recurring failures across releases.

Signals →

Find recurring failures hidden across AI SDK sessions

Reading traces one at a time finds the failure you went looking for. Latitude surfaces the one costing you the most sessions.

Search

Describe it in plain language

Find sessions by meaning, exact text, function id, model, provider, tool, release, user, or metadata.

Search →

Behaviors

Grouped by what users tried to do

Whole sessions cluster by user intent and outcome across generateText, streamText, and tool steps.

Behaviors →

Signals

One named, tracked problem

Repeated failures become one Signal with affected traces, examples, a trend, and a lifecycle. Evaluations keep scoring new traffic after the fix.

Signals →

From production failure to verified fix

Turn a recurring Vercel AI SDK failure into a regression test, an opened PR, and evidence from new traffic.

DetectLatitude groups repeated partial-stream sessions into a Signal.
TestTurn affected production traces into a regression eval.
FixAgent Dispatch sends the Signal, sample traces, and repo context to Claude Code or Cursor. Your coding agent writes the smallest fix, adds a regression test, and opens a PR.
VerifyLatitude scores new AI SDK traffic and alerts you if the failure returns.

Latitude detects and verifies. Your coding agent writes the fix. You review the PR.

Fits the Vercel AI SDK stack you already have

  • AI SDK 7 and AI SDK 6
  • generateText, streamText, and tool calls
  • Any AI SDK model provider
  • Cloud or self-hosted Latitude (MIT)

Using ai@7? Install @ai-sdk/otel and register OpenTelemetry once. Using ai@6? Pass experimental_telemetry with the Latitude tracer on each call. AI SDK 6 guide →

Already exporting OpenTelemetry?

Keep your existing provider setup. Vercel AI SDK 7 emits OpenTelemetry GenAI semantic-convention spans through @ai-sdk/otel, and Latitude accepts standard OTLP over HTTP. You can add Latitude to the same collector pipeline or use the Latitude SDK as the tracer provider. AI SDK telemetry docs

Latitude ingests the recommended GenAI semantic-convention format and the legacy AI SDK ai.* format. AI SDK 7 uses global, opt-out telemetry after registration. AI SDK 6 enables telemetry per generateText or streamText call.

When do you need more than Vercel AI SDK telemetry?

OpenTelemetry explains one generation workflow. Production observability also needs to show which failures keep happening across users, releases, and sessions.

CapabilityApplication logsAI SDK OpenTelemetryLatitude
Model and tool spansManualYesYes
Streaming latency and finish reasonsManualYesYes
Complete user sessionsManualRequires groupingYes
Semantic search across sessionsNoNoYes
Recurring failure discoveryManualManual analysisSignals
Production traces into evalsNoSeparate workflowYes
Dispatch to your coding agent and verifyNoNoYes
Self-hosted observabilityDependsCollector-dependentYes

MIT

Open source, 4.5k github stars

20K

Free credits a month, 30-day retention

Unlimited

Seats on every plan, no per-user pricing

GDPR

Compliant, data in AWS eu-central-1

Vercel AI SDK observability FAQ

How do I add observability to Vercel AI SDK 7?

Install @latitude-data/telemetry and @ai-sdk/otel. Initialize Latitude and wait for latitude.ready, then call registerTelemetry(new OpenTelemetry()) once. Every generateText and streamText call emits telemetry by default after registration. Wrap requests in capture() to attach a session id, user id, tags, and metadata.

Does Latitude support Vercel AI SDK 6?

Yes. AI SDK 6 uses the experimental_telemetry option on each generateText or streamText call. Enable it and pass latitude.getTracer("vercelai"). Latitude ingests the legacy ai.* spans emitted by that version.

What appears in a Vercel AI SDK trace?

A trace can include the full generateText or streamText operation, each provider call, tool execution, input and output messages when enabled, tool arguments and results, token usage, finish reasons, response time, time to first output, and streaming chunk timing.

Why does streamText fail without throwing an exception?

streamText starts streaming immediately. Many errors are returned as error parts in the stream so the server process can continue. Add an onError callback for application logging and keep telemetry enabled so the failed operation stays in the trace with its error finish reason, alongside the request, model, user, and release that produced it.

Can I send Vercel AI SDK OpenTelemetry spans through my existing collector?

Yes. Latitude accepts standard OTLP over HTTP at https://ingest.latitude.so/v1/traces. Point an existing OpenTelemetry pipeline to that endpoint with the Authorization and X-Latitude-Project headers. OpenTelemetry GenAI attributes provide the model, messages, token usage, finish reason, and tool details Latitude needs to render AI traces.

Does Latitude work with every AI SDK model provider?

Latitude reads the OpenTelemetry spans emitted by the AI SDK, so the integration works across AI SDK providers. Provider and model names appear on each model span. Provider-specific support for strict tool schemas and metadata can still differ.

How do I protect sensitive prompts and tool data?

Set telemetry recordInputs or recordOutputs to false for calls that contain sensitive content. AI SDK 7 also lets you include selected runtime and tool context fields while excluding the rest. Latitude supports ingest-side PII redaction and self-hosting for stricter data controls.

Does Latitude send fixes directly to production?

No. Agent Dispatch sends the Signal, sample traces, and relevant context to your coding agent, such as Claude Code or Cursor. That coding agent writes the smallest fix and regression test, then opens a PR. A human reviews and merges the change.

Trace your first Vercel AI SDK request

Connect your AI SDK application, run one production-like generateText or streamText request, and inspect the full model and tool workflow in Latitude.

No credit card required.