> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runagain.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Vercel AI SDK

> Instrument a Vercel AI SDK app with OpenTelemetry export to RunAgain.

The Vercel AI SDK emits OpenTelemetry spans when `experimental_telemetry` is
enabled. Register an OTLP exporter that points at RunAgain and every
`generateText` / `streamText` call becomes a trace.

## Install

<CodeGroup>
  ```bash npm theme={null}
  npm i runagain ai @ai-sdk/anthropic @vercel/otel
  ```

  ```bash pnpm theme={null}
  pnpm add runagain ai @ai-sdk/anthropic @vercel/otel
  ```

  ```bash yarn theme={null}
  yarn add runagain ai @ai-sdk/anthropic @vercel/otel
  ```

  ```bash bun theme={null}
  bun add runagain ai @ai-sdk/anthropic @vercel/otel
  ```
</CodeGroup>

## Configure

```bash .env.local theme={null}
RUNAGAIN_API_KEY=sk_…
RUNAGAIN_INGEST_URL=https://ingest.runagain.ai
```

## Register the exporter

```ts instrumentation.ts theme={null}
import { registerOTel } from "@vercel/otel";
import { RunAgainSpanExporter } from "runagain/otel";

export function register() {
  registerOTel({
    serviceName: "support-bot",
    traceExporter: new RunAgainSpanExporter({
      url: process.env.RUNAGAIN_INGEST_URL!,
      apiKey: process.env.RUNAGAIN_API_KEY!,
    }),
  });
}
```

## Enable telemetry on your calls

```ts app/api/chat/route.ts theme={null}
import { streamText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";

const result = streamText({
  model: anthropic("claude-opus-4-8"),
  prompt,
  // emit OpenTelemetry spans that RunAgain ingests
  experimental_telemetry: { isEnabled: true, functionId: "support-bot" },
});
```

## Run

```bash theme={null}
npm run dev   # then hit your route to produce a trace
```

<Tip>
  Deployed on Vercel? The exporter runs anywhere Node/Edge OpenTelemetry runs —
  set `RUNAGAIN_API_KEY` and `RUNAGAIN_INGEST_URL` as project environment
  variables.
</Tip>
