---
title: "Workers AI"
description: "Learn how Sentry instruments Cloudflare Workers AI to capture gen_ai spans."
url: https://docs.sentry.io/platforms/javascript/guides/cloudflare/agent-tracing/workers-ai/
---

# Cloudflare Workers AI

Available since: `v10.67.0`

Sentry automatically instruments the [Cloudflare Workers AI binding](https://developers.cloudflare.com/workers-ai/get-started/workers-wrangler/) (`env.AI`). Calls to `env.AI.run(...)` create `gen_ai` spans that follow Sentry's [Agent Tracing](https://docs.sentry.io/platforms/javascript/guides/cloudflare/agent-tracing.md) conventions, capturing the model, request parameters, and token usage.

No extra setup is required beyond the [quick start](https://docs.sentry.io/platforms/javascript/guides/cloudflare.md). The `AI` binding on the `env` that your handler receives is instrumented for you:

```typescript
export default {
  async fetch(request, env) {
    // env.AI is automatically instrumented
    const result = await env.AI.run("@cf/meta/llama-3.1-8b-instruct", {
      messages: [
        { role: "user", content: "What is the capital of France?" },
      ],
    });

    return new Response(JSON.stringify(result));
  },
} satisfies ExportedHandler<Env>;
```

That is enough for spans. The SDK records prompt and response content by default. To turn that off, set `genAI: { inputs: false, outputs: false }` in the [`dataCollection` option](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options.md#dataCollection).

Only `env.AI.run` is instrumented. Streaming spans end when the stream is fully read or cancelled. With `returnRawResponse` or `websocket`, response body fields are not recorded.

You can browse the full list of available models in the [Cloudflare Workers AI models directory](https://developers.cloudflare.com/ai/models/).

## [Trace Jev and Clef Evaluations](https://docs.sentry.io/platforms/javascript/guides/cloudflare/agent-tracing/workers-ai.md#trace-jev-and-clef-evaluations)

Available since: `v11.7.0`

Calls to TypeSafe's [Jev model](https://developers.cloudflare.com/ai/models/typesafe/jev/) (`typesafe/jev`) through `env.AI.run()` are traced automatically. No additional integration or setup is needed:

```typescript
export default {
  async fetch(request, env) {
    // env.AI is automatically instrumented
    const result = await env.AI.run("typesafe/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",
          },
        },
      },
    });

    return new Response(JSON.stringify(result));
  },
} satisfies ExportedHandler<Env>;
```

The SDK traces calls to Cloudflare's [Clef model](https://developers.cloudflare.com/workers-ai/models/clef/) (`@cf/cloudflare/clef`) the same way. Clef takes the same `state` and `questions` input as Jev:

```typescript
const result = await env.AI.run("@cf/cloudflare/clef", {
  model: "clef",
  state: "Checkout has been failing for every customer for the last hour.",
  questions: {
    urgent: {
      type: "noul",
      instructions: "Is this support request urgent?",
    },
  },
});
```

Each call creates a `gen_ai.decide` span named `decide <model>`, with the response model (for example, `jev-1.13.0` or `clef`), latency, and token usage. When recording is enabled, Sentry captures `state` and `questions` as input messages and `answers` as output messages, including probabilities and confidence values returned by the model. These spans have the same attributes as spans from the [TypeSafe integration](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/typesafe.md) on other runtimes.

Decision state and answers can contain sensitive data. To stop recording them, set `genAI: { inputs: false, outputs: false }` in the [`dataCollection` option](https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options.md#dataCollection).

## [Next Steps](https://docs.sentry.io/platforms/javascript/guides/cloudflare/agent-tracing/workers-ai.md#next-steps)

* Group multi-turn chats with [`setConversationId()`](https://docs.sentry.io/platforms/javascript/guides/cloudflare/agent-tracing.md#tracking-conversations)
* If you use the [Cloudflare Agents SDK](https://docs.sentry.io/platforms/javascript/guides/cloudflare/agent-tracing/agents-sdk.md), follow that guide
