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,722 @@
1
+ ---
2
+ title: Migrating from RSC to UI
3
+ description: Learn how to migrate from AI SDK RSC to AI SDK UI.
4
+ ---
5
+
6
+ # Migrating from RSC to UI
7
+
8
+ This guide helps you migrate from AI SDK RSC to AI SDK UI.
9
+
10
+ ## Background
11
+
12
+ The AI SDK has two packages that help you build the frontend for your applications – [AI SDK UI](/docs/ai-sdk-ui) and [AI SDK RSC](/docs/ai-sdk-rsc).
13
+
14
+ We introduced support for using [React Server Components](https://react.dev/reference/rsc/server-components) (RSC) within the AI SDK to simplify building generative user interfaces for frameworks that support RSC.
15
+
16
+ However, given we're pushing the boundaries of this technology, AI SDK RSC currently faces significant limitations that make it unsuitable for stable production use.
17
+
18
+ - It is not possible to abort a stream using server actions. This will be improved in future releases of React and Next.js [(1122)](https://github.com/vercel/ai/issues/1122).
19
+ - When using `createStreamableUI` and `streamUI`, components remount on `.done()`, causing them to flicker [(2939)](https://github.com/vercel/ai/issues/2939).
20
+ - Many suspense boundaries can lead to crashes [(2843)](https://github.com/vercel/ai/issues/2843).
21
+ - Using `createStreamableUI` can lead to quadratic data transfer. You can avoid this using createStreamableValue instead, and rendering the component client-side.
22
+ - Closed RSC streams cause update issues [(3007)](https://github.com/vercel/ai/issues/3007).
23
+
24
+ Due to these limitations, AI SDK RSC is marked as experimental, and we do not recommend using it for stable production environments.
25
+
26
+ As a result, we strongly recommend migrating to AI SDK UI, which has undergone extensive development to provide a more stable and production grade experience.
27
+
28
+ In building [v0](https://v0.dev), we have invested considerable time exploring how to create the best chat experience on the web. AI SDK UI ships with many of these best practices and commonly used patterns like [language model middleware](/docs/ai-sdk-core/middleware), [multi-step tool calls](/docs/ai-sdk-core/tools-and-tool-calling#multi-step-calls), [attachments](/docs/ai-sdk-ui/chatbot#attachments-experimental), [telemetry](/docs/ai-sdk-core/telemetry), [provider registry](/docs/ai-sdk-core/provider-management#provider-registry), and many more. These features have been considerately designed into a neat abstraction that you can use to reliably integrate AI into your applications.
29
+
30
+ ## Streaming Chat Completions
31
+
32
+ ### Basic Setup
33
+
34
+ The `streamUI` function executes as part of a server action as illustrated below.
35
+
36
+ #### Before: Handle generation and rendering in a single server action
37
+
38
+ ```tsx filename="@/app/actions.tsx"
39
+ import { openai } from '@ai-sdk/openai';
40
+ import { getMutableAIState, streamUI } from '@ai-sdk/rsc';
41
+
42
+ export async function sendMessage(message: string) {
43
+ 'use server';
44
+
45
+ const messages = getMutableAIState('messages');
46
+
47
+ messages.update([...messages.get(), { role: 'user', content: message }]);
48
+
49
+ const { value: stream } = await streamUI({
50
+ model: openai('gpt-4o'),
51
+ system: 'you are a friendly assistant!',
52
+ messages: messages.get(),
53
+ text: async function* ({ content, done }) {
54
+ // process text
55
+ },
56
+ tools: {
57
+ // tool definitions
58
+ },
59
+ });
60
+
61
+ return stream;
62
+ }
63
+ ```
64
+
65
+ #### Before: Call server action and update UI state
66
+
67
+ The chat interface calls the server action. The response is then saved using the `useUIState` hook.
68
+
69
+ ```tsx filename="@/app/page.tsx"
70
+ 'use client';
71
+
72
+ import { useState, ReactNode } from 'react';
73
+ import { useActions, useUIState } from '@ai-sdk/rsc';
74
+
75
+ export default function Page() {
76
+ const { sendMessage } = useActions();
77
+ const [input, setInput] = useState('');
78
+ const [messages, setMessages] = useUIState();
79
+
80
+ return (
81
+ <div>
82
+ {messages.map(message => message)}
83
+
84
+ <form
85
+ onSubmit={async () => {
86
+ const response: ReactNode = await sendMessage(input);
87
+ setMessages(msgs => [...msgs, response]);
88
+ }}
89
+ >
90
+ <input type="text" />
91
+ <button type="submit">Submit</button>
92
+ </form>
93
+ </div>
94
+ );
95
+ }
96
+ ```
97
+
98
+ The `streamUI` function combines generating text and rendering the user interface. To migrate to AI SDK UI, you need to **separate these concerns** – streaming generations with `streamText` and rendering the UI with `useChat`.
99
+
100
+ #### After: Replace server action with route handler
101
+
102
+ The `streamText` function executes as part of a route handler and streams the response to the client. The `useChat` hook on the client decodes this stream and renders the response within the chat interface.
103
+
104
+ ```ts filename="@/app/api/chat/route.ts"
105
+ import { streamText } from 'ai';
106
+ import { openai } from '@ai-sdk/openai';
107
+
108
+ export async function POST(request) {
109
+ const { messages } = await request.json();
110
+
111
+ const result = streamText({
112
+ model: __MODEL__,
113
+ system: 'you are a friendly assistant!',
114
+ messages,
115
+ tools: {
116
+ // tool definitions
117
+ },
118
+ });
119
+
120
+ return result.toUIMessageStreamResponse();
121
+ }
122
+ ```
123
+
124
+ #### After: Update client to use chat hook
125
+
126
+ ```tsx filename="@/app/page.tsx"
127
+ 'use client';
128
+
129
+ import { useChat } from '@ai-sdk/react';
130
+
131
+ export default function Page() {
132
+ const { messages, input, setInput, handleSubmit } = useChat();
133
+
134
+ return (
135
+ <div>
136
+ {messages.map(message => (
137
+ <div key={message.id}>
138
+ <div>{message.role}</div>
139
+ <div>{message.content}</div>
140
+ </div>
141
+ ))}
142
+
143
+ <form onSubmit={handleSubmit}>
144
+ <input
145
+ type="text"
146
+ value={input}
147
+ onChange={event => {
148
+ setInput(event.target.value);
149
+ }}
150
+ />
151
+ <button type="submit">Send</button>
152
+ </form>
153
+ </div>
154
+ );
155
+ }
156
+ ```
157
+
158
+ ### Parallel Tool Calls
159
+
160
+ In AI SDK RSC, `streamUI` does not support parallel tool calls. You will have to use a combination of `streamText`, `createStreamableUI` and `createStreamableValue`.
161
+
162
+ With AI SDK UI, `useChat` comes with built-in support for parallel tool calls. You can define multiple tools in the `streamText` and have them called them in parallel. The `useChat` hook will then handle the parallel tool calls for you automatically.
163
+
164
+ ### Multi-Step Tool Calls
165
+
166
+ In AI SDK RSC, `streamUI` does not support multi-step tool calls. You will have to use a combination of `streamText`, `createStreamableUI` and `createStreamableValue`.
167
+
168
+ With AI SDK UI, `useChat` comes with built-in support for multi-step tool calls. You can set `maxSteps` in the `streamText` function to define the number of steps the language model can make in a single call. The `useChat` hook will then handle the multi-step tool calls for you automatically.
169
+
170
+ ### Generative User Interfaces
171
+
172
+ The `streamUI` function uses `tools` as a way to execute functions based on user input and renders React components based on the function output to go beyond text in the chat interface.
173
+
174
+ #### Before: Render components within the server action and stream to client
175
+
176
+ ```tsx filename="@/app/actions.tsx"
177
+ import { z } from 'zod';
178
+ import { streamUI } from '@ai-sdk/rsc';
179
+ import { openai } from '@ai-sdk/openai';
180
+ import { getWeather } from '@/utils/queries';
181
+ import { Weather } from '@/components/weather';
182
+
183
+ const { value: stream } = await streamUI({
184
+ model: openai('gpt-4o'),
185
+ system: 'you are a friendly assistant!',
186
+ messages,
187
+ text: async function* ({ content, done }) {
188
+ // process text
189
+ },
190
+ tools: {
191
+ displayWeather: {
192
+ description: 'Display the weather for a location',
193
+ inputSchema: z.object({
194
+ latitude: z.number(),
195
+ longitude: z.number(),
196
+ }),
197
+ generate: async function* ({ latitude, longitude }) {
198
+ yield <div>Loading weather...</div>;
199
+
200
+ const { value, unit } = await getWeather({ latitude, longitude });
201
+
202
+ return <Weather value={value} unit={unit} />;
203
+ },
204
+ },
205
+ },
206
+ });
207
+ ```
208
+
209
+ As mentioned earlier, `streamUI` generates text and renders the React component in a single server action call.
210
+
211
+ #### After: Replace with route handler and stream props data to client
212
+
213
+ The `streamText` function streams the props data as response to the client, while `useChat` decode the stream as `toolInvocations` and renders the chat interface.
214
+
215
+ ```ts filename="@/app/api/chat/route.ts"
216
+ import { z } from 'zod';
217
+ import { openai } from '@ai-sdk/openai';
218
+ import { getWeather } from '@/utils/queries';
219
+ import { streamText } from 'ai';
220
+
221
+ export async function POST(request) {
222
+ const { messages } = await request.json();
223
+
224
+ const result = streamText({
225
+ model: __MODEL__,
226
+ system: 'you are a friendly assistant!',
227
+ messages,
228
+ tools: {
229
+ displayWeather: {
230
+ description: 'Display the weather for a location',
231
+ parameters: z.object({
232
+ latitude: z.number(),
233
+ longitude: z.number(),
234
+ }),
235
+ execute: async function ({ latitude, longitude }) {
236
+ const props = await getWeather({ latitude, longitude });
237
+ return props;
238
+ },
239
+ },
240
+ },
241
+ });
242
+
243
+ return result.toUIMessageStreamResponse();
244
+ }
245
+ ```
246
+
247
+ #### After: Update client to use chat hook and render components using tool invocations
248
+
249
+ ```tsx filename="@/app/page.tsx"
250
+ 'use client';
251
+
252
+ import { useChat } from '@ai-sdk/react';
253
+ import { Weather } from '@/components/weather';
254
+
255
+ export default function Page() {
256
+ const { messages, input, setInput, handleSubmit } = useChat();
257
+
258
+ return (
259
+ <div>
260
+ {messages.map(message => (
261
+ <div key={message.id}>
262
+ <div>{message.role}</div>
263
+ <div>{message.content}</div>
264
+
265
+ <div>
266
+ {message.toolInvocations.map(toolInvocation => {
267
+ const { toolName, toolCallId, state } = toolInvocation;
268
+
269
+ if (state === 'result') {
270
+ const { result } = toolInvocation;
271
+
272
+ return (
273
+ <div key={toolCallId}>
274
+ {toolName === 'displayWeather' ? (
275
+ <Weather weatherAtLocation={result} />
276
+ ) : null}
277
+ </div>
278
+ );
279
+ } else {
280
+ return (
281
+ <div key={toolCallId}>
282
+ {toolName === 'displayWeather' ? (
283
+ <div>Loading weather...</div>
284
+ ) : null}
285
+ </div>
286
+ );
287
+ }
288
+ })}
289
+ </div>
290
+ </div>
291
+ ))}
292
+
293
+ <form onSubmit={handleSubmit}>
294
+ <input
295
+ type="text"
296
+ value={input}
297
+ onChange={event => {
298
+ setInput(event.target.value);
299
+ }}
300
+ />
301
+ <button type="submit">Send</button>
302
+ </form>
303
+ </div>
304
+ );
305
+ }
306
+ ```
307
+
308
+ ### Handling Client Interactions
309
+
310
+ With AI SDK RSC, components streamed to the client can trigger subsequent generations by calling the relevant server action using the `useActions` hooks. This is possible as long as the component is a descendant of the `<AI/>` context provider.
311
+
312
+ #### Before: Use actions hook to send messages
313
+
314
+ ```tsx filename="@/app/components/list-flights.tsx"
315
+ 'use client';
316
+
317
+ import { useActions, useUIState } from '@ai-sdk/rsc';
318
+
319
+ export function ListFlights({ flights }) {
320
+ const { sendMessage } = useActions();
321
+ const [_, setMessages] = useUIState();
322
+
323
+ return (
324
+ <div>
325
+ {flights.map(flight => (
326
+ <div
327
+ key={flight.id}
328
+ onClick={async () => {
329
+ const response = await sendMessage(
330
+ `I would like to choose flight ${flight.id}!`,
331
+ );
332
+
333
+ setMessages(msgs => [...msgs, response]);
334
+ }}
335
+ >
336
+ {flight.name}
337
+ </div>
338
+ ))}
339
+ </div>
340
+ );
341
+ }
342
+ ```
343
+
344
+ #### After: Use another chat hook with same ID from the component
345
+
346
+ After switching to AI SDK UI, these messages are synced by initializing the `useChat` hook in the component with the same `id` as the parent component.
347
+
348
+ ```tsx filename="@/app/components/list-flights.tsx"
349
+ 'use client';
350
+
351
+ import { useChat } from '@ai-sdk/react';
352
+
353
+ export function ListFlights({ chatId, flights }) {
354
+ const { append } = useChat({
355
+ id: chatId,
356
+ body: { id: chatId },
357
+ maxSteps: 5,
358
+ });
359
+
360
+ return (
361
+ <div>
362
+ {flights.map(flight => (
363
+ <div
364
+ key={flight.id}
365
+ onClick={async () => {
366
+ await append({
367
+ role: 'user',
368
+ content: `I would like to choose flight ${flight.id}!`,
369
+ });
370
+ }}
371
+ >
372
+ {flight.name}
373
+ </div>
374
+ ))}
375
+ </div>
376
+ );
377
+ }
378
+ ```
379
+
380
+ ### Loading Indicators
381
+
382
+ In AI SDK RSC, you can use the `initial` parameter of `streamUI` to define the component to display while the generation is in progress.
383
+
384
+ #### Before: Use `loading` to show loading indicator
385
+
386
+ ```tsx filename="@/app/actions.tsx"
387
+ import { openai } from '@ai-sdk/openai';
388
+ import { streamUI } from '@ai-sdk/rsc';
389
+
390
+ const { value: stream } = await streamUI({
391
+ model: openai('gpt-4o'),
392
+ system: 'you are a friendly assistant!',
393
+ messages,
394
+ initial: <div>Loading...</div>,
395
+ text: async function* ({ content, done }) {
396
+ // process text
397
+ },
398
+ tools: {
399
+ // tool definitions
400
+ },
401
+ });
402
+
403
+ return stream;
404
+ ```
405
+
406
+ With AI SDK UI, you can use the tool invocation state to show a loading indicator while the tool is executing.
407
+
408
+ #### After: Use tool invocation state to show loading indicator
409
+
410
+ ```tsx filename="@/app/components/message.tsx"
411
+ 'use client';
412
+
413
+ export function Message({ role, content, toolInvocations }) {
414
+ return (
415
+ <div>
416
+ <div>{role}</div>
417
+ <div>{content}</div>
418
+
419
+ {toolInvocations && (
420
+ <div>
421
+ {toolInvocations.map(toolInvocation => {
422
+ const { toolName, toolCallId, state } = toolInvocation;
423
+
424
+ if (state === 'result') {
425
+ const { result } = toolInvocation;
426
+
427
+ return (
428
+ <div key={toolCallId}>
429
+ {toolName === 'getWeather' ? (
430
+ <Weather weatherAtLocation={result} />
431
+ ) : null}
432
+ </div>
433
+ );
434
+ } else {
435
+ return (
436
+ <div key={toolCallId}>
437
+ {toolName === 'getWeather' ? (
438
+ <Weather isLoading={true} />
439
+ ) : (
440
+ <div>Loading...</div>
441
+ )}
442
+ </div>
443
+ );
444
+ }
445
+ })}
446
+ </div>
447
+ )}
448
+ </div>
449
+ );
450
+ }
451
+ ```
452
+
453
+ ### Saving Chats
454
+
455
+ Before implementing `streamUI` as a server action, you should create an `<AI/>` provider and wrap your application at the root layout to sync the AI and UI states. During initialization, you typically use the `onSetAIState` callback function to track updates to the AI state and save it to the database when `done(...)` is called.
456
+
457
+ #### Before: Save chats using callback function of context provider
458
+
459
+ ```ts filename="@/app/actions.ts"
460
+ import { createAI } from '@ai-sdk/rsc';
461
+ import { saveChat } from '@/utils/queries';
462
+
463
+ export const AI = createAI({
464
+ initialAIState: {},
465
+ initialUIState: {},
466
+ actions: {
467
+ // server actions
468
+ },
469
+ onSetAIState: async ({ state, done }) => {
470
+ 'use server';
471
+
472
+ if (done) {
473
+ await saveChat(state);
474
+ }
475
+ },
476
+ });
477
+ ```
478
+
479
+ #### After: Save chats using callback function of `streamText`
480
+
481
+ With AI SDK UI, you will save chats using the `onFinish` callback function of `streamText` in your route handler.
482
+
483
+ ```ts filename="@/app/api/chat/route.ts"
484
+ import { openai } from '@ai-sdk/openai';
485
+ import { saveChat } from '@/utils/queries';
486
+ import { streamText, convertToModelMessages } from 'ai';
487
+
488
+ export async function POST(request) {
489
+ const { id, messages } = await request.json();
490
+
491
+ const coreMessages = await convertToModelMessages(messages);
492
+
493
+ const result = streamText({
494
+ model: __MODEL__,
495
+ system: 'you are a friendly assistant!',
496
+ messages: coreMessages,
497
+ onFinish: async ({ response }) => {
498
+ try {
499
+ await saveChat({
500
+ id,
501
+ messages: [...coreMessages, ...response.messages],
502
+ });
503
+ } catch (error) {
504
+ console.error('Failed to save chat');
505
+ }
506
+ },
507
+ });
508
+
509
+ return result.toUIMessageStreamResponse();
510
+ }
511
+ ```
512
+
513
+ ### Restoring Chats
514
+
515
+ When using AI SDK RSC, the `useUIState` hook contains the UI state of the chat. When restoring a previously saved chat, the UI state needs to be loaded with messages.
516
+
517
+ Similar to how you typically save chats in AI SDK RSC, you should use the `onGetUIState` callback function to retrieve the chat from the database, convert it into UI state, and return it to be accessible through `useUIState`.
518
+
519
+ #### Before: Load chat from database using callback function of context provider
520
+
521
+ ```ts filename="@/app/actions.ts"
522
+ import { createAI } from '@ai-sdk/rsc';
523
+ import { loadChatFromDB, convertToUIState } from '@/utils/queries';
524
+
525
+ export const AI = createAI({
526
+ actions: {
527
+ // server actions
528
+ },
529
+ onGetUIState: async () => {
530
+ 'use server';
531
+
532
+ const chat = await loadChatFromDB();
533
+ const uiState = convertToUIState(chat);
534
+
535
+ return uiState;
536
+ },
537
+ });
538
+ ```
539
+
540
+ AI SDK UI uses the `messages` field of `useChat` to store messages. To load messages when `useChat` is mounted, you should use `initialMessages`.
541
+
542
+ As messages are typically loaded from the database, we can use a server actions inside a Page component to fetch an older chat from the database during static generation and pass the messages as props to the `<Chat/>` component.
543
+
544
+ #### After: Load chat from database during static generation of page
545
+
546
+ ```tsx filename="@/app/chat/[id]/page.tsx"
547
+ import { Chat } from '@/app/components/chat';
548
+ import { getChatById } from '@/utils/queries';
549
+
550
+ // link to example implementation: https://github.com/vercel/ai-chatbot/blob/00b125378c998d19ef60b73fe576df0fe5a0e9d4/lib/utils.ts#L87-L127
551
+ import { convertToUIMessages } from '@/utils/functions';
552
+
553
+ export default async function Page({ params }: { params: any }) {
554
+ const { id } = params;
555
+ const chatFromDb = await getChatById({ id });
556
+
557
+ const chat: Chat = {
558
+ ...chatFromDb,
559
+ messages: convertToUIMessages(chatFromDb.messages),
560
+ };
561
+
562
+ return <Chat key={id} id={chat.id} initialMessages={chat.messages} />;
563
+ }
564
+ ```
565
+
566
+ #### After: Pass chat messages as props and load into chat hook
567
+
568
+ ```tsx filename="@/app/components/chat.tsx"
569
+ 'use client';
570
+
571
+ import { Message } from 'ai';
572
+ import { useChat } from '@ai-sdk/react';
573
+
574
+ export function Chat({
575
+ id,
576
+ initialMessages,
577
+ }: {
578
+ id;
579
+ initialMessages: Array<Message>;
580
+ }) {
581
+ const { messages } = useChat({
582
+ id,
583
+ initialMessages,
584
+ });
585
+
586
+ return (
587
+ <div>
588
+ {messages.map(message => (
589
+ <div key={message.id}>
590
+ <div>{message.role}</div>
591
+ <div>{message.content}</div>
592
+ </div>
593
+ ))}
594
+ </div>
595
+ );
596
+ }
597
+ ```
598
+
599
+ ## Streaming Object Generation
600
+
601
+ The `createStreamableValue` function streams any serializable data from the server to the client. As a result, this function allows you to stream object generations from the server to the client when paired with `streamObject`.
602
+
603
+ #### Before: Use streamable value to stream object generations
604
+
605
+ ```ts filename="@/app/actions.ts"
606
+ import { streamObject } from 'ai';
607
+ import { openai } from '@ai-sdk/openai';
608
+ import { createStreamableValue } from '@ai-sdk/rsc';
609
+ import { notificationsSchema } from '@/utils/schemas';
610
+
611
+ export async function generateSampleNotifications() {
612
+ 'use server';
613
+
614
+ const stream = createStreamableValue();
615
+
616
+ (async () => {
617
+ const { partialObjectStream } = streamObject({
618
+ model: __MODEL__,
619
+ system: 'generate sample ios messages for testing',
620
+ prompt: 'messages from a family group chat during diwali, max 4',
621
+ schema: notificationsSchema,
622
+ });
623
+
624
+ for await (const partialObject of partialObjectStream) {
625
+ stream.update(partialObject);
626
+ }
627
+ })();
628
+
629
+ stream.done();
630
+
631
+ return { partialNotificationsStream: stream.value };
632
+ }
633
+ ```
634
+
635
+ #### Before: Read streamable value and update object
636
+
637
+ ```tsx filename="@/app/page.tsx"
638
+ 'use client';
639
+
640
+ import { useState } from 'react';
641
+ import { readStreamableValue } from '@ai-sdk/rsc';
642
+ import { generateSampleNotifications } from '@/app/actions';
643
+
644
+ export default function Page() {
645
+ const [notifications, setNotifications] = useState(null);
646
+
647
+ return (
648
+ <div>
649
+ <button
650
+ onClick={async () => {
651
+ const { partialNotificationsStream } =
652
+ await generateSampleNotifications();
653
+
654
+ for await (const partialNotifications of readStreamableValue(
655
+ partialNotificationsStream,
656
+ )) {
657
+ if (partialNotifications) {
658
+ setNotifications(partialNotifications.notifications);
659
+ }
660
+ }
661
+ }}
662
+ >
663
+ Generate
664
+ </button>
665
+ </div>
666
+ );
667
+ }
668
+ ```
669
+
670
+ To migrate to AI SDK UI, you should use the `useObject` hook and implement `streamObject` within your route handler.
671
+
672
+ #### After: Replace with route handler and stream text response
673
+
674
+ ```ts filename="@/app/api/object/route.ts"
675
+ import { streamObject } from 'ai';
676
+ import { openai } from '@ai-sdk/openai';
677
+ import { notificationSchema } from '@/utils/schemas';
678
+
679
+ export async function POST(req: Request) {
680
+ const context = await req.json();
681
+
682
+ const result = streamObject({
683
+ model: __MODEL__,
684
+ schema: notificationSchema,
685
+ prompt:
686
+ `Generate 3 notifications for a messages app in this context:` + context,
687
+ });
688
+
689
+ return result.toTextStreamResponse();
690
+ }
691
+ ```
692
+
693
+ #### After: Use object hook to decode stream and update object
694
+
695
+ ```tsx filename="@/app/page.tsx"
696
+ 'use client';
697
+
698
+ import { useObject } from '@ai-sdk/react';
699
+ import { notificationSchema } from '@/utils/schemas';
700
+
701
+ export default function Page() {
702
+ const { object, submit } = useObject({
703
+ api: '/api/object',
704
+ schema: notificationSchema,
705
+ });
706
+
707
+ return (
708
+ <div>
709
+ <button onClick={() => submit('Messages during finals week.')}>
710
+ Generate notifications
711
+ </button>
712
+
713
+ {object?.notifications?.map((notification, index) => (
714
+ <div key={index}>
715
+ <p>{notification?.name}</p>
716
+ <p>{notification?.message}</p>
717
+ </div>
718
+ ))}
719
+ </div>
720
+ );
721
+ }
722
+ ```