$npx -y skills add vercel/ai --skill migrate-ai-sdk-v6-to-v7Migrate 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.
| 1 | ## AI SDK 6 to 7 Migration |
| 2 | |
| 3 | Use `content/docs/08-migration-guides/23-migration-guide-7-0.mdx` 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. |
| 4 | |
| 5 | ## Migration Workflow |
| 6 | |
| 7 | 1. Ensure the user has a clean backup or committed baseline before editing. |
| 8 | 2. Inspect `package.json` and lockfiles to identify installed `ai`, `@ai-sdk/*`, provider, UI, MCP, and telemetry packages. |
| 9 | 3. Upgrade AI SDK packages to latest versions, and add `@ai-sdk/otel` only if the project uses OpenTelemetry spans. |
| 10 | 4. Update runtime and module assumptions: Node.js must be `>=22`, and AI SDK packages are ESM-only. Replace `require()` imports with ESM imports and add `"type": "module"` or use `.mjs` where needed. |
| 11 | 5. Search for the v6 patterns below, migrate only the code that exists, then run typecheck and targeted tests. |
| 12 | |
| 13 | 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. |
| 14 | |
| 15 | ## Core API Changes |
| 16 | |
| 17 | - `experimental_customProvider` -> `customProvider`. |
| 18 | - `experimental_generateImage` -> `generateImage`; `Experimental_GenerateImageResult` -> `GenerateImageResult`. |
| 19 | - `experimental_transcribe` -> `transcribe`; `Experimental_TranscriptionResult` -> `TranscriptionResult`. |
| 20 | - `experimental_generateSpeech` -> `generateSpeech`; `Experimental_SpeechResult` -> `SpeechResult`. |
| 21 | - `experimental_output` option/result -> `output` option/result. |
| 22 | - `CallSettings` -> `LanguageModelCallOptions & Omit<RequestOptions, 'timeout'>`; `prepareCallSettings` -> `prepareLanguageModelCallOptions`. |
| 23 | - `stepCountIs` -> `isStepCount`. |
| 24 | |
| 25 | ## Prompts and Steps |
| 26 | |
| 27 | - Rename top-level `system` to `instructions` for `generateText`, `streamText`, `generateObject`, `streamObject`, and `streamUI`. |
| 28 | - Move `{ role: 'system' }` messages from `prompt` or `messages` into top-level `instructions`. Only use `allowSystemInMessages: true` for trusted persisted messages. |
| 29 | - Rename `experimental_prepareStep` to `prepareStep`. |
| 30 | - In `prepareStep`, rename returned `system` to `instructions`. |
| 31 | - In `experimental_repairToolCall`, use `{ instructions }` instead of `{ system }`. |
| 32 | - Audit `prepareStep` behavior: returned `instructions` and `messages` now carry forward into later steps. If code depended on one-step-only overrides, rebuild from `initialInstructions`, `initialMessages`, and `responseMessages` explicitly. |
| 33 | |
| 34 | ## Lifecycle Callbacks |
| 35 | |
| 36 | - `experimental_onStart` -> `onStart`. |
| 37 | - `experimental_onStepStart` -> `onStepStart`. |
| 38 | - `onFinish` -> `onEnd`. |
| 39 | - `onStepFinish` -> `onStepEnd`. |
| 40 | - For `embed`, `embedMany`, and `rerank`, `experimental_onFinish` -> `onEnd`. |
| 41 | - Callback event fields use `instructions` instead of `system`. |
| 42 | |
| 43 | ## Usage, Telemetry, and Include Options |
| 44 | |
| 45 | - `usage.cachedInputTokens` -> `usage.inputTokenDetails.cacheReadTokens`. |
| 46 | - `usage.reasoningTokens` -> `usage.outputTokenDetails.reasoningTokens`. |
| 47 | - OpenTelemetry moved out of `ai`; install `@ai-sdk/otel` and call `registerTelemetry(new OpenTelemetry(...))` at app startup. |
| 48 | - Telemetry is enabled by default once an integration is registered. Remove redundant `isEnabled: true`; use `isEnabled: false` to opt out per call. |
| 49 | - Move `experimental_telemetry.tracer` into the `OpenTelemetry` constructor. |
| 50 | - `experimental_telemetry` -> `telemetry`. |
| 51 | - Telemetry integration callbacks: `onRerankFinish` -> `onRerankEnd`, `onEmbedFinish` -> `onEmbedEnd`. Update tracing-channel subscribers for the same event type names. |
| 52 | - `experimental_include` -> `include`. |
| 53 | - `includeRawChunks` -> `include.rawChunks`. |
| 54 | - Request and response bodies are excluded by default. If code reads `request.body` or `response.body`, opt in with `include.requestBody` and, for `generateText`, `include.responseBody`. |
| 55 | |
| 56 | ## Streaming, Messages, and Tools |
| 57 | |
| 58 | - `StreamTextResult.fullStream` -> `stream`. |
| 59 | - `streamText` `onChunk` now receives all stream parts, including lifecycle, boundary, finish, abort, and error parts. Guard by `chunk.type` before assuming text/tool/raw content. |
| 60 | - `step.response.messages` is no longer accumulated across previous steps. Use `result.responseMessages` for the full response message history, or flatten `result.steps`. |
| 61 | - Tool execution callbacks: `experimental_onToolCallStart` -> `onToolExecutionStart`, `experimental_onToolCallFinish` -> `onToolExecutionEnd`. |
| 62 | - Tool callback `experimental_context` -> `context`. |
| 63 | - Split shared runtime data from tool-specific data: use top-level `runtimeContext` for orchestration state, declare per-tool `contextSchema`, and pass per-tool values through `toolsContext`. |
| 64 | - Move `needsApproval` from `tool()` / `dynamicTool()` into per- |