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

# Vercel AI SDK

> Observe Vercel AI SDK calls and agents in Adaline.

# Vercel AI SDK

Use the Adaline Vercel AI integration to send Vercel AI SDK execution data into Adaline. You wrap the SDK functions you already call — such as `generateText`, `streamText`, `generateObject`, `streamObject` — or a Vercel AI agent, and the wrapper observes their model calls, tool calls, and steps. The package exposes two helpers:

* `wrapVercelAISDK` to wrap SDK functions
* `wrapVercelAIAgent` to wrap an agent's `generate` and `stream`

## Prerequisites

Before you start, make sure you have:

* An [Adaline account](https://app.adaline.ai/sign-up?utm_source=adaline.ai).
* A **workspace API key** — create one under **Settings → API keys**.
* Your **project ID** — copy it from **Monitor → Copy Project ID**.

See [Integrate your AI Agent](/get-started/integrate-your-ai-agent) for a full walkthrough.

Set both as environment variables before running the examples on this page:

```bash theme={null}
export ADALINE_API_KEY="your-api-key"
export ADALINE_PROJECT_ID="your-project-id"
```

## Install

```bash theme={null}
npm install @adaline/client @adaline/vercel-ai ai zod @ai-sdk/openai
```

Install the `ai` package and the model-provider package your application already uses (for example `@ai-sdk/openai`) alongside the Adaline integration package.

## Initialize Adaline

Create an Adaline client, then initialize a monitor for the target project.

```typescript theme={null}
import { Adaline } from "@adaline/client";

const adaline = new Adaline({ apiKey: process.env.ADALINE_API_KEY! });
const monitor = adaline.initMonitor({ projectId: process.env.ADALINE_PROJECT_ID! });
```

<Note>
  For production guidance — buffering, batching, retries, serverless flushing, and graceful shutdown — see [Instrument with the Adaline SDK](/instrument/with-adaline-sdks).
</Note>

## Wrap the Vercel AI SDK

Pass the SDK functions you want to observe to `wrapVercelAISDK`. It returns wrapped versions with the same signatures, so the rest of your code stays unchanged.

```typescript theme={null}
import { wrapVercelAISDK } from "@adaline/vercel-ai";
import { generateText, streamText } from "ai";
import { openai } from "@ai-sdk/openai";

const sdk = wrapVercelAISDK(
  { generateText, streamText },
  {
    monitor,
    operationName: "support-reply",
    tags: ["support"],
  },
);

const result = await sdk.generateText?.({
  model: openai("gpt-4o-mini"),
  prompt: "Say hello in one word.",
  maxTokens: 10,
  experimental_telemetry: { isEnabled: true },
});

await monitor.flush();
```

<Note>
  Set `experimental_telemetry: { isEnabled: true }` on your calls so the Vercel AI SDK emits the step and tool-call events the wrapper needs to build the full span tree.
</Note>

## Wrap a Vercel AI agent

If you use a Vercel AI agent, wrap it with `wrapVercelAIAgent`. The wrapped agent exposes the same `generate` and `stream` methods.

```typescript theme={null}
import { wrapVercelAIAgent } from "@adaline/vercel-ai";

const observedAgent = wrapVercelAIAgent(agent, {
  monitor,
  operationName: "support-agent",
  sessionId: "support-session",
  tags: ["support"],
});

const result = await observedAgent.generate?.({
  prompt: "Say hello in one word.",
  experimental_telemetry: { isEnabled: true },
});

await monitor.flush();
```

## Basic example

This example keeps the integration intentionally small: a single wrapped `generateText` call against OpenAI, with the trace flushed to Adaline at the end.

```typescript theme={null}
import { Adaline } from "@adaline/client";
import { wrapVercelAISDK } from "@adaline/vercel-ai";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

const adaline = new Adaline({ apiKey: process.env.ADALINE_API_KEY! });
const monitor = adaline.initMonitor({ projectId: process.env.ADALINE_PROJECT_ID! });

async function main() {
  const sdk = wrapVercelAISDK(
    { generateText },
    { monitor, operationName: "hello-world" },
  );

  const result = await sdk.generateText?.({
    model: openai("gpt-4o-mini"),
    prompt: "Say hello in one word.",
    maxTokens: 10,
    experimental_telemetry: { isEnabled: true },
  });

  console.log(result);

  await monitor.flush();
}

main();
```

## Use an existing parent trace or span

The wrapper accepts an existing Adaline parent context, so Vercel AI work can be attached under a trace or span you created earlier.

```typescript theme={null}
const parentTrace = monitor.logTrace({
  name: "vercel-ai-run",
  referenceId: "vercel-ai-run-1",
});

const sdk = wrapVercelAISDK(
  { generateText },
  {
    monitor,
    operationName: "support-reply",
    parentTrace,
  },
);
```

Pass either `parentTrace` or `parentSpan`, but not both.

## What the Vercel AI integration captures

The Vercel AI integration is designed to capture the execution structure of your wrapped calls, including:

* a root operation trace for each wrapped call, tagged with the operation name, model provider, and model
* model step spans with provider, model, finish reason, and prompt, completion, and total token counts
* tool call spans with the tool input, output, duration, and success or failure status
* failures, which mark the root trace and any open tool spans as failed

## Next steps

<CardGroup cols={2}>
  <Card title="Instrument with the Adaline SDK" icon="code" href="/instrument/with-adaline-sdks">
    Monitor lifecycle, buffering and batching, retries, serverless flushing, and graceful shutdown.
  </Card>

  <Card title="SDK reference" icon="braces" href="/reference/sdk/v2/overview">
    Full class and type reference for the TypeScript and Python SDKs.
  </Card>

  <Card title="All integrations" icon="layout-grid" href="/integrations/introduction">
    Browse every framework and AI-provider integration Adaline supports.
  </Card>

  <Card title="View your logs" icon="line-chart" href="https://app.adaline.ai">
    Open Adaline to see traces and spans land in your project.
  </Card>
</CardGroup>
