---
title: "Vercel AI"
description: "Adds instrumentation for Vercel AI SDK."
url: https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/integrations/vercelai/
---

# Vercel AI | Sentry for Cloudflare

Requires SDK version `10.6.0` or higher for Node.js, Cloudflare Workers, Vercel Edge Functions and Bun. Requires SDK version `10.12.0` or higher for Deno.

On Cloudflare, AI SDK v7 support requires SDK version `10.64.0` or higher and the [`@sentry/cloudflare/nodejs_compat`](https://docs.sentry.io/platforms/javascript/guides/cloudflare/features/nodejs-compat.md) entrypoint.

Don't use the AI SDK's `registerTelemetry` API (AI SDK v7 and above) together with this integration. Sentry's `vercelAIIntegration` already instruments the AI SDK, so registering telemetry separately will result in duplicate spans.

`dataCollection: {}` enables the SDK's **permissive** defaults — generative AI inputs/outputs **and** other categories (user identity, cookies, headers, HTTP bodies, query parameters, and stack-frame locals) unless you override them. See [`dataCollection`](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options.md#dataCollection).

*Import name: `Sentry.vercelAIIntegration`*

The `vercelAIIntegration` adds instrumentation for the [`ai`](https://www.npmjs.com/package/ai) SDK by Vercel to capture spans using the [`AI SDK's built-in Telemetry`](https://sdk.vercel.ai/docs/ai-sdk-core/telemetry).

Not enabled by default. For AI SDK v7, register it with the [`nodejs_compat`](https://docs.sentry.io/platforms/javascript/guides/cloudflare/features/nodejs-compat.md) entrypoint (requires the Wrangler `nodejs_compat` compatibility flag):

```javascript
import * as Sentry from "@sentry/cloudflare/nodejs_compat";

export default Sentry.withSentry(
  (env) => ({
    dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    tracesSampleRate: 1.0,
    dataCollection: {},
    integrations: [Sentry.vercelAIIntegration()],
  }),
  {
    async fetch(request, env, ctx) {
      /* ... */
    },
  },
);
```

For AI SDK versions before v7, import `@sentry/cloudflare` instead and use the same options.

To correctly capture spans, pass the `experimental_telemetry` object with `isEnabled: true` to every `generateText`, `generateObject`, `streamText`, and `ToolLoopAgent` call. For more details, see the [AI SDK Telemetry Metadata docs](https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#telemetry-metadata).

```javascript
const result = await generateText({
  model: openai("gpt-4o"),
  experimental_telemetry: {
    isEnabled: true,
    recordInputs: true,
    recordOutputs: true,
  },
});
```

## [Options](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/integrations/vercelai.md#options)

### [`enableTruncation`](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/integrations/vercelai.md#enabletruncation)

*Type: `boolean`*

Enables or disables truncation of recorded input messages. Truncation keeps large payloads within span size limits.

Defaults to `true`.

```javascript
import * as Sentry from "@sentry/cloudflare/nodejs_compat";

export default Sentry.withSentry(
  (env) => ({
    dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    integrations: [
      Sentry.vercelAIIntegration({ enableTruncation: false }),
    ],
  }),
  {
    async fetch(request, env, ctx) {
      /* ... */
    },
  },
);
```

### [`recordInputs` and `recordOutputs`](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/integrations/vercelai.md#recordinputs-and-recordoutputs)

Integration-level `recordInputs` / `recordOutputs` need AI SDK v7+ and the [`nodejs_compat`](https://docs.sentry.io/platforms/javascript/guides/cloudflare/features/nodejs-compat.md) entrypoint. On the default entrypoint, set `recordInputs` / `recordOutputs` on each call’s `experimental_telemetry` instead (see [Configuration](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/integrations/vercelai.md#configuration)).

```javascript
// @sentry/cloudflare/nodejs_compat only (AI SDK v7+)
import * as Sentry from "@sentry/cloudflare/nodejs_compat";

export default Sentry.withSentry(
  (env) => ({
    dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    tracesSampleRate: 1.0,
    dataCollection: {},
    integrations: [
      Sentry.vercelAIIntegration({
        recordInputs: true,
        recordOutputs: true,
      }),
    ],
  }),
  {
    async fetch(request, env, ctx) {
      /* ... */
    },
  },
);
```

## [ToolLoopAgent](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/integrations/vercelai.md#toolloopagent)

The integration also captures spans for the [`ToolLoopAgent`](https://ai-sdk.dev/docs/agents/overview#toolloopagent-class) class. Each call to `generate()` or `stream()` creates an agent span with individual LLM requests and tool executions as child spans.

Pass `experimental_telemetry` with `isEnabled: true` to the `ToolLoopAgent` constructor to correctly capture spans:

```javascript
const agent = new ToolLoopAgent({
  model: openai("gpt-4o"),
  tools: {
    /* ... */
  },
  experimental_telemetry: { isEnabled: true },
});

const result = await agent.generate({
  prompt: "What is the weather in San Francisco?",
});
```

## [Identifying functions](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/integrations/vercelai.md#identifying-functions)

In order to make it easier to correlate captured spans with the function calls we recommend setting `functionId` in `experimental_telemetry` in all generation function calls:

```javascript
const result = await generateText({
  model: openai("gpt-4o"),
  experimental_telemetry: {
    isEnabled: true,
    functionId: "my-awesome-function",
  },
});
```

For `ToolLoopAgent`, set `functionId` in the constructor:

```javascript
const agent = new ToolLoopAgent({
  model: openai("gpt-4o"),
  tools: {
    /* ... */
  },
  experimental_telemetry: {
    isEnabled: true,
    functionId: "weather-agent",
  },
});
```

## [Configuration](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/integrations/vercelai.md#configuration)

By default this integration adds tracing support to all `ai` function callsites. If you need to disable span collection for a specific call, you can do so by setting `experimental_telemetry.isEnabled` to `false` in the first argument of the function call.

```javascript
const result = await generateText({
  model: openai("gpt-4o"),
  experimental_telemetry: { isEnabled: false },
});
```

If you set `experimental_telemetry.recordInputs` and `experimental_telemetry.recordOutputs` it will override the default behavior of collecting inputs and outputs for that function call.

```javascript
const result = await generateText({
  model: openai("gpt-4o"),
  experimental_telemetry: {
    isEnabled: true,
    recordInputs: true,
    recordOutputs: true,
  },
});
```

## [Supported Versions](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/integrations/vercelai.md#supported-versions)

* `ai`: `>=3.0.0 <=7`

## [Troubleshooting](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/integrations/vercelai.md#troubleshooting)
