Skip to main content

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

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.
  • 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 for a full walkthrough. Set both as environment variables before running the examples on this page:
export ADALINE_API_KEY="your-api-key"
export ADALINE_PROJECT_ID="your-project-id"

Install

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.
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! });
For production guidance — buffering, batching, retries, serverless flushing, and graceful shutdown — see Instrument with the Adaline SDK.

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.
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();
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.

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

Instrument with the Adaline SDK

Monitor lifecycle, buffering and batching, retries, serverless flushing, and graceful shutdown.

SDK reference

Full class and type reference for the TypeScript and Python SDKs.

All integrations

Browse every framework and AI-provider integration Adaline supports.

View your logs

Open Adaline to see traces and spans land in your project.