---
title: "Vercel AI SDK"
description: "Set up Blyp tracing for Vercel AI SDK calls with blypModel() or blypMiddleware()."
canonical_url: "https://www.blyp.dev/docs/ai/vercel-ai-sdk"
markdown_url: "https://www.blyp.dev/docs/ai/vercel-ai-sdk.md"
last_updated: "2018-10-20"
x_farming_labs_generated_preamble: true
agent:
  task: "Instrument Vercel AI SDK generateText or streamText calls with Blyp."
  outcome: "Model calls emit ai_trace records, including first-chunk latency for streams."
  appliesTo:
    package:
      - "@blyp/core"
      - "ai"
  prerequisites:
    - "A Vercel AI SDK model can complete a request without Blyp."
  files:
    - "blyp.config.ts"
    - "src/lib/ai.ts"
  commands:
    - "pnpm add @blyp/core ai"
  sideEffects:
    - "Configured capture can persist prompts"
    - "outputs"
    - "or tool payloads."
  verification:
    - "Run generateText or consume a complete stream and confirm one ai_trace record."
  rollback:
    - "Pass the original model directly to the AI SDK call."
  failureModes:
    - symptom: "A streaming trace never completes."
      resolution: "Consume or cancel the stream so the tracing middleware can finalize the record."
---

# Vercel AI SDK
URL: /docs/ai/vercel-ai-sdk
LLM index: /llms.txt
Description: Set up Blyp tracing for Vercel AI SDK calls with blypModel() or blypMiddleware().
Related: /docs/ai/tracing, /docs/ai/privacy-and-capture, /docs/ai/openai-sdk

<!-- farming-labs:agent-contract:start -->
## Agent Contract

Task: Instrument Vercel AI SDK generateText or streamText calls with Blyp.
Outcome: Model calls emit ai_trace records, including first-chunk latency for streams.

### Applies To

- Package: `@blyp/core`, `ai`

### Prerequisites

- A Vercel AI SDK model can complete a request without Blyp.

### Files

- `blyp.config.ts`
- `src/lib/ai.ts`

### Commands

- `pnpm add @blyp/core ai`

### Side Effects

- Configured capture can persist prompts
- outputs
- or tool payloads.

### Verification

- Run generateText or consume a complete stream and confirm one ai_trace record.

### Rollback

- Pass the original model directly to the AI SDK call.

### Failure Modes

- A streaming trace never completes. — Recovery: Consume or cancel the stream so the tracing middleware can finalize the record.
<!-- farming-labs:agent-contract:end -->

# Vercel AI SDK

Use `blypModel()` for the shortest setup or `blypMiddleware()` when composing middleware. Execute
the wrapped model and fully consume streams before checking output. Success is one `ai_trace` with
usage and timing; incomplete stream consumption is the common cause of unfinished traces.

Use `@blyp/core/ai/vercel` when your app already uses the Vercel AI SDK and you want Blyp to trace `generateText()` or `streamText()` calls.

## Install

Install the Vercel AI SDK in the app that uses the traced model:

```bash
bun add ai
```

## `blypModel()`

Use `blypModel()` when you want the shortest path for tracing a model instance:

```ts
import { anthropic } from "@ai-sdk/anthropic";
import { streamText } from "ai";
import { blypModel } from "@blyp/core/ai/vercel";

const model = blypModel(anthropic("claude-sonnet-4-5"), {
  operation: "support_chat",
});

const result = streamText({
  model,
  prompt: "Write a refund reply for this customer",
});
```

## `blypMiddleware()`

Use `blypMiddleware()` when the model is already being composed with Vercel AI SDK middleware:

```ts
import { anthropic } from "@ai-sdk/anthropic";
import { wrapLanguageModel } from "ai";
import { blypMiddleware } from "@blyp/core/ai/vercel";

const model = wrapLanguageModel({
  model: anthropic("claude-sonnet-4-5"),
  middleware: blypMiddleware({
    operation: "support_chat",
    metadata: {
      team: "support",
    },
  }),
});
```

## What gets traced

`@blyp/core/ai/vercel` covers:

- `generateText()`
- `streamText()`

It emits one normalized `ai_trace` record per traced call with provider, model, operation, usage, finish reason, timing, first-chunk latency for streams, and best-effort tool-call events.

## Shared controls

Use the shared privacy controls from [AI Privacy & Capture](/docs/ai/privacy-and-capture) when you want to opt into prompt or output capture.

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
Docs-scoped sitemap: [/docs/sitemap.md](/docs/sitemap.md).
Well-known sitemap: [/.well-known/sitemap.md](/.well-known/sitemap.md).
