ai 6.0.31 → 6.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/index.js +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/internal/index.js +1 -1
  5. package/dist/internal/index.mjs +1 -1
  6. package/docs/00-introduction/index.mdx +76 -0
  7. package/docs/02-foundations/01-overview.mdx +43 -0
  8. package/docs/02-foundations/02-providers-and-models.mdx +163 -0
  9. package/docs/02-foundations/03-prompts.mdx +620 -0
  10. package/docs/02-foundations/04-tools.mdx +160 -0
  11. package/docs/02-foundations/05-streaming.mdx +62 -0
  12. package/docs/02-foundations/index.mdx +43 -0
  13. package/docs/02-getting-started/00-choosing-a-provider.mdx +110 -0
  14. package/docs/02-getting-started/01-navigating-the-library.mdx +85 -0
  15. package/docs/02-getting-started/02-nextjs-app-router.mdx +556 -0
  16. package/docs/02-getting-started/03-nextjs-pages-router.mdx +542 -0
  17. package/docs/02-getting-started/04-svelte.mdx +627 -0
  18. package/docs/02-getting-started/05-nuxt.mdx +566 -0
  19. package/docs/02-getting-started/06-nodejs.mdx +512 -0
  20. package/docs/02-getting-started/07-expo.mdx +766 -0
  21. package/docs/02-getting-started/08-tanstack-start.mdx +583 -0
  22. package/docs/02-getting-started/index.mdx +44 -0
  23. package/docs/03-agents/01-overview.mdx +96 -0
  24. package/docs/03-agents/02-building-agents.mdx +367 -0
  25. package/docs/03-agents/03-workflows.mdx +370 -0
  26. package/docs/03-agents/04-loop-control.mdx +350 -0
  27. package/docs/03-agents/05-configuring-call-options.mdx +286 -0
  28. package/docs/03-agents/index.mdx +40 -0
  29. package/docs/03-ai-sdk-core/01-overview.mdx +33 -0
  30. package/docs/03-ai-sdk-core/05-generating-text.mdx +600 -0
  31. package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +662 -0
  32. package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +1102 -0
  33. package/docs/03-ai-sdk-core/16-mcp-tools.mdx +375 -0
  34. package/docs/03-ai-sdk-core/20-prompt-engineering.mdx +144 -0
  35. package/docs/03-ai-sdk-core/25-settings.mdx +198 -0
  36. package/docs/03-ai-sdk-core/30-embeddings.mdx +247 -0
  37. package/docs/03-ai-sdk-core/31-reranking.mdx +218 -0
  38. package/docs/03-ai-sdk-core/35-image-generation.mdx +341 -0
  39. package/docs/03-ai-sdk-core/36-transcription.mdx +173 -0
  40. package/docs/03-ai-sdk-core/37-speech.mdx +167 -0
  41. package/docs/03-ai-sdk-core/40-middleware.mdx +480 -0
  42. package/docs/03-ai-sdk-core/45-provider-management.mdx +349 -0
  43. package/docs/03-ai-sdk-core/50-error-handling.mdx +149 -0
  44. package/docs/03-ai-sdk-core/55-testing.mdx +218 -0
  45. package/docs/03-ai-sdk-core/60-telemetry.mdx +313 -0
  46. package/docs/03-ai-sdk-core/65-devtools.mdx +107 -0
  47. package/docs/03-ai-sdk-core/index.mdx +88 -0
  48. package/docs/04-ai-sdk-ui/01-overview.mdx +44 -0
  49. package/docs/04-ai-sdk-ui/02-chatbot.mdx +1313 -0
  50. package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +535 -0
  51. package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +263 -0
  52. package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +682 -0
  53. package/docs/04-ai-sdk-ui/04-generative-user-interfaces.mdx +389 -0
  54. package/docs/04-ai-sdk-ui/05-completion.mdx +186 -0
  55. package/docs/04-ai-sdk-ui/08-object-generation.mdx +344 -0
  56. package/docs/04-ai-sdk-ui/20-streaming-data.mdx +397 -0
  57. package/docs/04-ai-sdk-ui/21-error-handling.mdx +190 -0
  58. package/docs/04-ai-sdk-ui/21-transport.mdx +174 -0
  59. package/docs/04-ai-sdk-ui/24-reading-ui-message-streams.mdx +104 -0
  60. package/docs/04-ai-sdk-ui/25-message-metadata.mdx +152 -0
  61. package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +477 -0
  62. package/docs/04-ai-sdk-ui/index.mdx +64 -0
  63. package/docs/05-ai-sdk-rsc/01-overview.mdx +45 -0
  64. package/docs/05-ai-sdk-rsc/02-streaming-react-components.mdx +209 -0
  65. package/docs/05-ai-sdk-rsc/03-generative-ui-state.mdx +279 -0
  66. package/docs/05-ai-sdk-rsc/03-saving-and-restoring-states.mdx +105 -0
  67. package/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx +282 -0
  68. package/docs/05-ai-sdk-rsc/05-streaming-values.mdx +158 -0
  69. package/docs/05-ai-sdk-rsc/06-loading-state.mdx +273 -0
  70. package/docs/05-ai-sdk-rsc/08-error-handling.mdx +96 -0
  71. package/docs/05-ai-sdk-rsc/09-authentication.mdx +42 -0
  72. package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +722 -0
  73. package/docs/05-ai-sdk-rsc/index.mdx +58 -0
  74. package/docs/06-advanced/01-prompt-engineering.mdx +96 -0
  75. package/docs/06-advanced/02-stopping-streams.mdx +184 -0
  76. package/docs/06-advanced/03-backpressure.mdx +173 -0
  77. package/docs/06-advanced/04-caching.mdx +169 -0
  78. package/docs/06-advanced/05-multiple-streamables.mdx +68 -0
  79. package/docs/06-advanced/06-rate-limiting.mdx +60 -0
  80. package/docs/06-advanced/07-rendering-ui-with-language-models.mdx +213 -0
  81. package/docs/06-advanced/08-model-as-router.mdx +120 -0
  82. package/docs/06-advanced/09-multistep-interfaces.mdx +115 -0
  83. package/docs/06-advanced/09-sequential-generations.mdx +55 -0
  84. package/docs/06-advanced/10-vercel-deployment-guide.mdx +117 -0
  85. package/docs/06-advanced/index.mdx +11 -0
  86. package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2142 -0
  87. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +3215 -0
  88. package/docs/07-reference/01-ai-sdk-core/03-generate-object.mdx +780 -0
  89. package/docs/07-reference/01-ai-sdk-core/04-stream-object.mdx +1140 -0
  90. package/docs/07-reference/01-ai-sdk-core/05-embed.mdx +190 -0
  91. package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +171 -0
  92. package/docs/07-reference/01-ai-sdk-core/06-rerank.mdx +309 -0
  93. package/docs/07-reference/01-ai-sdk-core/10-generate-image.mdx +227 -0
  94. package/docs/07-reference/01-ai-sdk-core/11-transcribe.mdx +138 -0
  95. package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +214 -0
  96. package/docs/07-reference/01-ai-sdk-core/15-agent.mdx +203 -0
  97. package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +449 -0
  98. package/docs/07-reference/01-ai-sdk-core/17-create-agent-ui-stream.mdx +148 -0
  99. package/docs/07-reference/01-ai-sdk-core/18-create-agent-ui-stream-response.mdx +168 -0
  100. package/docs/07-reference/01-ai-sdk-core/18-pipe-agent-ui-stream-to-response.mdx +144 -0
  101. package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +196 -0
  102. package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +175 -0
  103. package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +410 -0
  104. package/docs/07-reference/01-ai-sdk-core/24-mcp-stdio-transport.mdx +68 -0
  105. package/docs/07-reference/01-ai-sdk-core/25-json-schema.mdx +94 -0
  106. package/docs/07-reference/01-ai-sdk-core/26-zod-schema.mdx +109 -0
  107. package/docs/07-reference/01-ai-sdk-core/27-valibot-schema.mdx +55 -0
  108. package/docs/07-reference/01-ai-sdk-core/28-output.mdx +342 -0
  109. package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +415 -0
  110. package/docs/07-reference/01-ai-sdk-core/31-ui-message.mdx +246 -0
  111. package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +101 -0
  112. package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +113 -0
  113. package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +182 -0
  114. package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +121 -0
  115. package/docs/07-reference/01-ai-sdk-core/50-cosine-similarity.mdx +52 -0
  116. package/docs/07-reference/01-ai-sdk-core/60-wrap-language-model.mdx +59 -0
  117. package/docs/07-reference/01-ai-sdk-core/61-wrap-image-model.mdx +64 -0
  118. package/docs/07-reference/01-ai-sdk-core/65-language-model-v2-middleware.mdx +46 -0
  119. package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +68 -0
  120. package/docs/07-reference/01-ai-sdk-core/67-simulate-streaming-middleware.mdx +71 -0
  121. package/docs/07-reference/01-ai-sdk-core/68-default-settings-middleware.mdx +80 -0
  122. package/docs/07-reference/01-ai-sdk-core/69-add-tool-input-examples-middleware.mdx +155 -0
  123. package/docs/07-reference/01-ai-sdk-core/70-extract-json-middleware.mdx +147 -0
  124. package/docs/07-reference/01-ai-sdk-core/70-step-count-is.mdx +84 -0
  125. package/docs/07-reference/01-ai-sdk-core/71-has-tool-call.mdx +120 -0
  126. package/docs/07-reference/01-ai-sdk-core/75-simulate-readable-stream.mdx +94 -0
  127. package/docs/07-reference/01-ai-sdk-core/80-smooth-stream.mdx +145 -0
  128. package/docs/07-reference/01-ai-sdk-core/90-generate-id.mdx +43 -0
  129. package/docs/07-reference/01-ai-sdk-core/91-create-id-generator.mdx +89 -0
  130. package/docs/07-reference/01-ai-sdk-core/index.mdx +159 -0
  131. package/docs/07-reference/02-ai-sdk-ui/01-use-chat.mdx +446 -0
  132. package/docs/07-reference/02-ai-sdk-ui/02-use-completion.mdx +179 -0
  133. package/docs/07-reference/02-ai-sdk-ui/03-use-object.mdx +178 -0
  134. package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +230 -0
  135. package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +108 -0
  136. package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +151 -0
  137. package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +113 -0
  138. package/docs/07-reference/02-ai-sdk-ui/42-pipe-ui-message-stream-to-response.mdx +73 -0
  139. package/docs/07-reference/02-ai-sdk-ui/43-read-ui-message-stream.mdx +57 -0
  140. package/docs/07-reference/02-ai-sdk-ui/46-infer-ui-tools.mdx +99 -0
  141. package/docs/07-reference/02-ai-sdk-ui/47-infer-ui-tool.mdx +75 -0
  142. package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +333 -0
  143. package/docs/07-reference/02-ai-sdk-ui/index.mdx +89 -0
  144. package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +767 -0
  145. package/docs/07-reference/03-ai-sdk-rsc/02-create-ai.mdx +90 -0
  146. package/docs/07-reference/03-ai-sdk-rsc/03-create-streamable-ui.mdx +91 -0
  147. package/docs/07-reference/03-ai-sdk-rsc/04-create-streamable-value.mdx +48 -0
  148. package/docs/07-reference/03-ai-sdk-rsc/05-read-streamable-value.mdx +78 -0
  149. package/docs/07-reference/03-ai-sdk-rsc/06-get-ai-state.mdx +50 -0
  150. package/docs/07-reference/03-ai-sdk-rsc/07-get-mutable-ai-state.mdx +70 -0
  151. package/docs/07-reference/03-ai-sdk-rsc/08-use-ai-state.mdx +26 -0
  152. package/docs/07-reference/03-ai-sdk-rsc/09-use-actions.mdx +42 -0
  153. package/docs/07-reference/03-ai-sdk-rsc/10-use-ui-state.mdx +35 -0
  154. package/docs/07-reference/03-ai-sdk-rsc/11-use-streamable-value.mdx +46 -0
  155. package/docs/07-reference/03-ai-sdk-rsc/20-render.mdx +262 -0
  156. package/docs/07-reference/03-ai-sdk-rsc/index.mdx +67 -0
  157. package/docs/07-reference/04-stream-helpers/01-ai-stream.mdx +89 -0
  158. package/docs/07-reference/04-stream-helpers/02-streaming-text-response.mdx +79 -0
  159. package/docs/07-reference/04-stream-helpers/05-stream-to-response.mdx +108 -0
  160. package/docs/07-reference/04-stream-helpers/07-openai-stream.mdx +77 -0
  161. package/docs/07-reference/04-stream-helpers/08-anthropic-stream.mdx +79 -0
  162. package/docs/07-reference/04-stream-helpers/09-aws-bedrock-stream.mdx +91 -0
  163. package/docs/07-reference/04-stream-helpers/10-aws-bedrock-anthropic-stream.mdx +96 -0
  164. package/docs/07-reference/04-stream-helpers/10-aws-bedrock-messages-stream.mdx +96 -0
  165. package/docs/07-reference/04-stream-helpers/11-aws-bedrock-cohere-stream.mdx +93 -0
  166. package/docs/07-reference/04-stream-helpers/12-aws-bedrock-llama-2-stream.mdx +93 -0
  167. package/docs/07-reference/04-stream-helpers/13-cohere-stream.mdx +78 -0
  168. package/docs/07-reference/04-stream-helpers/14-google-generative-ai-stream.mdx +85 -0
  169. package/docs/07-reference/04-stream-helpers/15-hugging-face-stream.mdx +84 -0
  170. package/docs/07-reference/04-stream-helpers/16-langchain-adapter.mdx +98 -0
  171. package/docs/07-reference/04-stream-helpers/16-llamaindex-adapter.mdx +70 -0
  172. package/docs/07-reference/04-stream-helpers/17-mistral-stream.mdx +81 -0
  173. package/docs/07-reference/04-stream-helpers/18-replicate-stream.mdx +83 -0
  174. package/docs/07-reference/04-stream-helpers/19-inkeep-stream.mdx +80 -0
  175. package/docs/07-reference/04-stream-helpers/index.mdx +103 -0
  176. package/docs/07-reference/05-ai-sdk-errors/ai-api-call-error.mdx +30 -0
  177. package/docs/07-reference/05-ai-sdk-errors/ai-download-error.mdx +27 -0
  178. package/docs/07-reference/05-ai-sdk-errors/ai-empty-response-body-error.mdx +24 -0
  179. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-argument-error.mdx +26 -0
  180. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-data-content-error.mdx +25 -0
  181. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-data-content.mdx +26 -0
  182. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-message-role-error.mdx +25 -0
  183. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-prompt-error.mdx +47 -0
  184. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-response-data-error.mdx +25 -0
  185. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-tool-approval-error.mdx +25 -0
  186. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-tool-input-error.mdx +27 -0
  187. package/docs/07-reference/05-ai-sdk-errors/ai-json-parse-error.mdx +25 -0
  188. package/docs/07-reference/05-ai-sdk-errors/ai-load-api-key-error.mdx +24 -0
  189. package/docs/07-reference/05-ai-sdk-errors/ai-load-setting-error.mdx +24 -0
  190. package/docs/07-reference/05-ai-sdk-errors/ai-message-conversion-error.mdx +25 -0
  191. package/docs/07-reference/05-ai-sdk-errors/ai-no-content-generated-error.mdx +24 -0
  192. package/docs/07-reference/05-ai-sdk-errors/ai-no-image-generated-error.mdx +36 -0
  193. package/docs/07-reference/05-ai-sdk-errors/ai-no-object-generated-error.mdx +43 -0
  194. package/docs/07-reference/05-ai-sdk-errors/ai-no-speech-generated-error.mdx +25 -0
  195. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +26 -0
  196. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +28 -0
  197. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-tool-error.mdx +26 -0
  198. package/docs/07-reference/05-ai-sdk-errors/ai-no-transcript-generated-error.mdx +25 -0
  199. package/docs/07-reference/05-ai-sdk-errors/ai-retry-error.mdx +27 -0
  200. package/docs/07-reference/05-ai-sdk-errors/ai-too-many-embedding-values-for-call-error.mdx +27 -0
  201. package/docs/07-reference/05-ai-sdk-errors/ai-tool-call-not-found-for-approval-error.mdx +26 -0
  202. package/docs/07-reference/05-ai-sdk-errors/ai-tool-call-repair-error.mdx +28 -0
  203. package/docs/07-reference/05-ai-sdk-errors/ai-type-validation-error.mdx +25 -0
  204. package/docs/07-reference/05-ai-sdk-errors/ai-unsupported-functionality-error.mdx +25 -0
  205. package/docs/07-reference/05-ai-sdk-errors/index.mdx +38 -0
  206. package/docs/07-reference/index.mdx +34 -0
  207. package/docs/08-migration-guides/00-versioning.mdx +46 -0
  208. package/docs/08-migration-guides/24-migration-guide-6-0.mdx +823 -0
  209. package/docs/08-migration-guides/25-migration-guide-5-0-data.mdx +882 -0
  210. package/docs/08-migration-guides/26-migration-guide-5-0.mdx +3427 -0
  211. package/docs/08-migration-guides/27-migration-guide-4-2.mdx +99 -0
  212. package/docs/08-migration-guides/28-migration-guide-4-1.mdx +14 -0
  213. package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1157 -0
  214. package/docs/08-migration-guides/36-migration-guide-3-4.mdx +14 -0
  215. package/docs/08-migration-guides/37-migration-guide-3-3.mdx +64 -0
  216. package/docs/08-migration-guides/38-migration-guide-3-2.mdx +46 -0
  217. package/docs/08-migration-guides/39-migration-guide-3-1.mdx +168 -0
  218. package/docs/08-migration-guides/index.mdx +22 -0
  219. package/docs/09-troubleshooting/01-azure-stream-slow.mdx +33 -0
  220. package/docs/09-troubleshooting/02-client-side-function-calls-not-invoked.mdx +22 -0
  221. package/docs/09-troubleshooting/03-server-actions-in-client-components.mdx +40 -0
  222. package/docs/09-troubleshooting/04-strange-stream-output.mdx +36 -0
  223. package/docs/09-troubleshooting/05-streamable-ui-errors.mdx +16 -0
  224. package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +106 -0
  225. package/docs/09-troubleshooting/06-streaming-not-working-when-deployed.mdx +31 -0
  226. package/docs/09-troubleshooting/06-streaming-not-working-when-proxied.mdx +31 -0
  227. package/docs/09-troubleshooting/06-timeout-on-vercel.mdx +60 -0
  228. package/docs/09-troubleshooting/07-unclosed-streams.mdx +34 -0
  229. package/docs/09-troubleshooting/08-use-chat-failed-to-parse-stream.mdx +26 -0
  230. package/docs/09-troubleshooting/09-client-stream-error.mdx +25 -0
  231. package/docs/09-troubleshooting/10-use-chat-tools-no-response.mdx +32 -0
  232. package/docs/09-troubleshooting/11-use-chat-custom-request-options.mdx +149 -0
  233. package/docs/09-troubleshooting/12-typescript-performance-zod.mdx +46 -0
  234. package/docs/09-troubleshooting/12-use-chat-an-error-occurred.mdx +59 -0
  235. package/docs/09-troubleshooting/13-repeated-assistant-messages.mdx +73 -0
  236. package/docs/09-troubleshooting/14-stream-abort-handling.mdx +73 -0
  237. package/docs/09-troubleshooting/14-tool-calling-with-structured-outputs.mdx +48 -0
  238. package/docs/09-troubleshooting/15-abort-breaks-resumable-streams.mdx +55 -0
  239. package/docs/09-troubleshooting/15-stream-text-not-working.mdx +33 -0
  240. package/docs/09-troubleshooting/16-streaming-status-delay.mdx +63 -0
  241. package/docs/09-troubleshooting/17-use-chat-stale-body-data.mdx +141 -0
  242. package/docs/09-troubleshooting/18-ontoolcall-type-narrowing.mdx +66 -0
  243. package/docs/09-troubleshooting/19-unsupported-model-version.mdx +50 -0
  244. package/docs/09-troubleshooting/20-no-object-generated-content-filter.mdx +72 -0
  245. package/docs/09-troubleshooting/30-model-is-not-assignable-to-type.mdx +21 -0
  246. package/docs/09-troubleshooting/40-typescript-cannot-find-namespace-jsx.mdx +24 -0
  247. package/docs/09-troubleshooting/50-react-maximum-update-depth-exceeded.mdx +39 -0
  248. package/docs/09-troubleshooting/60-jest-cannot-find-module-ai-rsc.mdx +22 -0
  249. package/docs/09-troubleshooting/index.mdx +11 -0
  250. package/package.json +8 -4
