Vercel's AI SDK 7 Lets Developers Swap Claude Code and Codex Like Models

Vercel's AI SDK 7 beta lands with HarnessAgent for Claude Code and Codex, typed tool context, durable WorkflowAgent, and a new video generation API

·
·
·
Vercel's AI SDK 7 Lets Developers Swap Claude Code and Codex Like Models
Read6 min
TypeNews
  • HarnessAgent lands in v7 beta: a single API to run Claude Code, Codex, and Pi agent runtimes — swap harnesses like you swap models. Docs
  • WorkflowAgent adds durability: agents that persist state, resume from checkpoints, and support human-in-the-loop approvals across process boundaries.
  • Typed tool context: contextSchema replaces manual type casts in tool callbacks, giving end-to-end TypeScript safety for runtime context like API keys.
  • Video generation added: the unified Core API now covers video generation alongside text, image, speech, and transcription.
  • Breaking changes: OpenTelemetry moved to a separate @ai-sdk/otel package; MCP redirect default changed to 'error' for SSRF protection.
  • Available now as beta: install with pnpm install ai@latest; free and open source, migration guide at ai-sdk.dev.

AI SDK 7 is now in public beta. Vercel's TypeScript toolkit for building AI-powered apps has been the de facto standard for shipping AI features on Next.js for a while now, but version 7 is a meaningful architectural shift, not just a feature bump. The headline addition is HarnessAgent, a new abstraction that lets you plug full coding agent runtimes like Claude Code, Codex, and Pi directly into your app through a unified API.

The problem with agent runtimes today

Provider lock-in, ad-hoc streaming protocols, hand-rolled tool-call shapes, and custom agent loops are maintenance liabilities that the AI SDK has been quietly solving over its lifetime. But until now, that story only covered language model calls. Coding agent runtimes like Claude Code and Codex are a different beast entirely: they own their own session state, sandboxed workspaces, permission flows, and built-in tooling. Integrating them meant writing bespoke glue code for each one.

AI SDK 7 fixes that with a new layer of abstraction sitting above the model provider layer.

HarnessAgent: one API for all coding runtimes

AI SDK 7 introduces HarnessAgent, a single API for running established agent harnesses, including Claude Code, Codex, and Pi. AI SDK has always let you switch models without rewriting your agent. Now you can switch the harness the same way.

A harness (the term used throughout the docs) is a complete agent runtime, not just a model. It owns capabilities that are larger than a model call: workspace access, built-in coding tools, native session state, compaction, permission flows, and runtime-specific configuration. All AI SDK agent harnesses operate in a sandbox, keeping the host environment safe.

The key design decision is that harnesses are decoupled from the model provider abstraction. Providers expose models to AI SDK Core functions such as generateText and streamText. Harnesses expose agent runtimes to HarnessAgent. But they share the same stream and response primitives, so your existing UI code just works.

Here's what swapping harnesses looks like in practice:

javascript
import { HarnessAgent } from 'ai';
import { claudeCode } from '@ai-sdk/harness-claude-code';
// swap claudeCode for codex or pi , same API
const agent = new HarnessAgent({ harness: claudeCode() });
const session = await agent.createSession();
const result = await agent.generate({
  session,
  prompt: 'Inspect the repo and summarize the test setup.',
});
console.log(result.text);
await session.destroy();

HarnessAgent lets you provide your own instructions, skills, AI SDK tools, permission settings, sandbox setup hooks, and adapter-specific configuration while preserving the runtime behavior that makes each harness powerful. Initial harness adapters for this experimental release include Claude Code, Codex, and Pi, with more coming soon.

WorkflowAgent: agents that survive crashes

The other major agent addition is WorkflowAgent, which solves a real production pain point. A standard ToolLoopAgent runs entirely in memory , if the process crashes, all progress is lost. For production agents that make multiple tool calls, this creates problems: long-running agent loops need to persist state across process boundaries, and if a step fails, you want to retry from the last checkpoint, not restart from scratch.

The WorkflowAgent from @ai-sdk/workflow is designed for building durable, resumable agents that run inside Vercel Workflows. It provides the same agent loop as the ToolLoopAgent, but adds automatic state persistence, tool schema serialization, and built-in tool approval flows that survive workflow step boundaries.

What else is new

Beyond the agent layer, version 7 ships a range of improvements across the SDK's surface area:

  • Video generation: The unified API now covers text generation, speech, transcription, image generation, video generation, tool calling, error handling, and DevTools , video being the notable new addition.
  • Typed tool context: In v6, passing runtime context (like API keys) to tools required manual type casting. Tool callbacks are now generic over a CONTEXT type. You declare the runtime context a tool expects with contextSchema, and the execute callback receives a typed experimental_context automatically. No more as { apiKey: string } casts.
  • Realtime API support: The docs now include a dedicated Realtime section under AI SDK Core, enabling low-latency voice and event-driven use cases.
  • OpenTelemetry decoupled: OpenTelemetry span collection is no longer built into the ai package. To continue receiving traces, you must install the new @ai-sdk/otel package and register the OpenTelemetryIntegration globally. This is a breaking change but makes telemetry opt-in and keeps the core bundle leaner.
  • MCP security hardening: The redirect option on MCPTransportConfig now defaults to 'error' instead of 'follow', preventing server-side request forgery (SSRF) attacks where an MCP server could redirect requests to unintended hosts.

The typed context upgrade in detail

The contextSchema change is small but eliminates a common source of runtime bugs. Here's the before and after:

php
// AI SDK 6 , manual cast, no type safety
const weather = tool({
  inputSchema: z.object({ location: z.string() }),
  execute: async ({ location }, { experimental_context }) => {
    const { weatherApiKey } = experimental_context as { weatherApiKey: string };
    return getWeather(location, weatherApiKey);
  },
});
// AI SDK 7 , schema-driven, fully typed
const weather = tool({
  inputSchema: z.object({ location: z.string() }),
  contextSchema: z.object({ weatherApiKey: z.string() }),
  execute: async ({ location }, { experimental_context: { weatherApiKey } }) => {
    return getWeather(location, weatherApiKey);
  },
});

What this means for the broader ecosystem

Downstream agentic frameworks like Mastra, Inngest's agent kit, and even LangChain's TypeScript port integrate against the AI SDK rather than competing with it. That makes this release consequential beyond Vercel's own users. If HarnessAgent becomes the standard interface for coding agent runtimes, it changes how the whole TypeScript AI ecosystem thinks about portability.

The implicit assumption being updated here is that agent runtimes are inherently tied to their provider's SDK. Claude Code has its own SDK, Codex has its own SDK. AI SDK 7 proposes a different model: harnesses are just another swappable layer, and your application code shouldn't care which one is running underneath.

It's worth noting that harness packages are explicitly marked as experimental in the docs, with breaking changes expected between releases. The core changes , typed context, decoupled telemetry, MCP security defaults , are stable and migration-ready today.

How to get started

AI SDK 7 is available now as a beta. You can install it with:

nginx
pnpm install ai@latest @ai-sdk/react@latest @ai-sdk/openai@latest @ai-sdk/otel@latest

The official migration guide covers every breaking change from v6. The SDK itself is free and open source. Costs are purely what you pay to your model providers , the SDK adds no markup. The harness documentation is the best place to start if HarnessAgent is what caught your eye.

Trending
  • No trending articles

Comments

avatar

Next Reads