Vercel AI for Remix

Adds instrumentation for the Vercel AI SDK. (default)

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.

Copied
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  // Tracing must be enabled for agent tracing to work
  tracesSampleRate: 1.0,
  integrations: [Sentry.vercelAIIntegration()],
});

By default, tracing support is added to the following ai functions:

  • generateText()
  • streamText()
  • generateObject() — on AI SDK v6 and below
  • streamObject() — on AI SDK v6 and below
  • embed()
  • embedMany()
  • rerank()
  • experimental_decide() — requires Sentry SDK 11.7.0 or higher and AI SDK 7.0.128 or higher

Plus generate() and stream() on ToolLoopAgent.

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():

Copied
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.

Copied
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  tracesSampleRate: 1.0,
  integrations: [
    Sentry.vercelAIIntegration({
      recordInputs: false,
      recordOutputs: false,
    }),
  ],
});
Was this helpful?
Help improve this content
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").