Vercel AI for Remix
Adds instrumentation for the Vercel AI SDK. (default)
Requires SDK version 11.0.0 or higher. On earlier versions, see the Agent Tracing setup for your SDK.
Import name: Sentry.vercelAIIntegration
This integration is enabled by default when tracing is enabled. If you'd like to modify your default integrations, read this.
The vercelAIIntegration adds instrumentation for the ai SDK by Vercel to capture agent tracing gen_ai spans, recording model, token usage, latency, and (when enabled) inputs and outputs.
Sentry.init({
dsn: "___PUBLIC_DSN___",
// Tracing must be enabled for agent tracing to work
tracesSampleRate: 1.0,
integrations: [Sentry.vercelAIIntegration()],
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
// Tracing must be enabled for agent tracing to work
tracesSampleRate: 1.0,
integrations: [Sentry.vercelAIIntegration()],
});
Don't use the AI SDK's registerTelemetry API (AI SDK v7 and above) together with this integration. vercelAIIntegration already instruments the AI SDK, so registering telemetry separately produces duplicate spans.
By default, tracing support is added to the following ai functions:
generateText()streamText()generateObject()— on AI SDK v6 and belowstreamObject()— on AI SDK v6 and belowembed()embedMany()rerank()experimental_decide()— requires Sentry SDK11.7.0or higher and AI SDK7.0.128or higher
Plus generate() and stream() on ToolLoopAgent.
On AI SDK v7, generateObject() and streamObject() don't produce spans. The AI SDK deprecated both in v6 and doesn't emit telemetry events for them in v7. Use generateText() or streamText() with an output setting instead, which Sentry traces like any other call. The AI SDK migration guide covers the change.
import { generateText, Output } from "ai";
import { z } from "zod";
const { output } = await generateText({
model,
output: Output.object({ schema: z.object({ name: z.string() }) }),
prompt: "Return a city name",
});
import { generateText, Output } from "ai";
import { z } from "zod";
const { output } = await generateText({
model,
output: Output.object({ schema: z.object({ name: z.string() }) }),
prompt: "Return a city name",
});
With Sentry SDK 11.7.0 or higher and AI SDK 7.0.128 or higher, vercelAIIntegration automatically traces experimental_decide() calls, including calls to TypeSafe's Jev model through Vercel AI Gateway. Keep your existing Sentry setup with tracing enabled; no additional integration or telemetry registration is needed.
Configure AI Gateway authentication with AI_GATEWAY_API_KEY or Vercel OIDC, then call experimental_decide():
import { experimental_decide } from "ai";
const result = await experimental_decide({
model: "typesafe-ai/jev",
state: "I was charged twice. Please refund the extra charge.",
questions: {
department: {
type: "choice",
instructions: "Which team should handle this?",
criteria: {
billing: "Charges and refunds",
technical: "Bugs and outages",
},
},
},
});
console.log(result.answers.department);
import { experimental_decide } from "ai";
const result = await experimental_decide({
model: "typesafe-ai/jev",
state: "I was charged twice. Please refund the extra charge.",
questions: {
department: {
type: "choice",
instructions: "Which team should handle this?",
criteria: {
billing: "Charges and refunds",
technical: "Bugs and outages",
},
},
},
});
console.log(result.answers.department);
Each call creates a gen_ai.decide span named decide <model>, with model, latency, and token usage when available. When recording is enabled, Sentry captures state and questions as input messages and answers as output messages. For TypeSafe answers, Sentry also includes confidence values from providerMetadata.typesafe.confidence when present.
Decision inputs and outputs follow the same recordInputs and recordOutputs options as other Vercel AI calls. Disable these options if decision state or answers contain sensitive data.
The AI SDK's decision API is experimental and may change in patch releases. If you use TypeSafeClient.systemOne() directly instead, see the TypeSafe integration.
ai:>=3.0.0 <=7
Type: boolean (optional)
Records inputs to ai function calls (such as prompts and messages).
Defaults to true if dataCollection.genAI.inputs is true, which is the default.
Type: boolean (optional)
Records outputs from ai function calls (such as generated text and responses).
Defaults to true if dataCollection.genAI.outputs is true, which is the default.
Sentry.init({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
integrations: [
Sentry.vercelAIIntegration({
recordInputs: false,
recordOutputs: false,
}),
],
});
Sentry.init({
dsn: "___PUBLIC_DSN___",
tracesSampleRate: 1.0,
integrations: [
Sentry.vercelAIIntegration({
recordInputs: false,
recordOutputs: false,
}),
],
});
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").