migrate-ai-sdk-v6-to-v7
Original:🇺🇸 English
Translated
Migrate applications from AI SDK 6.x to AI SDK 7.0. Use when upgrading Vercel AI SDK packages, fixing v7 migration errors, or when the user mentions AI SDK v6, v7, upgrade, migration, breaking changes, system to instructions, fullStream, telemetry, tool context, or finalStep.
16installs
Sourcevercel/ai
Added on
NPX Install
npx skill4agent add vercel/ai migrate-ai-sdk-v6-to-v7Tags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →AI SDK 6 to 7 Migration
Use from the AI SDK repo as the source of truth. This skill is the working checklist; read the guide for exact examples or when behavior is unclear.
content/docs/08-migration-guides/23-migration-guide-7-0.mdxMigration Workflow
- Ensure the user has a clean backup or committed baseline before editing.
- Inspect and lockfiles to identify installed
package.json,ai, provider, UI, MCP, and telemetry packages.@ai-sdk/* - Upgrade AI SDK packages to latest versions, and add only if the project uses OpenTelemetry spans.
@ai-sdk/otel - Update runtime and module assumptions: Node.js must be , and AI SDK packages are ESM-only. Replace
>=22imports with ESM imports and addrequire()or use"type": "module"where needed..mjs - Search for the v6 patterns below, migrate only the code that exists, then run typecheck and targeted tests.
Prefer behavior-preserving changes. When v7 changes semantics, decide whether the app wants the new all-steps behavior or the previous final-step-only behavior.
Core API Changes
- ->
experimental_customProvider.customProvider - ->
experimental_generateImage;generateImage->Experimental_GenerateImageResult.GenerateImageResult - ->
experimental_transcribe;transcribe->Experimental_TranscriptionResult.TranscriptionResult - ->
experimental_generateSpeech;generateSpeech->Experimental_SpeechResult.SpeechResult - option/result ->
experimental_outputoption/result.output - ->
CallSettings;LanguageModelCallOptions & Omit<RequestOptions, 'timeout'>->prepareCallSettings.prepareLanguageModelCallOptions - ->
stepCountIs.isStepCount
Prompts and Steps
- Rename top-level to
systemforinstructions,generateText,streamText,generateObject, andstreamObject.streamUI - Move messages from
{ role: 'system' }orpromptinto top-levelmessages. Only useinstructionsfor trusted persisted messages.allowSystemInMessages: true - Rename to
experimental_prepareStep.prepareStep - In , rename returned
prepareSteptosystem.instructions - In , use
experimental_repairToolCallinstead of{ instructions }.{ system } - Audit behavior: returned
prepareStepandinstructionsnow carry forward into later steps. If code depended on one-step-only overrides, rebuild frommessages,initialInstructions, andinitialMessagesexplicitly.responseMessages
Lifecycle Callbacks
- ->
experimental_onStart.onStart - ->
experimental_onStepStart.onStepStart - ->
onFinish.onEnd - ->
onStepFinish.onStepEnd - For ,
embed, andembedMany,rerank->experimental_onFinish.onEnd - Callback event fields use instead of
instructions.system
Usage, Telemetry, and Include Options
- ->
usage.cachedInputTokens.usage.inputTokenDetails.cacheReadTokens - ->
usage.reasoningTokens.usage.outputTokenDetails.reasoningTokens - OpenTelemetry moved out of ; install
aiand call@ai-sdk/otelat app startup.registerTelemetry(new OpenTelemetry(...)) - Telemetry is enabled by default once an integration is registered. Remove redundant ; use
isEnabled: trueto opt out per call.isEnabled: false - Move into the
experimental_telemetry.tracerconstructor.OpenTelemetry - ->
experimental_telemetry.telemetry - Telemetry integration callbacks: ->
onRerankFinish,onRerankEnd->onEmbedFinish. Update tracing-channel subscribers for the same event type names.onEmbedEnd - ->
experimental_include.include - ->
includeRawChunks.include.rawChunks - Request and response bodies are excluded by default. If code reads or
request.body, opt in withresponse.bodyand, forinclude.requestBody,generateText.include.responseBody
Streaming, Messages, and Tools
- ->
StreamTextResult.fullStream.stream streamTextnow receives all stream parts, including lifecycle, boundary, finish, abort, and error parts. Guard byonChunkbefore assuming text/tool/raw content.chunk.type- is no longer accumulated across previous steps. Use
step.response.messagesfor the full response message history, or flattenresult.responseMessages.result.steps - Tool execution callbacks: ->
experimental_onToolCallStart,onToolExecutionStart->experimental_onToolCallFinish.onToolExecutionEnd - Tool callback ->
experimental_context.context - Split shared runtime data from tool-specific data: use top-level for orchestration state, declare per-tool
runtimeContext, and pass per-tool values throughcontextSchema.toolsContext - Move from
needsApproval/tool()into per-call or agentdynamicTool().toolApproval - ->
experimental_activeTools.activeTools - ->
ToolCallOptions.ToolExecutionOptions - ->
isToolOrDynamicToolUIPart.isToolUIPart
Content Parts and Reasoning
- Tool result is removed; use
{ type: 'media' }.{ type: 'file-data' } - Migrate
toModelOutput,image-*,file-*, andfile-idvariants to canonicalimage-file-id.{ type: 'file', mediaType, data: { type: 'data' | 'url' | 'reference', ... } } - User message is deprecated; use
{ type: 'image', image, mediaType? }.{ type: 'file', mediaType: 'image' | 'image/*', data } - Add support for the new content type in exhaustive switches, renderers, serializers, and validators.
reasoning-file - When adopting top-level , remove overlapping provider-specific reasoning settings from
reasoningunless provider-specific settings intentionally take precedence.providerOptions
Multi-Step Result Shape
- now includes all steps;
result.usageis deprecated. Useresult.totalUsagefor final-step-only usage.result.finalStep.usage - Top-level ,
content,toolCalls,staticToolCalls,dynamicToolCalls,toolResults,staticToolResults,dynamicToolResults,files, andsourcesnow include all steps. Usewarningsfor previous final-step-only behavior.finalStep - Top-level ,
reasoning,reasoningText,request, andresponseare deprecated for final-step data. UseproviderMetadata; forresult.finalStep.*, awaitstreamText.result.finalStep - Apply the same result-shape rules to events.
onEnd
Stream Response Helpers
The result helper methods are deprecated. Replace result methods with top-level stateless helpers:
streamText- ->
result.toUIMessageStream(...).toUIMessageStream({ stream: result.stream, ... }) - ->
result.toUIMessageStreamResponse(...)plustoUIMessageStream(...).createUIMessageStreamResponse({ stream }) - ->
result.pipeUIMessageStreamToResponse(response, ...)plustoUIMessageStream(...).pipeUIMessageStreamToResponse({ response, stream }) - ->
result.toTextStreamResponse()plustoTextStream({ stream: result.stream }).createTextStreamResponse({ stream }) - ->
result.pipeTextStreamToResponse(response)plustoTextStream({ stream: result.stream }).pipeTextStreamToResponse({ response, stream })
Package-Specific Checks
- MCP: now defaults to
MCPTransportConfig.redirect. Only set'error'for trusted MCP servers that rely on redirects.redirect: 'follow' - Vue:
@ai-sdk/vueclass is deprecated. PreferChat, including getter/ref init for reactive chat inputs.useChat - Anthropic and :
@ai-sdk/google-vertex/anthropicwas removed. UseproviderMetadata.anthropic.cacheCreationInputTokens; raw Anthropic usage remains atusage.inputTokenDetails.cacheWriteTokens.finalStep.providerMetadata?.anthropic?.usage - Google: rename types, classes, and functions to
GoogleGenerativeAI*, e.g.Google*->createGoogleGenerativeAI. ThecreateGoogleentry point is unchanged.google
Validation
Run the project typecheck after edits, then the smallest relevant test suite. Also smoke-test streaming, chat UI, tool execution, telemetry, and multi-step flows if the migration touched them. If type errors remain, search the migration guide for the exact removed or renamed symbol before inventing a workaround.