@@ -0,0 +1,1157 @@
1
+ ---
2
+ title: Migrate AI SDK 3.4 to 4.0
3
+ description: Learn how to upgrade AI SDK 3.4 to 4.0.
4
+ ---
5
+
6
+ # Migrate AI SDK 3.4 to 4.0
7
+
8
+ <Note>
9
+ Check out the [AI SDK 4.0 release blog
10
+ post](https://vercel.com/blog/ai-sdk-4-0) for more information about the
11
+ release.
12
+ </Note>
13
+
14
+ ## Recommended Migration Process
15
+
16
+ 1. Backup your project. If you use a versioning control system, make sure all previous versions are committed.
17
+ 1. [Migrate to AI SDK 3.4](/docs/troubleshooting/migration-guide/migration-guide-3-4).
18
+ 1. Upgrade to AI SDK 4.0.
19
+ 1. Automatically migrate your code using [codemods](#codemods).
20
+ > If you don't want to use codemods, we recommend resolving all deprecation warnings before upgrading to AI SDK 4.0.
21
+ 1. Follow the breaking changes guide below.
22
+ 1. Verify your project is working as expected.
23
+ 1. Commit your changes.
24
+
25
+ ## AI SDK 4.0 package versions
26
+
27
+ You need to update the following packages to the following versions in your `package.json` file(s):
28
+
29
+ - `ai` package: `4.0.*`
30
+ - `ai-sdk@provider-utils` package: `2.0.*`
31
+ - `ai-sdk/*` packages: `1.0.*` (other `@ai-sdk` packages)
32
+
33
+ ## Codemods
34
+
35
+ The AI SDK provides Codemod transformations to help upgrade your codebase when a
36
+ feature is deprecated, removed, or otherwise changed.
37
+
38
+ Codemods are transformations that run on your codebase programmatically. They
39
+ allow you to easily apply many changes without having to manually go through
40
+ every file.
41
+
42
+ <Note>
43
+ Codemods are intended as a tool to help you with the upgrade process. They may
44
+ not cover all of the changes you need to make. You may need to make additional
45
+ changes manually.
46
+ </Note>
47
+
48
+ You can run all codemods provided as part of the 4.0 upgrade process by running
49
+ the following command from the root of your project:
50
+
51
+ ```sh
52
+ npx @ai-sdk/codemod upgrade
53
+ ```
54
+
55
+ To run only the v4 codemods:
56
+
57
+ ```sh
58
+ npx @ai-sdk/codemod v4
59
+ ```
60
+
61
+ Individual codemods can be run by specifying the name of the codemod:
62
+
63
+ ```sh
64
+ npx @ai-sdk/codemod <codemod-name> <path>
65
+ ```
66
+
67
+ For example, to run a specific v4 codemod:
68
+
69
+ ```sh
70
+ npx @ai-sdk/codemod v4/replace-baseurl src/
71
+ ```
72
+
73
+ See also the [table of codemods](#codemod-table). In addition, the latest set of
74
+ codemods can be found in the
75
+ [`@ai-sdk/codemod`](https://github.com/vercel/ai/tree/main/packages/codemod/src/codemods)
76
+ repository.
77
+
78
+ ## Provider Changes
79
+
80
+ ### Removed `baseUrl` option
81
+
82
+ The `baseUrl` option has been removed from all providers. Please use the `baseURL` option instead.
83
+
84
+ ```ts filename="AI SDK 3.4"
85
+ const perplexity = createOpenAI({
86
+ // ...
87
+ baseUrl: 'https://api.perplexity.ai/',
88
+ });
89
+ ```
90
+
91
+ ```ts filename="AI SDK 4.0"
92
+ const perplexity = createOpenAI({
93
+ // ...
94
+ baseURL: 'https://api.perplexity.ai/',
95
+ });
96
+ ```
97
+
98
+ ### Anthropic Provider
99
+
100
+ #### Removed `Anthropic` facade
101
+
102
+ The `Anthropic` facade has been removed from the Anthropic provider.
103
+ Please use the `anthropic` object or the `createAnthropic` function instead.
104
+
105
+ ```ts filename="AI SDK 3.4"
106
+ const anthropic = new Anthropic({
107
+ // ...
108
+ });
109
+ ```
110
+
111
+ ```ts filename="AI SDK 4.0"
112
+ const anthropic = createAnthropic({
113
+ // ...
114
+ });
115
+ ```
116
+
117
+ #### Removed `topK` setting
118
+
119
+ <Note type="warning">
120
+ There is no codemod available for this change. Please review and update your
121
+ code manually.
122
+ </Note>
123
+
124
+ The model specific `topK` setting has been removed from the Anthropic provider.
125
+ You can use the standard `topK` setting instead.
126
+
127
+ ```ts filename="AI SDK 3.4"
128
+ const result = await generateText({
129
+ model: anthropic('claude-3-5-sonnet-latest', {
130
+ topK: 0.5,
131
+ }),
132
+ });
133
+ ```
134
+
135
+ ```ts filename="AI SDK 4.0"
136
+ const result = await generateText({
137
+ model: anthropic('claude-3-5-sonnet-latest'),
138
+ topK: 0.5,
139
+ });
140
+ ```
141
+
142
+ ### Google Generative AI Provider
143
+
144
+ #### Removed `Google` facade
145
+
146
+ The `Google` facade has been removed from the Google Generative AI provider.
147
+ Please use the `google` object or the `createGoogleGenerativeAI` function instead.
148
+
149
+ ```ts filename="AI SDK 3.4"
150
+ const google = new Google({
151
+ // ...
152
+ });
153
+ ```
154
+
155
+ ```ts filename="AI SDK 4.0"
156
+ const google = createGoogleGenerativeAI({
157
+ // ...
158
+ });
159
+ ```
160
+
161
+ #### Removed `topK` setting
162
+
163
+ <Note type="warning">
164
+ There is no codemod available for this change. Please review and update your
165
+ code manually.
166
+ </Note>
167
+
168
+ The model-specific `topK` setting has been removed from the Google Generative AI provider.
169
+ You can use the standard `topK` setting instead.
170
+
171
+ ```ts filename="AI SDK 3.4"
172
+ const result = await generateText({
173
+ model: google('gemini-1.5-flash', {
174
+ topK: 0.5,
175
+ }),
176
+ });
177
+ ```
178
+
179
+ ```ts filename="AI SDK 4.0"
180
+ const result = await generateText({
181
+ model: google('gemini-1.5-flash'),
182
+ topK: 0.5,
183
+ });
184
+ ```
185
+
186
+ ### Google Vertex Provider
187
+
188
+ #### Removed `topK` setting
189
+
190
+ <Note type="warning">
191
+ There is no codemod available for this change. Please review and update your
192
+ code manually.
193
+ </Note>
194
+
195
+ The model-specific `topK` setting has been removed from the Google Vertex provider.
196
+ You can use the standard `topK` setting instead.
197
+
198
+ ```ts filename="AI SDK 3.4"
199
+ const result = await generateText({
200
+ model: vertex('gemini-1.5-flash', {
201
+ topK: 0.5,
202
+ }),
203
+ });
204
+ ```
205
+
206
+ ```ts filename="AI SDK 4.0"
207
+ const result = await generateText({
208
+ model: vertex('gemini-1.5-flash'),
209
+ topK: 0.5,
210
+ });
211
+ ```
212
+
213
+ ### Mistral Provider
214
+
215
+ #### Removed `Mistral` facade
216
+
217
+ The `Mistral` facade has been removed from the Mistral provider.
218
+ Please use the `mistral` object or the `createMistral` function instead.
219
+
220
+ ```ts filename="AI SDK 3.4"
221
+ const mistral = new Mistral({
222
+ // ...
223
+ });
224
+ ```
225
+
226
+ ```ts filename="AI SDK 4.0"
227
+ const mistral = createMistral({
228
+ // ...
229
+ });
230
+ ```
231
+
232
+ ### OpenAI Provider
233
+
234
+ #### Removed `OpenAI` facade
235
+
236
+ The `OpenAI` facade has been removed from the OpenAI provider.
237
+ Please use the `openai` object or the `createOpenAI` function instead.
238
+
239
+ ```ts filename="AI SDK 3.4"
240
+ const openai = new OpenAI({
241
+ // ...
242
+ });
243
+ ```
244
+
245
+ ```ts filename="AI SDK 4.0"
246
+ const openai = createOpenAI({
247
+ // ...
248
+ });
249
+ ```
250
+
251
+ ### LangChain Adapter
252
+
253
+ #### Removed `toAIStream`
254
+
255
+ The `toAIStream` function has been removed from the LangChain adapter.
256
+ Please use the `toDataStream` function instead.
257
+
258
+ ```ts filename="AI SDK 3.4"
259
+ LangChainAdapter.toAIStream(stream);
260
+ ```
261
+
262
+ ```ts filename="AI SDK 4.0"
263
+ LangChainAdapter.toDataStream(stream);
264
+ ```
265
+
266
+ ## AI SDK Core Changes
267
+
268
+ ### `streamText` returns immediately
269
+
270
+ Instead of returning a Promise, the `streamText` function now returns immediately.
271
+ It is not necessary to await the result of `streamText`.
272
+
273
+ ```ts filename="AI SDK 3.4"
274
+ const result = await streamText({
275
+ // ...
276
+ });
277
+ ```
278
+
279
+ ```ts filename="AI SDK 4.0"
280
+ const result = streamText({
281
+ // ...
282
+ });
283
+ ```
284
+
285
+ ### `streamObject` returns immediately
286
+
287
+ Instead of returning a Promise, the `streamObject` function now returns immediately.
288
+ It is not necessary to await the result of `streamObject`.
289
+
290
+ ```ts filename="AI SDK 3.4"
291
+ const result = await streamObject({
292
+ // ...
293
+ });
294
+ ```
295
+
296
+ ```ts filename="AI SDK 4.0"
297
+ const result = streamObject({
298
+ // ...
299
+ });
300
+ ```
301
+
302
+ ### Remove roundtrips
303
+
304
+ The `maxToolRoundtrips` and `maxAutomaticRoundtrips` options have been removed from the `generateText` and `streamText` functions.
305
+ Please use the `maxSteps` option instead.
306
+
307
+ The `roundtrips` property has been removed from the `GenerateTextResult` type.
308
+ Please use the `steps` property instead.
309
+
310
+ ```ts filename="AI SDK 3.4"
311
+ const { text, roundtrips } = await generateText({
312
+ maxToolRoundtrips: 1, // or maxAutomaticRoundtrips
313
+ // ...
314
+ });
315
+ ```
316
+
317
+ ```ts filename="AI SDK 4.0"
318
+ const { text, steps } = await generateText({
319
+ maxSteps: 2,
320
+ // ...
321
+ });
322
+ ```
323
+
324
+ ### Removed `nanoid` export
325
+
326
+ The `nanoid` export has been removed. Please use [`generateId`](/docs/reference/ai-sdk-core/generate-id) instead.
327
+
328
+ ```ts filename="AI SDK 3.4"
329
+ import { nanoid } from 'ai';
330
+ ```
331
+
332
+ ```ts filename="AI SDK 4.0"
333
+ import { generateId } from 'ai';
334
+ ```
335
+
336
+ ### Increased default size of generated IDs
337
+
338
+ <Note type="warning">
339
+ There is no codemod available for this change. Please review and update your
340
+ code manually.
341
+ </Note>
342
+
343
+ The [`generateId`](/docs/reference/ai-sdk-core/generate-id) function now
344
+ generates 16-character IDs. The previous default was 7 characters.
345
+
346
+ This might e.g. require updating your database schema if you limit the length of
347
+ IDs.
348
+
349
+ ```ts filename="AI SDK 4.0"
350
+ import { generateId } from 'ai';
351
+
352
+ const id = generateId(); // now 16 characters
353
+ ```
354
+
355
+ ### Removed `ExperimentalMessage` types
356
+
357
+ The following types have been removed:
358
+
359
+ - `ExperimentalMessage` (use `ModelMessage` instead)
360
+ - `ExperimentalUserMessage` (use `CoreUserMessage` instead)
361
+ - `ExperimentalAssistantMessage` (use `CoreAssistantMessage` instead)
362
+ - `ExperimentalToolMessage` (use `CoreToolMessage` instead)
363
+
364
+ ```ts filename="AI SDK 3.4"
365
+ import {
366
+ ExperimentalMessage,
367
+ ExperimentalUserMessage,
368
+ ExperimentalAssistantMessage,
369
+ ExperimentalToolMessage,
370
+ } from 'ai';
371
+ ```
372
+
373
+ ```ts filename="AI SDK 4.0"
374
+ import {
375
+ ModelMessage,
376
+ CoreUserMessage,
377
+ CoreAssistantMessage,
378
+ CoreToolMessage,
379
+ } from 'ai';
380
+ ```
381
+
382
+ ### Removed `ExperimentalTool` type
383
+
384
+ The `ExperimentalTool` type has been removed. Please use the `CoreTool` type instead.
385
+
386
+ ```ts filename="AI SDK 3.4"
387
+ import { ExperimentalTool } from 'ai';
388
+ ```
389
+
390
+ ```ts filename="AI SDK 4.0"
391
+ import { CoreTool } from 'ai';
392
+ ```
393
+
394
+ ### Removed experimental AI function exports
395
+
396
+ The following exports have been removed:
397
+
398
+ - `experimental_generateText` (use `generateText` instead)
399
+ - `experimental_streamText` (use `streamText` instead)
400
+ - `experimental_generateObject` (use `generateObject` instead)
401
+ - `experimental_streamObject` (use `streamObject` instead)
402
+
403
+ ```ts filename="AI SDK 3.4"
404
+ import {
405
+ experimental_generateText,
406
+ experimental_streamText,
407
+ experimental_generateObject,
408
+ experimental_streamObject,
409
+ } from 'ai';
410
+ ```
411
+
412
+ ```ts filename="AI SDK 4.0"
413
+ import { generateText, streamText, generateObject, streamObject } from 'ai';
414
+ ```
415
+
416
+ ### Removed AI-stream related methods from `streamText`
417
+
418
+ The following methods have been removed from the `streamText` result:
419
+
420
+ - `toAIStream`
421
+ - `pipeAIStreamToResponse`
422
+ - `toAIStreamResponse`
423
+
424
+ Use the `toDataStream`, `pipeDataStreamToResponse`, and `toDataStreamResponse` functions instead.
425
+
426
+ ```ts filename="AI SDK 3.4"
427
+ const result = await streamText({
428
+ // ...
429
+ });
430
+
431
+ result.toAIStream();
432
+ result.pipeAIStreamToResponse(response);
433
+ result.toAIStreamResponse();
434
+ ```
435
+
436
+ ```ts filename="AI SDK 4.0"
437
+ const result = streamText({
438
+ // ...
439
+ });
440
+
441
+ result.toDataStream();
442
+ result.pipeDataStreamToResponse(response);
443
+ result.toUIMessageStreamResponse();
444
+ ```
445
+
446
+ ### Renamed "formatStreamPart" to "formatDataStreamPart"
447
+
448
+ The `formatStreamPart` function has been renamed to `formatDataStreamPart`.
449
+
450
+ ```ts filename="AI SDK 3.4"
451
+ formatStreamPart('text', 'Hello, world!');
452
+ ```
453
+
454
+ ```ts filename="AI SDK 4.0"
455
+ formatDataStreamPart('text', 'Hello, world!');
456
+ ```
457
+
458
+ ### Renamed "parseStreamPart" to "parseDataStreamPart"
459
+
460
+ The `parseStreamPart` function has been renamed to `parseDataStreamPart`.
461
+
462
+ ```ts filename="AI SDK 3.4"
463
+ const part = parseStreamPart(line);
464
+ ```
465
+
466
+ ```ts filename="AI SDK 4.0"
467
+ const part = parseDataStreamPart(line);
468
+ ```
469
+
470
+ ### Renamed `TokenUsage`, `CompletionTokenUsage` and `EmbeddingTokenUsage` types
471
+
472
+ The `TokenUsage`, `CompletionTokenUsage` and `EmbeddingTokenUsage` types have
473
+ been renamed to `LanguageModelUsage` (for the first two) and
474
+ `EmbeddingModelUsage` (for the last).
475
+
476
+ ```ts filename="AI SDK 3.4"
477
+ import { TokenUsage, CompletionTokenUsage, EmbeddingTokenUsage } from 'ai';
478
+ ```
479
+
480
+ ```ts filename="AI SDK 4.0"
481
+ import { LanguageModelUsage, EmbeddingModelUsage } from 'ai';
482
+ ```
483
+
484
+ ### Removed deprecated telemetry data
485
+
486
+ <Note type="warning">
487
+ There is no codemod available for this change. Please review and update your
488
+ code manually.
489
+ </Note>
490
+
491
+ The following telemetry data values have been removed:
492
+
493
+ - `ai.finishReason` (now in `ai.response.finishReason`)
494
+ - `ai.result.object` (now in `ai.response.object`)
495
+ - `ai.result.text` (now in `ai.response.text`)
496
+ - `ai.result.toolCalls` (now in `ai.response.toolCalls`)
497
+ - `ai.stream.msToFirstChunk` (now in `ai.response.msToFirstChunk`)
498
+
499
+ This change will apply to observability providers and any scripts or automation that you use for processing telemetry data.
500
+
501
+ ### Provider Registry
502
+
503
+ #### Removed experimental_Provider, experimental_ProviderRegistry, and experimental_ModelRegistry
504
+
505
+ The `experimental_Provider` interface, `experimental_ProviderRegistry` interface, and `experimental_ModelRegistry` interface have been removed.
506
+ Please use the `Provider` interface instead.
507
+
508
+ ```ts filename="AI SDK 3.4"
509
+ import { experimental_Provider, experimental_ProviderRegistry } from 'ai';
510
+ ```
511
+
512
+ ```ts filename="AI SDK 4.0"
513
+ import { Provider } from 'ai';
514
+ ```
515
+
516
+ <Note>
517
+ The model registry is not available any more. Please [register
518
+ providers](/docs/reference/ai-sdk-core/provider-registry#setup) instead.
519
+ </Note>
520
+
521
+ #### Removed `experimental_​createModelRegistry` function
522
+
523
+ The `experimental_createModelRegistry` function has been removed.
524
+ Please use the `experimental_createProviderRegistry` function instead.
525
+
526
+ ```ts filename="AI SDK 3.4"
527
+ import { experimental_createModelRegistry } from 'ai';
528
+ ```
529
+
530
+ ```ts filename="AI SDK 4.0"
531
+ import { experimental_createProviderRegistry } from 'ai';
532
+ ```
533
+
534
+ <Note>
535
+ The model registry is not available any more. Please [register
536
+ providers](/docs/reference/ai-sdk-core/provider-registry#setup) instead.
537
+ </Note>
538
+
539
+ ### Removed `rawResponse` from results
540
+
541
+ <Note type="warning">
542
+ There is no codemod available for this change. Please review and update your
543
+ code manually.
544
+ </Note>
545
+
546
+ The `rawResponse` property has been removed from the `generateText`, `streamText`, `generateObject`, and `streamObject` results.
547
+ You can use the `response` property instead.
548
+
549
+ ```ts filename="AI SDK 3.4"
550
+ const { text, rawResponse } = await generateText({
551
+ // ...
552
+ });
553
+ ```
554
+
555
+ ```ts filename="AI SDK 4.0"
556
+ const { text, response } = await generateText({
557
+ // ...
558
+ });
559
+ ```
560
+
561
+ ### Removed `init` option from `pipeDataStreamToResponse` and `toDataStreamResponse`
562
+
563
+ <Note type="warning">
564
+ There is no codemod available for this change. Please review and update your
565
+ code manually.
566
+ </Note>
567
+
568
+ The `init` option has been removed from the `pipeDataStreamToResponse` and `toDataStreamResponse` functions.
569
+ You can set the values from `init` directly into the `options` object.
570
+
571
+ ```ts filename="AI SDK 3.4"
572
+ const result = await streamText({
573
+ // ...
574
+ });
575
+
576
+ result.toUIMessageStreamResponse(response, {
577
+ init: {
578
+ headers: {
579
+ 'X-Custom-Header': 'value',
580
+ },
581
+ },
582
+ // ...
583
+ });
584
+ ```
585
+
586
+ ```ts filename="AI SDK 4.0"
587
+ const result = streamText({
588
+ // ...
589
+ });
590
+
591
+ result.toUIMessageStreamResponse(response, {
592
+ headers: {
593
+ 'X-Custom-Header': 'value',
594
+ },
595
+ // ...
596
+ });
597
+ ```
598
+
599
+ ### Removed `responseMessages` from `generateText` and `streamText`
600
+
601
+ <Note type="warning">
602
+ There is no codemod available for this change. Please review and update your
603
+ code manually.
604
+ </Note>
605
+
606
+ The `responseMessages` property has been removed from the `generateText` and `streamText` results.
607
+ This includes the `onFinish` callback.
608
+ Please use the `response.messages` property instead.
609
+
610
+ ```ts filename="AI SDK 3.4"
611
+ const { text, responseMessages } = await generateText({
612
+ // ...
613
+ });
614
+ ```
615
+
616
+ ```ts filename="AI SDK 4.0"
617
+ const { text, response } = await generateText({
618
+ // ...
619
+ });
620
+
621
+ const responseMessages = response.messages;
622
+ ```
623
+
624
+ ### Removed `experimental_​continuationSteps` option
625
+
626
+ The `experimental_continuationSteps` option has been removed from the `generateText` function.
627
+ Please use the `experimental_continueSteps` option instead.
628
+
629
+ ```ts filename="AI SDK 3.4"
630
+ const result = await generateText({
631
+ experimental_continuationSteps: true,
632
+ // ...
633
+ });
634
+ ```
635
+
636
+ ```ts filename="AI SDK 4.0"
637
+ const result = await generateText({
638
+ experimental_continueSteps: true,
639
+ // ...
640
+ });
641
+ ```
642
+
643
+ ### Removed `LanguageModelResponseMetadataWithHeaders` type
644
+
645
+ The `LanguageModelResponseMetadataWithHeaders` type has been removed.
646
+ Please use the `LanguageModelResponseMetadata` type instead.
647
+
648
+ ```ts filename="AI SDK 3.4"
649
+ import { LanguageModelResponseMetadataWithHeaders } from 'ai';
650
+ ```
651
+
652
+ ```ts filename="AI SDK 4.0"
653
+ import { LanguageModelResponseMetadata } from 'ai';
654
+ ```
655
+
656
+ #### Changed `streamText` warnings result to Promise
657
+
658
+ <Note type="warning">
659
+ There is no codemod available for this change. Please review and update your
660
+ code manually.
661
+ </Note>
662
+
663
+ The `warnings` property of the `StreamTextResult` type is now a Promise.
664
+
665
+ ```ts filename="AI SDK 3.4"
666
+ const result = await streamText({
667
+ // ...
668
+ });
669
+
670
+ const warnings = result.warnings;
671
+ ```
672
+
673
+ ```ts filename="AI SDK 4.0"
674
+ const result = streamText({
675
+ // ...
676
+ });
677
+
678
+ const warnings = await result.warnings;
679
+ ```
680
+
681
+ #### Changed `streamObject` warnings result to Promise
682
+
683
+ <Note type="warning">
684
+ There is no codemod available for this change. Please review and update your
685
+ code manually.
686
+ </Note>
687
+
688
+ The `warnings` property of the `StreamObjectResult` type is now a Promise.
689
+
690
+ ```ts filename="AI SDK 3.4"
691
+ const result = await streamObject({
692
+ // ...
693
+ });
694
+
695
+ const warnings = result.warnings;
696
+ ```
697
+
698
+ ```ts filename="AI SDK 4.0"
699
+ const result = streamObject({
700
+ // ...
701
+ });
702
+
703
+ const warnings = await result.warnings;
704
+ ```
705
+
706
+ #### Renamed `simulateReadableStream` `values` to `chunks`
707
+
708
+ <Note type="warning">
709
+ There is no codemod available for this change. Please review and update your
710
+ code manually.
711
+ </Note>
712
+
713
+ The `simulateReadableStream` function from `ai/test` has been renamed to `chunks`.
714
+
715
+ ```ts filename="AI SDK 3.4"
716
+ import { simulateReadableStream } from 'ai/test';
717
+
718
+ const stream = simulateReadableStream({
719
+ values: [1, 2, 3],
720
+ chunkDelayInMs: 100,
721
+ });
722
+ ```
723
+
724
+ ```ts filename="AI SDK 4.0"
725
+ import { simulateReadableStream } from 'ai/test';
726
+
727
+ const stream = simulateReadableStream({
728
+ chunks: [1, 2, 3],
729
+ chunkDelayInMs: 100,
730
+ });
731
+ ```
732
+
733
+ ## AI SDK RSC Changes
734
+
735
+ <Note type="warning">
736
+ There are no codemods available for the changes in this section. Please review
737
+ and update your code manually.
738
+ </Note>
739
+
740
+ ### Removed `render` function
741
+
742
+ The AI SDK RSC 3.0 `render` function has been removed.
743
+ Please use the `streamUI` function instead or [switch to AI SDK UI](/docs/ai-sdk-rsc/migrating-to-ui).
744
+
745
+ ```ts filename="AI SDK 3.0"
746
+ import { render } from '@ai-sdk/rsc';
747
+ ```
748
+
749
+ ```ts filename="AI SDK 4.0"
750
+ import { streamUI } from '@ai-sdk/rsc';
751
+ ```
752
+
753
+ ## AI SDK UI Changes
754
+
755
+ ### Removed Svelte, Vue, and SolidJS exports
756
+
757
+ <Note type="warning">
758
+ This codemod only operates on `.ts` and `.tsx` files. If you have code in
759
+ files with other suffixes, please review and update your code manually.
760
+ </Note>
761
+
762
+ The `ai` package no longer exports Svelte, Vue, and SolidJS UI integrations.
763
+ You need to install the `@ai-sdk/svelte`, `@ai-sdk/vue`, and `@ai-sdk/solid` packages directly.
764
+
765
+ ```ts filename="AI SDK 3.4"
766
+ import { useChat } from 'ai/svelte';
767
+ ```
768
+
769
+ ```ts filename="AI SDK 4.0"
770
+ import { useChat } from '@ai-sdk/svelte';
771
+ ```
772
+
773
+ ### Removed `experimental_StreamData`
774
+
775
+ The `experimental_StreamData` export has been removed.
776
+ Please use the `StreamData` export instead.
777
+
778
+ ```ts filename="AI SDK 3.4"
779
+ import { experimental_StreamData } from 'ai';
780
+ ```
781
+
782
+ ```ts filename="AI SDK 4.0"
783
+ import { StreamData } from 'ai';
784
+ ```
785
+
786
+ ### `useChat` hook
787
+
788
+ <Note type="warning">
789
+ There are no codemods available for the changes in this section. Please review
790
+ and update your code manually.
791
+ </Note>
792
+
793
+ #### Removed `streamMode` setting
794
+
795
+ The `streamMode` options has been removed from the `useChat` hook.
796
+ Please use the `streamProtocol` parameter instead.
797
+
798
+ ```ts filename="AI SDK 3.4"
799
+ const { messages } = useChat({
800
+ streamMode: 'text',
801
+ // ...
802
+ });
803
+ ```
804
+
805
+ ```ts filename="AI SDK 4.0"
806
+ const { messages } = useChat({
807
+ streamProtocol: 'text',
808
+ // ...
809
+ });
810
+ ```
811
+
812
+ #### Replaced roundtrip setting with `maxSteps`
813
+
814
+ The following options have been removed from the `useChat` hook:
815
+
816
+ - `experimental_maxAutomaticRoundtrips`
817
+ - `maxAutomaticRoundtrips`
818
+ - `maxToolRoundtrips`
819
+
820
+ Please use the [`maxSteps`](/docs/ai-sdk-core/tools-and-tool-calling#multi-step-calls) option instead.
821
+ The value of `maxSteps` is equal to roundtrips + 1.
822
+
823
+ ```ts filename="AI SDK 3.4"
824
+ const { messages } = useChat({
825
+ experimental_maxAutomaticRoundtrips: 2,
826
+ // or maxAutomaticRoundtrips
827
+ // or maxToolRoundtrips
828
+ // ...
829
+ });
830
+ ```
831
+
832
+ ```ts filename="AI SDK 4.0"
833
+ const { messages } = useChat({
834
+ maxSteps: 3, // 2 roundtrips + 1
835
+ // ...
836
+ });
837
+ ```
838
+
839
+ #### Removed `options` setting
840
+
841
+ The `options` parameter in the `useChat` hook has been removed.
842
+ Please use the `headers` and `body` parameters instead.
843
+
844
+ ```ts filename="AI SDK 3.4"
845
+ const { messages } = useChat({
846
+ options: {
847
+ headers: {
848
+ 'X-Custom-Header': 'value',
849
+ },
850
+ },
851
+ // ...
852
+ });
853
+ ```
854
+
855
+ ```ts filename="AI SDK 4.0"
856
+ const { messages } = useChat({
857
+ headers: {
858
+ 'X-Custom-Header': 'value',
859
+ },
860
+ // ...
861
+ });
862
+ ```
863
+
864
+ #### Removed `experimental_addToolResult` method
865
+
866
+ The `experimental_addToolResult` method has been removed from the `useChat` hook.
867
+ Please use the `addToolResult` method instead.
868
+
869
+ ```ts filename="AI SDK 3.4"
870
+ const { messages, experimental_addToolResult } = useChat({
871
+ // ...
872
+ });
873
+ ```
874
+
875
+ ```ts filename="AI SDK 4.0"
876
+ const { messages, addToolResult } = useChat({
877
+ // ...
878
+ });
879
+ ```
880
+
881
+ #### Changed default value of `keepLastMessageOnError` to true and deprecated the option
882
+
883
+ The `keepLastMessageOnError` option has been changed to default to `true`.
884
+ The option will be removed in the next major release.
885
+
886
+ ```ts filename="AI SDK 3.4"
887
+ const { messages } = useChat({
888
+ keepLastMessageOnError: true,
889
+ // ...
890
+ });
891
+ ```
892
+
893
+ ```ts filename="AI SDK 4.0"
894
+ const { messages } = useChat({
895
+ // ...
896
+ });
897
+ ```
898
+
899
+ ### `useCompletion` hook
900
+
901
+ <Note type="warning">
902
+ There are no codemods available for the changes in this section. Please review
903
+ and update your code manually.
904
+ </Note>
905
+
906
+ #### Removed `streamMode` setting
907
+
908
+ The `streamMode` options has been removed from the `useCompletion` hook.
909
+ Please use the `streamProtocol` parameter instead.
910
+
911
+ ```ts filename="AI SDK 3.4"
912
+ const { text } = useCompletion({
913
+ streamMode: 'text',
914
+ // ...
915
+ });
916
+ ```
917
+
918
+ ```ts filename="AI SDK 4.0"
919
+ const { text } = useCompletion({
920
+ streamProtocol: 'text',
921
+ // ...
922
+ });
923
+ ```
924
+
925
+ ### `useAssistant` hook
926
+
927
+ #### Removed `experimental_useAssistant` export
928
+
929
+ The `experimental_useAssistant` export has been removed from the `useAssistant` hook.
930
+ Please use the `useAssistant` hook directly instead.
931
+
932
+ ```ts filename="AI SDK 3.4"
933
+ import { experimental_useAssistant } from '@ai-sdk/react';
934
+ ```
935
+
936
+ ```ts filename="AI SDK 4.0"
937
+ import { useAssistant } from '@ai-sdk/react';
938
+ ```
939
+
940
+ #### Removed `threadId` and `messageId` from `AssistantResponse`
941
+
942
+ <Note type="warning">
943
+ There is no codemod available for this change. Please review and update your
944
+ code manually.
945
+ </Note>
946
+
947
+ The `threadId` and `messageId` parameters have been removed from the `AssistantResponse` function.
948
+ Please use the `threadId` and `messageId` variables from the outer scope instead.
949
+
950
+ ```ts filename="AI SDK 3.4"
951
+ return AssistantResponse(
952
+ { threadId: myThreadId, messageId: myMessageId },
953
+ async ({ forwardStream, sendDataMessage, threadId, messageId }) => {
954
+ // use threadId and messageId here
955
+ },
956
+ );
957
+ ```
958
+
959
+ ```ts filename="AI SDK 4.0"
960
+ return AssistantResponse(
961
+ { threadId: myThreadId, messageId: myMessageId },
962
+ async ({ forwardStream, sendDataMessage }) => {
963
+ // use myThreadId and myMessageId here
964
+ },
965
+ );
966
+ ```
967
+
968
+ #### Removed `experimental_​AssistantResponse` export
969
+
970
+ <Note type="warning">
971
+ There is no codemod available for this change. Please review and update your
972
+ code manually.
973
+ </Note>
974
+
975
+ The `experimental_AssistantResponse` export has been removed.
976
+ Please use the `AssistantResponse` function directly instead.
977
+
978
+ ```ts filename="AI SDK 3.4"
979
+ import { experimental_AssistantResponse } from 'ai';
980
+ ```
981
+
982
+ ```ts filename="AI SDK 4.0"
983
+ import { AssistantResponse } from 'ai';
984
+ ```
985
+
986
+ ### `experimental_useObject` hook
987
+
988
+ <Note type="warning">
989
+ There are no codemods available for the changes in this section. Please review
990
+ and update your code manually.
991
+ </Note>
992
+
993
+ The `setInput` helper has been removed from the `experimental_useObject` hook.
994
+ Please use the `submit` helper instead.
995
+
996
+ ```ts filename="AI SDK 3.4"
997
+ const { object, setInput } = useObject({
998
+ // ...
999
+ });
1000
+ ```
1001
+
1002
+ ```ts filename="AI SDK 4.0"
1003
+ const { object, submit } = useObject({
1004
+ // ...
1005
+ });
1006
+ ```
1007
+
1008
+ ## AI SDK Errors
1009
+
1010
+ ### Removed `isXXXError` static methods
1011
+
1012
+ The `isXXXError` static methods have been removed from AI SDK errors.
1013
+ Please use the `isInstance` method of the corresponding error class instead.
1014
+
1015
+ ```ts filename="AI SDK 3.4"
1016
+ import { APICallError } from 'ai';
1017
+
1018
+ APICallError.isAPICallError(error);
1019
+ ```
1020
+
1021
+ ```ts filename="AI SDK 4.0"
1022
+ import { APICallError } from 'ai';
1023
+
1024
+ APICallError.isInstance(error);
1025
+ ```
1026
+
1027
+ ### Removed `toJSON` method
1028
+
1029
+ <Note type="warning">
1030
+ There is no codemod available for this change. Please review and update your
1031
+ code manually.
1032
+ </Note>
1033
+
1034
+ The `toJSON` method has been removed from AI SDK errors.
1035
+
1036
+ ## AI SDK 2.x Legacy Changes
1037
+
1038
+ <Note type="warning">
1039
+ There are no codemods available for the changes in this section. Please review
1040
+ and update your code manually.
1041
+ </Note>
1042
+
1043
+ ### Removed 2.x legacy providers
1044
+
1045
+ Legacy providers from AI SDK 2.x have been removed. Please use the new [AI SDK provider architecture](/docs/foundations/providers-and-models) instead.
1046
+
1047
+ #### Removed 2.x legacy function and tool calling
1048
+
1049
+ The legacy `function_call` and `tools` options have been removed from `useChat` and `Message`.
1050
+ The `name` property from the `Message` type has been removed.
1051
+ Please use the [AI SDK Core tool calling](/docs/ai-sdk-core/tools-and-tool-calling) instead.
1052
+
1053
+ ### Removed 2.x prompt helpers
1054
+
1055
+ Prompt helpers for constructing message prompts are no longer needed with the AI SDK provider architecture and have been removed.
1056
+
1057
+ ### Removed 2.x `AIStream`
1058
+
1059
+ The `AIStream` function and related exports have been removed.
1060
+ Please use the [`streamText`](/docs/reference/ai-sdk-core/stream-text) function and its `toDataStream()` method instead.
1061
+
1062
+ ### Removed 2.x `StreamingTextResponse`
1063
+
1064
+ The `StreamingTextResponse` function has been removed.
1065
+ Please use the [`streamText`](/docs/reference/ai-sdk-core/stream-text) function and its `toDataStreamResponse()` method instead.
1066
+
1067
+ ### Removed 2.x `streamToResponse`
1068
+
1069
+ The `streamToResponse` function has been removed.
1070
+ Please use the [`streamText`](/docs/reference/ai-sdk-core/stream-text) function and its `pipeDataStreamToResponse()` method instead.
1071
+
1072
+ ### Removed 2.x RSC `Tokens` streaming
1073
+
1074
+ The legacy `Tokens` RSC streaming from 2.x has been removed.
1075
+ `Tokens` were implemented prior to AI SDK RSC and are no longer needed.
1076
+
1077
+ ## Codemod Table
1078
+
1079
+ The following table lists codemod availability for the AI SDK 4.0 upgrade
1080
+ process. Note the codemod `upgrade` command will run all of them for you. This
1081
+ list is provided to give visibility into which migrations have some automation.
1082
+ It can also be helpful to find the codemod names if you'd like to run a subset
1083
+ of codemods. For more, see the [Codemods](#codemods) section.
1084
+
1085
+ | Change | Codemod |
1086
+ | --------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
1087
+ | **Provider Changes** | |
1088
+ | Removed baseUrl option | `v4/replace-baseurl` |
1089
+ | **Anthropic Provider** | |
1090
+ | Removed Anthropic facade | `v4/remove-anthropic-facade` |
1091
+ | Removed topK setting | _N/A_ |
1092
+ | **Google Generative AI Provider** | |
1093
+ | Removed Google facade | `v4/remove-google-facade` |
1094
+ | Removed topK setting | _N/A_ |
1095
+ | **Google Vertex Provider** | |
1096
+ | Removed topK setting | _N/A_ |
1097
+ | **Mistral Provider** | |
1098
+ | Removed Mistral facade | `v4/remove-mistral-facade` |
1099
+ | **OpenAI Provider** | |
1100
+ | Removed OpenAI facade | `v4/remove-openai-facade` |
1101
+ | **LangChain Adapter** | |
1102
+ | Removed toAIStream | `v4/replace-langchain-toaistream` |
1103
+ | **AI SDK Core Changes** | |
1104
+ | streamText returns immediately | `v4/remove-await-streamtext` |
1105
+ | streamObject returns immediately | `v4/remove-await-streamobject` |
1106
+ | Remove roundtrips | `v4/replace-roundtrips-with-maxsteps` |
1107
+ | Removed nanoid export | `v4/replace-nanoid` |
1108
+ | Increased default size of generated IDs | _N/A_ |
1109
+ | Removed ExperimentalMessage types | `v4/remove-experimental-message-types` |
1110
+ | Removed ExperimentalTool type | `v4/remove-experimental-tool` |
1111
+ | Removed experimental AI function exports | `v4/remove-experimental-ai-fn-exports` |
1112
+ | Removed AI-stream related methods from streamText | `v4/remove-ai-stream-methods-from-stream-text-result` |
1113
+ | Renamed "formatStreamPart" to "formatDataStreamPart" | `v4/rename-format-stream-part` |
1114
+ | Renamed "parseStreamPart" to "parseDataStreamPart" | `v4/rename-parse-stream-part` |
1115
+ | Renamed TokenUsage, CompletionTokenUsage and EmbeddingTokenUsage types | `v4/replace-token-usage-types` |
1116
+ | Removed deprecated telemetry data | _N/A_ |
1117
+ | **Provider Registry** | |
1118
+ | &rarr; Removed experimental_Provider, experimental_ProviderRegistry, and experimental_ModelRegistry | `v4/remove-deprecated-provider-registry-exports` |
1119
+ | &rarr; Removed experimental_createModelRegistry function | _N/A_ |
1120
+ | Removed rawResponse from results | _N/A_ |
1121
+ | Removed init option from pipeDataStreamToResponse and toDataStreamResponse | _N/A_ |
1122
+ | Removed responseMessages from generateText and streamText | _N/A_ |
1123
+ | Removed experimental_continuationSteps option | `v4/replace-continuation-steps` |
1124
+ | Removed LanguageModelResponseMetadataWithHeaders type | `v4/remove-metadata-with-headers` |
1125
+ | Changed streamText warnings result to Promise | _N/A_ |
1126
+ | Changed streamObject warnings result to Promise | _N/A_ |
1127
+ | Renamed simulateReadableStream values to chunks | _N/A_ |
1128
+ | **AI SDK RSC Changes** | |
1129
+ | Removed render function | _N/A_ |
1130
+ | **AI SDK UI Changes** | |
1131
+ | Removed Svelte, Vue, and SolidJS exports | `v4/rewrite-framework-imports` |
1132
+ | Removed experimental_StreamData | `v4/remove-experimental-streamdata` |
1133
+ | **useChat hook** | |
1134
+ | Removed streamMode setting | _N/A_ |
1135
+ | Replaced roundtrip setting with maxSteps | `v4/replace-roundtrips-with-maxsteps` |
1136
+ | Removed options setting | _N/A_ |
1137
+ | Removed experimental_addToolResult method | _N/A_ |
1138
+ | Changed default value of keepLastMessageOnError to true and deprecated the option | _N/A_ |
1139
+ | **useCompletion hook** | |
1140
+ | Removed streamMode setting | _N/A_ |
1141
+ | **useAssistant hook** | |
1142
+ | Removed experimental_useAssistant export | `v4/remove-experimental-useassistant` |
1143
+ | Removed threadId and messageId from AssistantResponse | _N/A_ |
1144
+ | Removed experimental_AssistantResponse export | _N/A_ |
1145
+ | **experimental_useObject hook** | |
1146
+ | Removed setInput helper | _N/A_ |
1147
+ | **AI SDK Errors** | |
1148
+ | Removed isXXXError static methods | `v4/remove-isxxxerror` |
1149
+ | Removed toJSON method | _N/A_ |
1150
+ | **AI SDK 2.x Legacy Changes** | |
1151
+ | Removed 2.x legacy providers | _N/A_ |
1152
+ | Removed 2.x legacy function and tool calling | _N/A_ |
1153
+ | Removed 2.x prompt helpers | _N/A_ |
1154
+ | Removed 2.x AIStream | _N/A_ |
1155
+ | Removed 2.x StreamingTextResponse | _N/A_ |
1156
+ | Removed 2.x streamToResponse | _N/A_ |
1157
+ | Removed 2.x RSC Tokens streaming | _N/A_ |