Vercel AI SDK v7 Development Guide

SkillFiles & storage

Vercel AI SDK v7 development and migration. Use when building or upgrading AI SDK 7 apps, especially ToolLoopAgent, WorkflowAgent, HarnessAgent, Claude Code/Codex/Pi harnesses, runtimeContext, toolsContext, toolApproval, telemetry, reasoning, file or skill uploads, realtime, video generation, or v6-to-v7 breaking changes. For AI SDK v6 code use ai-sdk-6; for version discovery and general doc lookup use ai-sdk.

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the Vercel AI SDK v7 Development Guide skill

What this skill tells your AI

The instructions your AI receives, as published by laguagu/claude-code-nextjs-skills in skills/ai-sdk-7/SKILL.md and read by ahel’s review.

Use this skill for AI SDK 7-specific implementation, migrations, and agent architecture. For AI SDK 6 projects, use ai-sdk-6. For unknown versions, use ai-sdk first to inspect node_modules/ai/package.json and local docs.

First Checks

  1. Inspect package.json, lockfiles, and node_modules/ai/package.json.
  2. Confirm the installed ai major version is 7 before applying this guide.
  3. Search local docs first: node_modules/ai/docs/ and node_modules/ai/src/.
  4. In monorepos, check app/package workspaces such as apps/*/node_modules/ai/ and packages/*/node_modules/ai/.
  5. If local docs are missing or ambiguous, verify against ai-sdk.dev or the Vercel AI repository docs source before coding.

AI SDK 7 requires Node.js >=22 and AI SDK packages are ESM-only. Convert require() imports to import syntax before chasing downstream type errors.

Install

Use the project's package manager and install only packages needed by the task:

bun add ai @ai-sdk/react
bun add @ai-sdk/openai # or the provider already used by the project

For durable agents, add @ai-sdk/workflow and workflow. For harness agents, add @ai-sdk/harness, one harness adapter, and a sandbox provider.

Core v7 Patterns

TaskPrefer in AI SDK 7
Text generationgenerateText / streamText
System prompttop-level instructions, not system
Structured outputoutput: Output.object(...) on text functions
Loop limitstopWhen: isStepCount(n)
Shared server stateruntimeContext
Per-tool state/secretstool contextSchema + toolsContext
Sensitive toolstoolApproval on generateText, streamText, or ToolLoopAgent
Durable long-running agentsWorkflowAgent from @ai-sdk/workflow
Running Claude Code/Codex/PiHarnessAgent from @ai-sdk/harness/agent
ObservabilityregisterTelemetry(new OpenTelemetry())
Stalled callstimeout number or object

In examples, __MODEL__ is a placeholder: resolve a current model via the project's provider package (e.g. anthropic('...')) or a gateway model string, following the model-ID guidance in the ai-sdk skill. Never hard-code a model ID from memory.

import { generateText, isStepCount, Output } from 'ai';
import { z } from 'zod';

const result = await generateText({
  model: __MODEL__,
  instructions: 'Answer concisely.',
  prompt: 'Classify this support ticket.',
  reasoning: 'high',
  stopWhen: isStepCount(3),
  timeout: { totalMs: 60_000, stepMs: 15_000 },
  output: Output.object({
    schema: z.object({
      priority: z.enum(['low', 'medium', 'high']),
      summary: z.string(),
    }),
  }),
});

console.log(result.output);

Documentation Routing

Read only the reference needed for the current task:

Gotchas

  • Do not rely on memory for AI SDK APIs. Verify against local docs/source or official docs before writing code.
  • Harness packages are experimental. Keep adapter/package details easy to change and re-check docs before adding long-lived abstractions.
  • result.usage now aggregates all steps. Use result.finalStep.usage for previous final-step-only behavior.
  • For streamText, await result.finalStep before reading final-step-only metadata.
  • Harness sessions own conversation history. Persist resume state from detach() or stop() instead of replaying the entire UI message history.
  • WorkflowAgent is stream-first and durable; use ToolLoopAgent for simple in-memory agents.
  • toolApproval applies to AI SDK-executed tools. Provider-executed tools and harness built-ins have separate approval/permission behavior.
  • Always fetch or verify current model IDs from the project's config or provider docs before hard-coding a model string.

Signals

GitHub stars
62
Forks
18
Last commit
Sep 2026
Advanced
Catalog kind
skill
Gateway key
ai-sdk-7
Source
github.com/laguagu/claude-code-nextjs-skills