Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/cloudflare/agents/llms.txt

Use this file to discover all available pages before exploring further.

This guide covers the changes needed when upgrading from AI SDK v5 to v6 with @cloudflare/ai-chat.

Installation

npm install ai@latest @ai-sdk/react@latest @ai-sdk/openai@latest

Breaking changes

1. convertToModelMessages() is now async

Add await to all calls:
const result = streamText({
  messages: convertToModelMessages(this.messages),
  model: openai("gpt-4o")
});

2. CoreMessage removed

Replace CoreMessage with ModelMessage and convertToCoreMessages() with convertToModelMessages():
import { convertToCoreMessages, type CoreMessage } from "ai";
v6 introduces needsApproval and the onToolCall callback. For most apps, define tools on the server with tool() from "ai" for full Zod type safety:
// Client defined tools with AITool type
useAgentChat({
  agent,
  tools: clientTools,
  experimental_automaticToolResolution: true,
  toolsRequiringConfirmation: ["askConfirmation"]
});
Dynamic client tools (SDK/platform pattern): If you are building an SDK or platform where tools are defined dynamically by the embedding application at runtime, the tools option on useAgentChat and createToolsFromClientSchemas() on the server are still fully supported:
// Server: accept whatever tools the client sends
const tools = {
  ...createToolsFromClientSchemas(options.clientTools),
  ...serverTools
};

4. generateObject mode option removed

Remove mode: "json" or similar from generateObject calls.

5. isToolUIPart and getToolName now include dynamic tools

In v6, these check both static and dynamic tool parts. For the old behavior, use isStaticToolUIPart and getStaticToolName. Most users do not need to change anything.

Deprecated APIs

DeprecatedReplacement
toolsRequiringConfirmationneedsApproval on server tools
experimental_automaticToolResolutiononToolCall callback
addToolResult()addToolOutput() or addToolApprovalResponse()
Not deprecated: AITool, createToolsFromClientSchemas(), extractClientToolSchemas(), and the tools option on useAgentChat are supported for SDK/platform use cases where tools are defined dynamically at runtime.

Migration checklist

1

Update packages

  • ai to ^6.0.0
  • @ai-sdk/react to ^3.0.0
  • @ai-sdk/openai (and other providers) to ^3.0.0
2

Add await to convertToModelMessages()

Add await to all convertToModelMessages() calls
3

Replace CoreMessage

Replace CoreMessage with ModelMessage
4

Replace convertToCoreMessages()

Replace convertToCoreMessages() with convertToModelMessages()
5

Remove mode from generateObject

Remove mode from generateObject calls
6

Move tool definitions to server

Move static tool definitions to server using tool() (recommended for most apps)
7

Use onToolCall callback

Use onToolCall in useAgentChat for client-side tool execution
8

Replace toolsRequiringConfirmation

Replace toolsRequiringConfirmation with needsApproval
9

Replace addToolResult()

Replace addToolResult() with addToolOutput() or addToolApprovalResponse()

Further reading

Build docs developers (and LLMs) love