@fondation-io/ai 7.0.0-beta.45

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 (536) hide show
  1. package/CHANGELOG.md +7687 -0
  2. package/README.md +238 -0
  3. package/dist/index.d.mts +7056 -0
  4. package/dist/index.d.ts +7056 -0
  5. package/dist/index.js +14607 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +14578 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/dist/internal/index.d.mts +303 -0
  10. package/dist/internal/index.d.ts +303 -0
  11. package/dist/internal/index.js +1352 -0
  12. package/dist/internal/index.js.map +1 -0
  13. package/dist/internal/index.mjs +1336 -0
  14. package/dist/internal/index.mjs.map +1 -0
  15. package/dist/test/index.d.mts +265 -0
  16. package/dist/test/index.d.ts +265 -0
  17. package/dist/test/index.js +509 -0
  18. package/dist/test/index.js.map +1 -0
  19. package/dist/test/index.mjs +472 -0
  20. package/dist/test/index.mjs.map +1 -0
  21. package/docs/00-introduction/index.mdx +76 -0
  22. package/docs/02-foundations/01-overview.mdx +43 -0
  23. package/docs/02-foundations/02-providers-and-models.mdx +160 -0
  24. package/docs/02-foundations/03-prompts.mdx +616 -0
  25. package/docs/02-foundations/04-tools.mdx +251 -0
  26. package/docs/02-foundations/05-streaming.mdx +62 -0
  27. package/docs/02-foundations/06-provider-options.mdx +345 -0
  28. package/docs/02-foundations/index.mdx +49 -0
  29. package/docs/02-getting-started/00-choosing-a-provider.mdx +110 -0
  30. package/docs/02-getting-started/01-navigating-the-library.mdx +85 -0
  31. package/docs/02-getting-started/02-nextjs-app-router.mdx +559 -0
  32. package/docs/02-getting-started/03-nextjs-pages-router.mdx +542 -0
  33. package/docs/02-getting-started/04-svelte.mdx +627 -0
  34. package/docs/02-getting-started/05-nuxt.mdx +566 -0
  35. package/docs/02-getting-started/06-nodejs.mdx +512 -0
  36. package/docs/02-getting-started/07-expo.mdx +766 -0
  37. package/docs/02-getting-started/08-tanstack-start.mdx +583 -0
  38. package/docs/02-getting-started/09-coding-agents.mdx +179 -0
  39. package/docs/02-getting-started/index.mdx +44 -0
  40. package/docs/03-agents/01-overview.mdx +96 -0
  41. package/docs/03-agents/02-building-agents.mdx +449 -0
  42. package/docs/03-agents/03-workflows.mdx +386 -0
  43. package/docs/03-agents/04-loop-control.mdx +394 -0
  44. package/docs/03-agents/05-configuring-call-options.mdx +286 -0
  45. package/docs/03-agents/06-memory.mdx +222 -0
  46. package/docs/03-agents/06-subagents.mdx +362 -0
  47. package/docs/03-agents/index.mdx +46 -0
  48. package/docs/03-ai-sdk-core/01-overview.mdx +31 -0
  49. package/docs/03-ai-sdk-core/05-generating-text.mdx +707 -0
  50. package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +498 -0
  51. package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +1148 -0
  52. package/docs/03-ai-sdk-core/16-mcp-tools.mdx +383 -0
  53. package/docs/03-ai-sdk-core/20-prompt-engineering.mdx +146 -0
  54. package/docs/03-ai-sdk-core/25-settings.mdx +216 -0
  55. package/docs/03-ai-sdk-core/26-reasoning.mdx +190 -0
  56. package/docs/03-ai-sdk-core/30-embeddings.mdx +236 -0
  57. package/docs/03-ai-sdk-core/31-reranking.mdx +218 -0
  58. package/docs/03-ai-sdk-core/35-image-generation.mdx +341 -0
  59. package/docs/03-ai-sdk-core/36-transcription.mdx +227 -0
  60. package/docs/03-ai-sdk-core/37-speech.mdx +169 -0
  61. package/docs/03-ai-sdk-core/38-video-generation.mdx +366 -0
  62. package/docs/03-ai-sdk-core/40-middleware.mdx +485 -0
  63. package/docs/03-ai-sdk-core/45-provider-management.mdx +349 -0
  64. package/docs/03-ai-sdk-core/50-error-handling.mdx +149 -0
  65. package/docs/03-ai-sdk-core/55-testing.mdx +219 -0
  66. package/docs/03-ai-sdk-core/60-telemetry.mdx +391 -0
  67. package/docs/03-ai-sdk-core/65-devtools.mdx +107 -0
  68. package/docs/03-ai-sdk-core/65-event-listeners.mdx +1303 -0
  69. package/docs/03-ai-sdk-core/index.mdx +99 -0
  70. package/docs/04-ai-sdk-ui/01-overview.mdx +44 -0
  71. package/docs/04-ai-sdk-ui/02-chatbot.mdx +1320 -0
  72. package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +534 -0
  73. package/docs/04-ai-sdk-ui/03-chatbot-resume-streams.mdx +263 -0
  74. package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +682 -0
  75. package/docs/04-ai-sdk-ui/04-generative-user-interfaces.mdx +389 -0
  76. package/docs/04-ai-sdk-ui/05-completion.mdx +181 -0
  77. package/docs/04-ai-sdk-ui/08-object-generation.mdx +344 -0
  78. package/docs/04-ai-sdk-ui/20-streaming-data.mdx +397 -0
  79. package/docs/04-ai-sdk-ui/21-error-handling.mdx +190 -0
  80. package/docs/04-ai-sdk-ui/21-transport.mdx +174 -0
  81. package/docs/04-ai-sdk-ui/24-reading-ui-message-streams.mdx +104 -0
  82. package/docs/04-ai-sdk-ui/25-message-metadata.mdx +152 -0
  83. package/docs/04-ai-sdk-ui/50-stream-protocol.mdx +503 -0
  84. package/docs/04-ai-sdk-ui/index.mdx +64 -0
  85. package/docs/05-ai-sdk-rsc/01-overview.mdx +45 -0
  86. package/docs/05-ai-sdk-rsc/02-streaming-react-components.mdx +209 -0
  87. package/docs/05-ai-sdk-rsc/03-generative-ui-state.mdx +279 -0
  88. package/docs/05-ai-sdk-rsc/03-saving-and-restoring-states.mdx +105 -0
  89. package/docs/05-ai-sdk-rsc/04-multistep-interfaces.mdx +282 -0
  90. package/docs/05-ai-sdk-rsc/05-streaming-values.mdx +157 -0
  91. package/docs/05-ai-sdk-rsc/06-loading-state.mdx +273 -0
  92. package/docs/05-ai-sdk-rsc/08-error-handling.mdx +94 -0
  93. package/docs/05-ai-sdk-rsc/09-authentication.mdx +42 -0
  94. package/docs/05-ai-sdk-rsc/10-migrating-to-ui.mdx +722 -0
  95. package/docs/05-ai-sdk-rsc/index.mdx +63 -0
  96. package/docs/06-advanced/01-prompt-engineering.mdx +96 -0
  97. package/docs/06-advanced/02-stopping-streams.mdx +184 -0
  98. package/docs/06-advanced/03-backpressure.mdx +173 -0
  99. package/docs/06-advanced/04-caching.mdx +169 -0
  100. package/docs/06-advanced/05-multiple-streamables.mdx +68 -0
  101. package/docs/06-advanced/06-rate-limiting.mdx +60 -0
  102. package/docs/06-advanced/07-rendering-ui-with-language-models.mdx +225 -0
  103. package/docs/06-advanced/08-model-as-router.mdx +120 -0
  104. package/docs/06-advanced/09-multistep-interfaces.mdx +115 -0
  105. package/docs/06-advanced/09-sequential-generations.mdx +55 -0
  106. package/docs/06-advanced/10-vercel-deployment-guide.mdx +117 -0
  107. package/docs/06-advanced/index.mdx +11 -0
  108. package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2785 -0
  109. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +3752 -0
  110. package/docs/07-reference/01-ai-sdk-core/05-embed.mdx +332 -0
  111. package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +330 -0
  112. package/docs/07-reference/01-ai-sdk-core/06-rerank.mdx +323 -0
  113. package/docs/07-reference/01-ai-sdk-core/10-generate-image.mdx +251 -0
  114. package/docs/07-reference/01-ai-sdk-core/11-transcribe.mdx +152 -0
  115. package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +221 -0
  116. package/docs/07-reference/01-ai-sdk-core/13-generate-video.mdx +264 -0
  117. package/docs/07-reference/01-ai-sdk-core/15-agent.mdx +235 -0
  118. package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +973 -0
  119. package/docs/07-reference/01-ai-sdk-core/17-create-agent-ui-stream.mdx +154 -0
  120. package/docs/07-reference/01-ai-sdk-core/18-create-agent-ui-stream-response.mdx +173 -0
  121. package/docs/07-reference/01-ai-sdk-core/18-pipe-agent-ui-stream-to-response.mdx +150 -0
  122. package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +209 -0
  123. package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +223 -0
  124. package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +423 -0
  125. package/docs/07-reference/01-ai-sdk-core/24-mcp-stdio-transport.mdx +68 -0
  126. package/docs/07-reference/01-ai-sdk-core/25-json-schema.mdx +94 -0
  127. package/docs/07-reference/01-ai-sdk-core/26-zod-schema.mdx +109 -0
  128. package/docs/07-reference/01-ai-sdk-core/27-valibot-schema.mdx +58 -0
  129. package/docs/07-reference/01-ai-sdk-core/28-output.mdx +342 -0
  130. package/docs/07-reference/01-ai-sdk-core/30-model-message.mdx +435 -0
  131. package/docs/07-reference/01-ai-sdk-core/31-ui-message.mdx +264 -0
  132. package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +101 -0
  133. package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +113 -0
  134. package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +198 -0
  135. package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +157 -0
  136. package/docs/07-reference/01-ai-sdk-core/50-cosine-similarity.mdx +52 -0
  137. package/docs/07-reference/01-ai-sdk-core/60-wrap-language-model.mdx +59 -0
  138. package/docs/07-reference/01-ai-sdk-core/61-wrap-image-model.mdx +64 -0
  139. package/docs/07-reference/01-ai-sdk-core/65-language-model-v2-middleware.mdx +74 -0
  140. package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +68 -0
  141. package/docs/07-reference/01-ai-sdk-core/67-simulate-streaming-middleware.mdx +71 -0
  142. package/docs/07-reference/01-ai-sdk-core/68-default-settings-middleware.mdx +80 -0
  143. package/docs/07-reference/01-ai-sdk-core/69-add-tool-input-examples-middleware.mdx +155 -0
  144. package/docs/07-reference/01-ai-sdk-core/70-extract-json-middleware.mdx +147 -0
  145. package/docs/07-reference/01-ai-sdk-core/70-step-count-is.mdx +84 -0
  146. package/docs/07-reference/01-ai-sdk-core/71-has-tool-call.mdx +120 -0
  147. package/docs/07-reference/01-ai-sdk-core/75-simulate-readable-stream.mdx +94 -0
  148. package/docs/07-reference/01-ai-sdk-core/80-smooth-stream.mdx +145 -0
  149. package/docs/07-reference/01-ai-sdk-core/90-generate-id.mdx +30 -0
  150. package/docs/07-reference/01-ai-sdk-core/91-create-id-generator.mdx +89 -0
  151. package/docs/07-reference/01-ai-sdk-core/92-default-generated-file.mdx +68 -0
  152. package/docs/07-reference/01-ai-sdk-core/index.mdx +160 -0
  153. package/docs/07-reference/02-ai-sdk-ui/01-use-chat.mdx +493 -0
  154. package/docs/07-reference/02-ai-sdk-ui/02-use-completion.mdx +185 -0
  155. package/docs/07-reference/02-ai-sdk-ui/03-use-object.mdx +196 -0
  156. package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +231 -0
  157. package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +108 -0
  158. package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +162 -0
  159. package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +119 -0
  160. package/docs/07-reference/02-ai-sdk-ui/42-pipe-ui-message-stream-to-response.mdx +77 -0
  161. package/docs/07-reference/02-ai-sdk-ui/43-read-ui-message-stream.mdx +57 -0
  162. package/docs/07-reference/02-ai-sdk-ui/46-infer-ui-tools.mdx +99 -0
  163. package/docs/07-reference/02-ai-sdk-ui/47-infer-ui-tool.mdx +75 -0
  164. package/docs/07-reference/02-ai-sdk-ui/50-direct-chat-transport.mdx +333 -0
  165. package/docs/07-reference/02-ai-sdk-ui/index.mdx +89 -0
  166. package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +767 -0
  167. package/docs/07-reference/03-ai-sdk-rsc/02-create-ai.mdx +90 -0
  168. package/docs/07-reference/03-ai-sdk-rsc/03-create-streamable-ui.mdx +91 -0
  169. package/docs/07-reference/03-ai-sdk-rsc/04-create-streamable-value.mdx +78 -0
  170. package/docs/07-reference/03-ai-sdk-rsc/05-read-streamable-value.mdx +79 -0
  171. package/docs/07-reference/03-ai-sdk-rsc/06-get-ai-state.mdx +50 -0
  172. package/docs/07-reference/03-ai-sdk-rsc/07-get-mutable-ai-state.mdx +70 -0
  173. package/docs/07-reference/03-ai-sdk-rsc/08-use-ai-state.mdx +26 -0
  174. package/docs/07-reference/03-ai-sdk-rsc/09-use-actions.mdx +42 -0
  175. package/docs/07-reference/03-ai-sdk-rsc/10-use-ui-state.mdx +35 -0
  176. package/docs/07-reference/03-ai-sdk-rsc/11-use-streamable-value.mdx +46 -0
  177. package/docs/07-reference/03-ai-sdk-rsc/20-render.mdx +266 -0
  178. package/docs/07-reference/03-ai-sdk-rsc/index.mdx +67 -0
  179. package/docs/07-reference/05-ai-sdk-errors/ai-api-call-error.mdx +31 -0
  180. package/docs/07-reference/05-ai-sdk-errors/ai-download-error.mdx +28 -0
  181. package/docs/07-reference/05-ai-sdk-errors/ai-empty-response-body-error.mdx +24 -0
  182. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-argument-error.mdx +26 -0
  183. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-data-content-error.mdx +26 -0
  184. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-message-role-error.mdx +25 -0
  185. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-prompt-error.mdx +47 -0
  186. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-response-data-error.mdx +25 -0
  187. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-tool-approval-error.mdx +24 -0
  188. package/docs/07-reference/05-ai-sdk-errors/ai-invalid-tool-input-error.mdx +27 -0
  189. package/docs/07-reference/05-ai-sdk-errors/ai-json-parse-error.mdx +25 -0
  190. package/docs/07-reference/05-ai-sdk-errors/ai-load-api-key-error.mdx +24 -0
  191. package/docs/07-reference/05-ai-sdk-errors/ai-load-setting-error.mdx +24 -0
  192. package/docs/07-reference/05-ai-sdk-errors/ai-message-conversion-error.mdx +25 -0
  193. package/docs/07-reference/05-ai-sdk-errors/ai-no-content-generated-error.mdx +24 -0
  194. package/docs/07-reference/05-ai-sdk-errors/ai-no-image-generated-error.mdx +36 -0
  195. package/docs/07-reference/05-ai-sdk-errors/ai-no-object-generated-error.mdx +43 -0
  196. package/docs/07-reference/05-ai-sdk-errors/ai-no-output-generated-error.mdx +25 -0
  197. package/docs/07-reference/05-ai-sdk-errors/ai-no-speech-generated-error.mdx +24 -0
  198. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +26 -0
  199. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +28 -0
  200. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-tool-error.mdx +26 -0
  201. package/docs/07-reference/05-ai-sdk-errors/ai-no-transcript-generated-error.mdx +24 -0
  202. package/docs/07-reference/05-ai-sdk-errors/ai-no-video-generated-error.mdx +39 -0
  203. package/docs/07-reference/05-ai-sdk-errors/ai-retry-error.mdx +27 -0
  204. package/docs/07-reference/05-ai-sdk-errors/ai-too-many-embedding-values-for-call-error.mdx +27 -0
  205. package/docs/07-reference/05-ai-sdk-errors/ai-tool-call-not-found-for-approval-error.mdx +25 -0
  206. package/docs/07-reference/05-ai-sdk-errors/ai-tool-call-repair-error.mdx +28 -0
  207. package/docs/07-reference/05-ai-sdk-errors/ai-type-validation-error.mdx +25 -0
  208. package/docs/07-reference/05-ai-sdk-errors/ai-ui-message-stream-error.mdx +67 -0
  209. package/docs/07-reference/05-ai-sdk-errors/ai-unsupported-functionality-error.mdx +25 -0
  210. package/docs/07-reference/05-ai-sdk-errors/index.mdx +39 -0
  211. package/docs/07-reference/index.mdx +28 -0
  212. package/docs/08-migration-guides/00-versioning.mdx +46 -0
  213. package/docs/08-migration-guides/23-migration-guide-7-0.mdx +95 -0
  214. package/docs/08-migration-guides/24-migration-guide-6-0.mdx +823 -0
  215. package/docs/08-migration-guides/25-migration-guide-5-0-data.mdx +882 -0
  216. package/docs/08-migration-guides/26-migration-guide-5-0.mdx +3427 -0
  217. package/docs/08-migration-guides/27-migration-guide-4-2.mdx +99 -0
  218. package/docs/08-migration-guides/28-migration-guide-4-1.mdx +14 -0
  219. package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1157 -0
  220. package/docs/08-migration-guides/36-migration-guide-3-4.mdx +14 -0
  221. package/docs/08-migration-guides/37-migration-guide-3-3.mdx +64 -0
  222. package/docs/08-migration-guides/38-migration-guide-3-2.mdx +46 -0
  223. package/docs/08-migration-guides/39-migration-guide-3-1.mdx +168 -0
  224. package/docs/08-migration-guides/index.mdx +22 -0
  225. package/docs/09-troubleshooting/01-azure-stream-slow.mdx +33 -0
  226. package/docs/09-troubleshooting/03-server-actions-in-client-components.mdx +40 -0
  227. package/docs/09-troubleshooting/04-strange-stream-output.mdx +36 -0
  228. package/docs/09-troubleshooting/05-streamable-ui-errors.mdx +16 -0
  229. package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +106 -0
  230. package/docs/09-troubleshooting/06-streaming-not-working-when-deployed.mdx +31 -0
  231. package/docs/09-troubleshooting/06-streaming-not-working-when-proxied.mdx +31 -0
  232. package/docs/09-troubleshooting/06-timeout-on-vercel.mdx +60 -0
  233. package/docs/09-troubleshooting/07-unclosed-streams.mdx +34 -0
  234. package/docs/09-troubleshooting/08-use-chat-failed-to-parse-stream.mdx +26 -0
  235. package/docs/09-troubleshooting/09-client-stream-error.mdx +25 -0
  236. package/docs/09-troubleshooting/10-use-chat-tools-no-response.mdx +32 -0
  237. package/docs/09-troubleshooting/11-use-chat-custom-request-options.mdx +149 -0
  238. package/docs/09-troubleshooting/12-typescript-performance-zod.mdx +46 -0
  239. package/docs/09-troubleshooting/12-use-chat-an-error-occurred.mdx +59 -0
  240. package/docs/09-troubleshooting/13-repeated-assistant-messages.mdx +73 -0
  241. package/docs/09-troubleshooting/14-stream-abort-handling.mdx +73 -0
  242. package/docs/09-troubleshooting/14-tool-calling-with-structured-outputs.mdx +48 -0
  243. package/docs/09-troubleshooting/15-abort-breaks-resumable-streams.mdx +55 -0
  244. package/docs/09-troubleshooting/15-stream-text-not-working.mdx +33 -0
  245. package/docs/09-troubleshooting/16-streaming-status-delay.mdx +63 -0
  246. package/docs/09-troubleshooting/17-use-chat-stale-body-data.mdx +141 -0
  247. package/docs/09-troubleshooting/18-ontoolcall-type-narrowing.mdx +66 -0
  248. package/docs/09-troubleshooting/19-unsupported-model-version.mdx +50 -0
  249. package/docs/09-troubleshooting/20-no-object-generated-content-filter.mdx +76 -0
  250. package/docs/09-troubleshooting/21-missing-tool-results-error.mdx +82 -0
  251. package/docs/09-troubleshooting/30-model-is-not-assignable-to-type.mdx +21 -0
  252. package/docs/09-troubleshooting/40-typescript-cannot-find-namespace-jsx.mdx +24 -0
  253. package/docs/09-troubleshooting/50-react-maximum-update-depth-exceeded.mdx +39 -0
  254. package/docs/09-troubleshooting/60-jest-cannot-find-module-ai-rsc.mdx +22 -0
  255. package/docs/09-troubleshooting/70-high-memory-usage-with-images.mdx +108 -0
  256. package/docs/09-troubleshooting/index.mdx +11 -0
  257. package/internal.d.ts +1 -0
  258. package/package.json +120 -0
  259. package/src/agent/agent.ts +156 -0
  260. package/src/agent/create-agent-ui-stream-response.ts +61 -0
  261. package/src/agent/create-agent-ui-stream.ts +84 -0
  262. package/src/agent/index.ts +37 -0
  263. package/src/agent/infer-agent-tools.ts +7 -0
  264. package/src/agent/infer-agent-ui-message.ts +11 -0
  265. package/src/agent/pipe-agent-ui-stream-to-response.ts +64 -0
  266. package/src/agent/tool-loop-agent-settings.ts +252 -0
  267. package/src/agent/tool-loop-agent.ts +205 -0
  268. package/src/embed/embed-events.ts +181 -0
  269. package/src/embed/embed-many-result.ts +53 -0
  270. package/src/embed/embed-many.ts +428 -0
  271. package/src/embed/embed-result.ts +50 -0
  272. package/src/embed/embed.ts +266 -0
  273. package/src/embed/index.ts +5 -0
  274. package/src/error/index.ts +37 -0
  275. package/src/error/invalid-argument-error.ts +34 -0
  276. package/src/error/invalid-stream-part-error.ts +28 -0
  277. package/src/error/invalid-tool-approval-error.ts +26 -0
  278. package/src/error/invalid-tool-input-error.ts +33 -0
  279. package/src/error/missing-tool-result-error.ts +28 -0
  280. package/src/error/no-image-generated-error.ts +39 -0
  281. package/src/error/no-object-generated-error.ts +70 -0
  282. package/src/error/no-output-generated-error.ts +26 -0
  283. package/src/error/no-speech-generated-error.ts +28 -0
  284. package/src/error/no-such-tool-error.ts +35 -0
  285. package/src/error/no-transcript-generated-error.ts +30 -0
  286. package/src/error/no-video-generated-error.ts +57 -0
  287. package/src/error/tool-call-not-found-for-approval-error.ts +32 -0
  288. package/src/error/tool-call-repair-error.ts +30 -0
  289. package/src/error/ui-message-stream-error.ts +48 -0
  290. package/src/error/unsupported-model-version-error.ts +23 -0
  291. package/src/error/verify-no-object-generated-error.ts +27 -0
  292. package/src/generate-image/generate-image-result.ts +42 -0
  293. package/src/generate-image/generate-image.ts +361 -0
  294. package/src/generate-image/index.ts +18 -0
  295. package/src/generate-object/generate-object-result.ts +67 -0
  296. package/src/generate-object/generate-object.ts +514 -0
  297. package/src/generate-object/index.ts +9 -0
  298. package/src/generate-object/inject-json-instruction.ts +30 -0
  299. package/src/generate-object/output-strategy.ts +415 -0
  300. package/src/generate-object/parse-and-validate-object-result.ts +111 -0
  301. package/src/generate-object/repair-text.ts +12 -0
  302. package/src/generate-object/stream-object-result.ts +120 -0
  303. package/src/generate-object/stream-object.ts +984 -0
  304. package/src/generate-object/validate-object-generation-input.ts +144 -0
  305. package/src/generate-speech/generate-speech-result.ts +30 -0
  306. package/src/generate-speech/generate-speech.ts +191 -0
  307. package/src/generate-speech/generated-audio-file.ts +65 -0
  308. package/src/generate-speech/index.ts +3 -0
  309. package/src/generate-text/collect-tool-approvals.ts +116 -0
  310. package/src/generate-text/content-part.ts +31 -0
  311. package/src/generate-text/core-events.ts +390 -0
  312. package/src/generate-text/create-execute-tools-transformation.ts +144 -0
  313. package/src/generate-text/execute-tool-call.ts +190 -0
  314. package/src/generate-text/extract-reasoning-content.ts +17 -0
  315. package/src/generate-text/extract-text-content.ts +15 -0
  316. package/src/generate-text/generate-text-result.ts +168 -0
  317. package/src/generate-text/generate-text.ts +1445 -0
  318. package/src/generate-text/generated-file.ts +70 -0
  319. package/src/generate-text/index.ts +78 -0
  320. package/src/generate-text/invoke-tool-callbacks-from-stream.ts +81 -0
  321. package/src/generate-text/is-approval-needed.ts +29 -0
  322. package/src/generate-text/output-utils.ts +23 -0
  323. package/src/generate-text/output.ts +590 -0
  324. package/src/generate-text/parse-tool-call.ts +188 -0
  325. package/src/generate-text/prepare-step.ts +103 -0
  326. package/src/generate-text/prune-messages.ts +167 -0
  327. package/src/generate-text/reasoning-output.ts +99 -0
  328. package/src/generate-text/reasoning.ts +10 -0
  329. package/src/generate-text/response-message.ts +10 -0
  330. package/src/generate-text/smooth-stream.ts +162 -0
  331. package/src/generate-text/step-result.ts +310 -0
  332. package/src/generate-text/stop-condition.ts +29 -0
  333. package/src/generate-text/stream-model-call.ts +418 -0
  334. package/src/generate-text/stream-text-result.ts +536 -0
  335. package/src/generate-text/stream-text.ts +2696 -0
  336. package/src/generate-text/to-response-messages.ts +195 -0
  337. package/src/generate-text/tool-approval-request-output.ts +21 -0
  338. package/src/generate-text/tool-call-repair-function.ts +27 -0
  339. package/src/generate-text/tool-call.ts +47 -0
  340. package/src/generate-text/tool-error.ts +34 -0
  341. package/src/generate-text/tool-output-denied.ts +21 -0
  342. package/src/generate-text/tool-output.ts +7 -0
  343. package/src/generate-text/tool-result.ts +36 -0
  344. package/src/generate-text/tool-set.ts +14 -0
  345. package/src/generate-video/generate-video-result.ts +36 -0
  346. package/src/generate-video/generate-video.ts +402 -0
  347. package/src/generate-video/index.ts +3 -0
  348. package/src/global.ts +36 -0
  349. package/src/index.ts +49 -0
  350. package/src/logger/index.ts +6 -0
  351. package/src/logger/log-warnings.ts +140 -0
  352. package/src/middleware/add-tool-input-examples-middleware.ts +90 -0
  353. package/src/middleware/default-embedding-settings-middleware.ts +22 -0
  354. package/src/middleware/default-settings-middleware.ts +33 -0
  355. package/src/middleware/extract-json-middleware.ts +197 -0
  356. package/src/middleware/extract-reasoning-middleware.ts +249 -0
  357. package/src/middleware/index.ts +10 -0
  358. package/src/middleware/simulate-streaming-middleware.ts +79 -0
  359. package/src/middleware/wrap-embedding-model.ts +89 -0
  360. package/src/middleware/wrap-image-model.ts +92 -0
  361. package/src/middleware/wrap-language-model.ts +108 -0
  362. package/src/middleware/wrap-provider.ts +51 -0
  363. package/src/model/as-embedding-model-v3.ts +24 -0
  364. package/src/model/as-embedding-model-v4.ts +25 -0
  365. package/src/model/as-image-model-v3.ts +24 -0
  366. package/src/model/as-image-model-v4.ts +21 -0
  367. package/src/model/as-language-model-v3.ts +103 -0
  368. package/src/model/as-language-model-v4.ts +25 -0
  369. package/src/model/as-provider-v3.ts +36 -0
  370. package/src/model/as-provider-v4.ts +47 -0
  371. package/src/model/as-reranking-model-v4.ts +16 -0
  372. package/src/model/as-speech-model-v3.ts +24 -0
  373. package/src/model/as-speech-model-v4.ts +21 -0
  374. package/src/model/as-transcription-model-v3.ts +24 -0
  375. package/src/model/as-transcription-model-v4.ts +25 -0
  376. package/src/model/as-video-model-v4.ts +19 -0
  377. package/src/model/resolve-model.ts +172 -0
  378. package/src/prompt/call-settings.ts +169 -0
  379. package/src/prompt/content-part.ts +236 -0
  380. package/src/prompt/convert-to-language-model-prompt.ts +548 -0
  381. package/src/prompt/create-tool-model-output.ts +34 -0
  382. package/src/prompt/data-content.ts +134 -0
  383. package/src/prompt/index.ts +27 -0
  384. package/src/prompt/invalid-data-content-error.ts +29 -0
  385. package/src/prompt/invalid-message-role-error.ts +27 -0
  386. package/src/prompt/message-conversion-error.ts +28 -0
  387. package/src/prompt/message.ts +72 -0
  388. package/src/prompt/prepare-call-settings.ts +110 -0
  389. package/src/prompt/prepare-tools-and-tool-choice.ts +86 -0
  390. package/src/prompt/prompt.ts +43 -0
  391. package/src/prompt/split-data-url.ts +17 -0
  392. package/src/prompt/standardize-prompt.ts +99 -0
  393. package/src/prompt/wrap-gateway-error.ts +29 -0
  394. package/src/registry/custom-provider.ts +210 -0
  395. package/src/registry/index.ts +7 -0
  396. package/src/registry/no-such-provider-error.ts +41 -0
  397. package/src/registry/provider-registry.ts +331 -0
  398. package/src/rerank/index.ts +8 -0
  399. package/src/rerank/rerank-events.ts +189 -0
  400. package/src/rerank/rerank-result.ts +70 -0
  401. package/src/rerank/rerank.ts +348 -0
  402. package/src/telemetry/assemble-operation-name.ts +21 -0
  403. package/src/telemetry/get-base-telemetry-attributes.ts +45 -0
  404. package/src/telemetry/get-global-telemetry-integration.ts +126 -0
  405. package/src/telemetry/get-tracer.ts +20 -0
  406. package/src/telemetry/index.ts +4 -0
  407. package/src/telemetry/noop-tracer.ts +69 -0
  408. package/src/telemetry/open-telemetry-integration.ts +875 -0
  409. package/src/telemetry/record-span.ts +75 -0
  410. package/src/telemetry/select-telemetry-attributes.ts +78 -0
  411. package/src/telemetry/stringify-for-telemetry.ts +33 -0
  412. package/src/telemetry/telemetry-integration-registry.ts +22 -0
  413. package/src/telemetry/telemetry-integration.ts +139 -0
  414. package/src/telemetry/telemetry-settings.ts +55 -0
  415. package/src/test/mock-embedding-model-v2.ts +35 -0
  416. package/src/test/mock-embedding-model-v3.ts +48 -0
  417. package/src/test/mock-embedding-model-v4.ts +48 -0
  418. package/src/test/mock-image-model-v2.ts +28 -0
  419. package/src/test/mock-image-model-v3.ts +28 -0
  420. package/src/test/mock-image-model-v4.ts +28 -0
  421. package/src/test/mock-language-model-v2.ts +72 -0
  422. package/src/test/mock-language-model-v3.ts +77 -0
  423. package/src/test/mock-language-model-v4.ts +77 -0
  424. package/src/test/mock-provider-v2.ts +68 -0
  425. package/src/test/mock-provider-v3.ts +80 -0
  426. package/src/test/mock-provider-v4.ts +80 -0
  427. package/src/test/mock-reranking-model-v3.ts +25 -0
  428. package/src/test/mock-reranking-model-v4.ts +25 -0
  429. package/src/test/mock-server-response.ts +69 -0
  430. package/src/test/mock-speech-model-v2.ts +24 -0
  431. package/src/test/mock-speech-model-v3.ts +24 -0
  432. package/src/test/mock-speech-model-v4.ts +24 -0
  433. package/src/test/mock-tracer.ts +156 -0
  434. package/src/test/mock-transcription-model-v2.ts +24 -0
  435. package/src/test/mock-transcription-model-v3.ts +24 -0
  436. package/src/test/mock-transcription-model-v4.ts +24 -0
  437. package/src/test/mock-values.ts +4 -0
  438. package/src/test/mock-video-model-v3.ts +28 -0
  439. package/src/test/mock-video-model-v4.ts +28 -0
  440. package/src/test/not-implemented.ts +3 -0
  441. package/src/text-stream/create-text-stream-response.ts +30 -0
  442. package/src/text-stream/index.ts +2 -0
  443. package/src/text-stream/pipe-text-stream-to-response.ts +38 -0
  444. package/src/transcribe/index.ts +2 -0
  445. package/src/transcribe/transcribe-result.ts +60 -0
  446. package/src/transcribe/transcribe.ts +187 -0
  447. package/src/types/embedding-model-middleware.ts +15 -0
  448. package/src/types/embedding-model.ts +20 -0
  449. package/src/types/image-model-middleware.ts +15 -0
  450. package/src/types/image-model-response-metadata.ts +16 -0
  451. package/src/types/image-model.ts +19 -0
  452. package/src/types/index.ts +29 -0
  453. package/src/types/json-value.ts +15 -0
  454. package/src/types/language-model-middleware.ts +15 -0
  455. package/src/types/language-model-request-metadata.ts +6 -0
  456. package/src/types/language-model-response-metadata.ts +21 -0
  457. package/src/types/language-model.ts +106 -0
  458. package/src/types/provider-metadata.ts +16 -0
  459. package/src/types/provider.ts +55 -0
  460. package/src/types/reranking-model.ts +6 -0
  461. package/src/types/speech-model-response-metadata.ts +21 -0
  462. package/src/types/speech-model.ts +10 -0
  463. package/src/types/transcription-model-response-metadata.ts +16 -0
  464. package/src/types/transcription-model.ts +14 -0
  465. package/src/types/usage.ts +200 -0
  466. package/src/types/video-model-response-metadata.ts +28 -0
  467. package/src/types/video-model.ts +15 -0
  468. package/src/types/warning.ts +7 -0
  469. package/src/ui/call-completion-api.ts +157 -0
  470. package/src/ui/chat-transport.ts +83 -0
  471. package/src/ui/chat.ts +786 -0
  472. package/src/ui/convert-file-list-to-file-ui-parts.ts +36 -0
  473. package/src/ui/convert-to-model-messages.ts +403 -0
  474. package/src/ui/default-chat-transport.ts +36 -0
  475. package/src/ui/direct-chat-transport.ts +117 -0
  476. package/src/ui/http-chat-transport.ts +273 -0
  477. package/src/ui/index.ts +76 -0
  478. package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +44 -0
  479. package/src/ui/last-assistant-message-is-complete-with-tool-calls.ts +39 -0
  480. package/src/ui/process-text-stream.ts +16 -0
  481. package/src/ui/process-ui-message-stream.ts +858 -0
  482. package/src/ui/text-stream-chat-transport.ts +23 -0
  483. package/src/ui/transform-text-to-ui-message-stream.ts +27 -0
  484. package/src/ui/ui-messages.ts +602 -0
  485. package/src/ui/use-completion.ts +84 -0
  486. package/src/ui/validate-ui-messages.ts +521 -0
  487. package/src/ui-message-stream/create-ui-message-stream-response.ts +44 -0
  488. package/src/ui-message-stream/create-ui-message-stream.ts +145 -0
  489. package/src/ui-message-stream/get-response-ui-message-id.ts +35 -0
  490. package/src/ui-message-stream/handle-ui-message-stream-finish.ts +170 -0
  491. package/src/ui-message-stream/index.ts +14 -0
  492. package/src/ui-message-stream/json-to-sse-transform-stream.ts +17 -0
  493. package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +51 -0
  494. package/src/ui-message-stream/read-ui-message-stream.ts +87 -0
  495. package/src/ui-message-stream/ui-message-chunks.ts +372 -0
  496. package/src/ui-message-stream/ui-message-stream-headers.ts +7 -0
  497. package/src/ui-message-stream/ui-message-stream-on-finish-callback.ts +32 -0
  498. package/src/ui-message-stream/ui-message-stream-on-step-finish-callback.ts +25 -0
  499. package/src/ui-message-stream/ui-message-stream-response-init.ts +14 -0
  500. package/src/ui-message-stream/ui-message-stream-writer.ts +24 -0
  501. package/src/util/as-array.ts +3 -0
  502. package/src/util/async-iterable-stream.ts +94 -0
  503. package/src/util/consume-stream.ts +31 -0
  504. package/src/util/cosine-similarity.ts +46 -0
  505. package/src/util/create-resolvable-promise.ts +30 -0
  506. package/src/util/create-stitchable-stream.ts +112 -0
  507. package/src/util/data-url.ts +17 -0
  508. package/src/util/deep-partial.ts +84 -0
  509. package/src/util/detect-media-type.ts +226 -0
  510. package/src/util/download/create-download.ts +13 -0
  511. package/src/util/download/download-function.ts +45 -0
  512. package/src/util/download/download.ts +74 -0
  513. package/src/util/error-handler.ts +1 -0
  514. package/src/util/fix-json.ts +401 -0
  515. package/src/util/get-potential-start-index.ts +39 -0
  516. package/src/util/index.ts +12 -0
  517. package/src/util/is-deep-equal-data.ts +48 -0
  518. package/src/util/is-non-empty-object.ts +5 -0
  519. package/src/util/job.ts +1 -0
  520. package/src/util/log-v2-compatibility-warning.ts +21 -0
  521. package/src/util/merge-abort-signals.ts +43 -0
  522. package/src/util/merge-objects.ts +79 -0
  523. package/src/util/notify.ts +22 -0
  524. package/src/util/now.ts +4 -0
  525. package/src/util/parse-partial-json.ts +30 -0
  526. package/src/util/prepare-headers.ts +14 -0
  527. package/src/util/prepare-retries.ts +47 -0
  528. package/src/util/retry-error.ts +41 -0
  529. package/src/util/retry-with-exponential-backoff.ts +154 -0
  530. package/src/util/serial-job-executor.ts +36 -0
  531. package/src/util/simulate-readable-stream.ts +39 -0
  532. package/src/util/split-array.ts +20 -0
  533. package/src/util/value-of.ts +65 -0
  534. package/src/util/write-to-server-response.ts +49 -0
  535. package/src/version.ts +5 -0
  536. package/test.d.ts +1 -0
@@ -0,0 +1,2785 @@
1
+ ---
2
+ title: generateText
3
+ description: API Reference for generateText.
4
+ ---
5
+
6
+ # `generateText()`
7
+
8
+ Generates text and calls tools for a given prompt using a language model.
9
+
10
+ It is ideal for non-interactive use cases such as automation tasks where you need to write text (e.g. drafting email or summarizing web pages) and for agents that use tools.
11
+
12
+ ```ts
13
+ import { generateText } from 'ai';
14
+ __PROVIDER_IMPORT__;
15
+
16
+ const { text } = await generateText({
17
+ model: __MODEL__,
18
+ prompt: 'Invent a new holiday and describe its traditions.',
19
+ });
20
+
21
+ console.log(text);
22
+ ```
23
+
24
+ To see `generateText` in action, check out [these examples](#examples).
25
+
26
+ ## Import
27
+
28
+ <Snippet text={`import { generateText } from "ai"`} prompt={false} />
29
+
30
+ ## API Signature
31
+
32
+ ### Parameters
33
+
34
+ <PropertiesTable
35
+ content={[
36
+ {
37
+ name: 'model',
38
+ type: 'LanguageModel',
39
+ description: "The language model to use. Example: openai('gpt-4o')",
40
+ },
41
+ {
42
+ name: 'system',
43
+ type: 'string | SystemModelMessage | SystemModelMessage[]',
44
+ description:
45
+ 'The system prompt to use that specifies the behavior of the model.',
46
+ },
47
+ {
48
+ name: 'prompt',
49
+ type: 'string | Array<SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage>',
50
+ description: 'The input prompt to generate the text from.',
51
+ },
52
+ {
53
+ name: 'messages',
54
+ type: 'Array<SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage>',
55
+ description:
56
+ 'A list of messages that represent a conversation. Automatically converts UI messages from the useChat hook.',
57
+ properties: [
58
+ {
59
+ type: 'SystemModelMessage',
60
+ parameters: [
61
+ {
62
+ name: 'role',
63
+ type: "'system'",
64
+ description: 'The role for the system message.',
65
+ },
66
+ {
67
+ name: 'content',
68
+ type: 'string',
69
+ description: 'The content of the message.',
70
+ },
71
+ ],
72
+ },
73
+ {
74
+ type: 'UserModelMessage',
75
+ parameters: [
76
+ {
77
+ name: 'role',
78
+ type: "'user'",
79
+ description: 'The role for the user message.',
80
+ },
81
+ {
82
+ name: 'content',
83
+ type: 'string | Array<TextPart | ImagePart | FilePart>',
84
+ description: 'The content of the message.',
85
+ properties: [
86
+ {
87
+ type: 'TextPart',
88
+ parameters: [
89
+ {
90
+ name: 'type',
91
+ type: "'text'",
92
+ description: 'The type of the message part.',
93
+ },
94
+ {
95
+ name: 'text',
96
+ type: 'string',
97
+ description: 'The text content of the message part.',
98
+ },
99
+ ],
100
+ },
101
+ {
102
+ type: 'ImagePart',
103
+ parameters: [
104
+ {
105
+ name: 'type',
106
+ type: "'image'",
107
+ description: 'The type of the message part.',
108
+ },
109
+ {
110
+ name: 'image',
111
+ type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
112
+ description:
113
+ 'The image content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
114
+ },
115
+ {
116
+ name: 'mediaType',
117
+ type: 'string',
118
+ description:
119
+ 'The IANA media type of the image. Optional.',
120
+ isOptional: true,
121
+ },
122
+ ],
123
+ },
124
+ {
125
+ type: 'FilePart',
126
+ parameters: [
127
+ {
128
+ name: 'type',
129
+ type: "'file'",
130
+ description: 'The type of the message part.',
131
+ },
132
+ {
133
+ name: 'data',
134
+ type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
135
+ description:
136
+ 'The file content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
137
+ },
138
+ {
139
+ name: 'mediaType',
140
+ type: 'string',
141
+ description: 'The IANA media type of the file.',
142
+ },
143
+ ],
144
+ },
145
+ ],
146
+ },
147
+ ],
148
+ },
149
+ {
150
+ type: 'AssistantModelMessage',
151
+ parameters: [
152
+ {
153
+ name: 'role',
154
+ type: "'assistant'",
155
+ description: 'The role for the assistant message.',
156
+ },
157
+ {
158
+ name: 'content',
159
+ type: 'string | Array<TextPart | FilePart | ReasoningPart | ReasoningFilePart | ToolCallPart>',
160
+ description: 'The content of the message.',
161
+ properties: [
162
+ {
163
+ type: 'TextPart',
164
+ parameters: [
165
+ {
166
+ name: 'type',
167
+ type: "'text'",
168
+ description: 'The type of the message part.',
169
+ },
170
+ {
171
+ name: 'text',
172
+ type: 'string',
173
+ description: 'The text content of the message part.',
174
+ },
175
+ ],
176
+ },
177
+ {
178
+ type: 'ReasoningPart',
179
+ parameters: [
180
+ {
181
+ name: 'type',
182
+ type: "'reasoning'",
183
+ description: 'The type of the message part.',
184
+ },
185
+ {
186
+ name: 'text',
187
+ type: 'string',
188
+ description: 'The reasoning text.',
189
+ },
190
+ ],
191
+ },
192
+ {
193
+ type: 'ReasoningFilePart',
194
+ parameters: [
195
+ {
196
+ name: 'type',
197
+ type: "'reasoning-file'",
198
+ description: 'The type of the message part.',
199
+ },
200
+ {
201
+ name: 'data',
202
+ type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
203
+ description:
204
+ 'The file data. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
205
+ },
206
+ {
207
+ name: 'mediaType',
208
+ type: 'string',
209
+ description: 'The IANA media type of the file.',
210
+ },
211
+ ],
212
+ },
213
+ {
214
+ type: 'FilePart',
215
+ parameters: [
216
+ {
217
+ name: 'type',
218
+ type: "'file'",
219
+ description: 'The type of the message part.',
220
+ },
221
+ {
222
+ name: 'data',
223
+ type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
224
+ description:
225
+ 'The file content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
226
+ },
227
+ {
228
+ name: 'mediaType',
229
+ type: 'string',
230
+ description: 'The IANA media type of the file.',
231
+ },
232
+ {
233
+ name: 'filename',
234
+ type: 'string',
235
+ description: 'The name of the file.',
236
+ isOptional: true,
237
+ },
238
+ ],
239
+ },
240
+ {
241
+ type: 'ToolCallPart',
242
+ parameters: [
243
+ {
244
+ name: 'type',
245
+ type: "'tool-call'",
246
+ description: 'The type of the message part.',
247
+ },
248
+ {
249
+ name: 'toolCallId',
250
+ type: 'string',
251
+ description: 'The id of the tool call.',
252
+ },
253
+ {
254
+ name: 'toolName',
255
+ type: 'string',
256
+ description:
257
+ 'The name of the tool, which typically would be the name of the function.',
258
+ },
259
+ {
260
+ name: 'input',
261
+ type: 'object based on zod schema',
262
+ description:
263
+ 'Input (parameters) generated by the model to be used by the tool.',
264
+ },
265
+ ],
266
+ },
267
+ ],
268
+ },
269
+ ],
270
+ },
271
+ {
272
+ type: 'ToolModelMessage',
273
+ parameters: [
274
+ {
275
+ name: 'role',
276
+ type: "'tool'",
277
+ description: 'The role for the assistant message.',
278
+ },
279
+ {
280
+ name: 'content',
281
+ type: 'Array<ToolResultPart>',
282
+ description: 'The content of the message.',
283
+ properties: [
284
+ {
285
+ type: 'ToolResultPart',
286
+ parameters: [
287
+ {
288
+ name: 'type',
289
+ type: "'tool-result'",
290
+ description: 'The type of the message part.',
291
+ },
292
+ {
293
+ name: 'toolCallId',
294
+ type: 'string',
295
+ description:
296
+ 'The id of the tool call the result corresponds to.',
297
+ },
298
+ {
299
+ name: 'toolName',
300
+ type: 'string',
301
+ description:
302
+ 'The name of the tool the result corresponds to.',
303
+ },
304
+ {
305
+ name: 'output',
306
+ type: 'unknown',
307
+ description:
308
+ 'The result returned by the tool after execution.',
309
+ },
310
+ {
311
+ name: 'isError',
312
+ type: 'boolean',
313
+ isOptional: true,
314
+ description:
315
+ 'Whether the result is an error or an error message.',
316
+ },
317
+ ],
318
+ },
319
+ ],
320
+ },
321
+ ],
322
+ },
323
+ ],
324
+ },
325
+ {
326
+ name: 'tools',
327
+ type: 'ToolSet',
328
+ description:
329
+ 'Tools that are accessible to and can be called by the model. The model needs to support calling tools.',
330
+ properties: [
331
+ {
332
+ type: 'Tool',
333
+ parameters: [
334
+ {
335
+ name: 'description',
336
+ isOptional: true,
337
+ type: 'string',
338
+ description:
339
+ 'Information about the purpose of the tool including details on how and when it can be used by the model.',
340
+ },
341
+ {
342
+ name: 'inputSchema',
343
+ type: 'Zod Schema | JSON Schema',
344
+ description:
345
+ 'The schema of the input that the tool expects. The language model will use this to generate the input. It is also used to validate the output of the language model. Use descriptions to make the input understandable for the language model. You can either pass in a Zod schema or a JSON schema (using the `jsonSchema` function).',
346
+ },
347
+ {
348
+ name: 'execute',
349
+ isOptional: true,
350
+ type: 'async (parameters: T, options: ToolExecutionOptions) => RESULT',
351
+ description:
352
+ 'An async function that is called with the arguments from the tool call and produces a result. If not provided, the tool will not be executed automatically.',
353
+ properties: [
354
+ {
355
+ type: 'ToolExecutionOptions',
356
+ parameters: [
357
+ {
358
+ name: 'toolCallId',
359
+ type: 'string',
360
+ description:
361
+ 'The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.',
362
+ },
363
+ {
364
+ name: 'messages',
365
+ type: 'ModelMessage[]',
366
+ description:
367
+ 'Messages that were sent to the language model to initiate the response that contained the tool call. The messages do not include the system prompt nor the assistant response that contained the tool call.',
368
+ },
369
+ {
370
+ name: 'abortSignal',
371
+ type: 'AbortSignal',
372
+ description:
373
+ 'An optional abort signal that indicates that the overall operation should be aborted.',
374
+ },
375
+ ],
376
+ },
377
+ ],
378
+ },
379
+ ],
380
+ },
381
+ ],
382
+ },
383
+ {
384
+ name: 'toolChoice',
385
+ isOptional: true,
386
+ type: '"auto" | "none" | "required" | { "type": "tool", "toolName": string }',
387
+ description:
388
+ 'The tool choice setting. It specifies how tools are selected for execution. The default is "auto". "none" disables tool execution. "required" requires tools to be executed. { "type": "tool", "toolName": string } specifies a specific tool to execute.',
389
+ },
390
+ {
391
+ name: 'maxOutputTokens',
392
+ type: 'number',
393
+ isOptional: true,
394
+ description: 'Maximum number of tokens to generate.',
395
+ },
396
+ {
397
+ name: 'temperature',
398
+ type: 'number',
399
+ isOptional: true,
400
+ description:
401
+ 'Temperature setting. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.',
402
+ },
403
+ {
404
+ name: 'topP',
405
+ type: 'number',
406
+ isOptional: true,
407
+ description:
408
+ 'Nucleus sampling. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.',
409
+ },
410
+ {
411
+ name: 'topK',
412
+ type: 'number',
413
+ isOptional: true,
414
+ description:
415
+ 'Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. Recommended for advanced use cases only. You usually only need to use temperature.',
416
+ },
417
+ {
418
+ name: 'presencePenalty',
419
+ type: 'number',
420
+ isOptional: true,
421
+ description:
422
+ 'Presence penalty setting. It affects the likelihood of the model to repeat information that is already in the prompt. The value is passed through to the provider. The range depends on the provider and model.',
423
+ },
424
+ {
425
+ name: 'frequencyPenalty',
426
+ type: 'number',
427
+ isOptional: true,
428
+ description:
429
+ 'Frequency penalty setting. It affects the likelihood of the model to repeatedly use the same words or phrases. The value is passed through to the provider. The range depends on the provider and model.',
430
+ },
431
+ {
432
+ name: 'stopSequences',
433
+ type: 'string[]',
434
+ isOptional: true,
435
+ description:
436
+ 'Sequences that will stop the generation of the text. If the model generates any of these sequences, it will stop generating further text.',
437
+ },
438
+ {
439
+ name: 'seed',
440
+ type: 'number',
441
+ isOptional: true,
442
+ description:
443
+ 'The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results.',
444
+ },
445
+ {
446
+ name: 'reasoning',
447
+ type: "'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'",
448
+ isOptional: true,
449
+ description:
450
+ "Controls how much reasoning the model performs before generating a response. When omitted, the provider's default behavior is used. `'provider-default'` explicitly requests the provider's default. Providers that do not support reasoning will emit a warning. If reasoning-related `providerOptions` are also set, they take precedence and this parameter is ignored. See the [reasoning guide](/docs/ai-sdk-core/reasoning) for provider-specific mapping details.",
451
+ },
452
+ {
453
+ name: 'maxRetries',
454
+ type: 'number',
455
+ isOptional: true,
456
+ description:
457
+ 'Maximum number of retries. Set to 0 to disable retries. Default: 2.',
458
+ },
459
+ {
460
+ name: 'abortSignal',
461
+ type: 'AbortSignal',
462
+ isOptional: true,
463
+ description:
464
+ 'An optional abort signal that can be used to cancel the call.',
465
+ },
466
+ {
467
+ name: 'timeout',
468
+ type: 'number | { totalMs?: number; stepMs?: number; toolMs?: number; tools?: { [toolName]Ms?: number } }',
469
+ isOptional: true,
470
+ description:
471
+ 'Timeout in milliseconds. Can be specified as a number or as an object with totalMs, stepMs, toolMs, and/or tools properties. totalMs sets the total timeout for the entire call. stepMs sets the timeout for each individual step (LLM call). toolMs sets the default timeout for all tool executions. tools sets per-tool timeout overrides using the pattern {toolName}Ms (e.g. weatherMs, slowApiMs) that take precedence over toolMs - tool names are type-checked for autocomplete. If a tool takes longer than its timeout, it aborts and returns a tool-error so the model can respond or retry. Can be used alongside abortSignal.',
472
+ },
473
+ {
474
+ name: 'headers',
475
+ type: 'Record<string, string | undefined>',
476
+ isOptional: true,
477
+ description:
478
+ 'Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.',
479
+ },
480
+ {
481
+ name: 'experimental_telemetry',
482
+ type: 'TelemetrySettings',
483
+ isOptional: true,
484
+ description: 'Telemetry configuration. Experimental feature.',
485
+ properties: [
486
+ {
487
+ type: 'TelemetrySettings',
488
+ parameters: [
489
+ {
490
+ name: 'isEnabled',
491
+ type: 'boolean',
492
+ isOptional: true,
493
+ description:
494
+ 'Enable or disable telemetry. Disabled by default while experimental.',
495
+ },
496
+ {
497
+ name: 'recordInputs',
498
+ type: 'boolean',
499
+ isOptional: true,
500
+ description:
501
+ 'Enable or disable input recording. Enabled by default.',
502
+ },
503
+ {
504
+ name: 'recordOutputs',
505
+ type: 'boolean',
506
+ isOptional: true,
507
+ description:
508
+ 'Enable or disable output recording. Enabled by default.',
509
+ },
510
+ {
511
+ name: 'functionId',
512
+ type: 'string',
513
+ isOptional: true,
514
+ description:
515
+ 'Identifier for this function. Used to group telemetry data by function.',
516
+ },
517
+ {
518
+ name: 'metadata',
519
+ isOptional: true,
520
+ type: 'Record<string, string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>>',
521
+ description:
522
+ 'Additional information to include in the telemetry data.',
523
+ },
524
+ ],
525
+ },
526
+ ],
527
+ },
528
+ {
529
+ name: 'providerOptions',
530
+ type: 'Record<string,JSONObject> | undefined',
531
+ isOptional: true,
532
+ description:
533
+ 'Provider-specific options. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
534
+ },
535
+ {
536
+ name: 'activeTools',
537
+ type: 'Array<TOOLNAME>',
538
+ isOptional: true,
539
+ description:
540
+ 'Limits the tools that are available for the model to call without changing the tool call and result types in the result. All tools are active by default.',
541
+ },
542
+ {
543
+ name: 'stopWhen',
544
+ type: 'StopCondition<TOOLS> | Array<StopCondition<TOOLS>>',
545
+ isOptional: true,
546
+ description:
547
+ 'Condition for stopping the generation when there are tool results in the last step. When the condition is an array, any of the conditions can be met to stop the generation. Default: stepCountIs(1).',
548
+ },
549
+ {
550
+ name: 'prepareStep',
551
+ type: '(options: PrepareStepOptions) => PrepareStepResult<TOOLS> | Promise<PrepareStepResult<TOOLS>>',
552
+ isOptional: true,
553
+ description:
554
+ 'Optional function that you can use to provide different settings for a step. You can modify the model, tool choices, active tools, system prompt, and input messages for each step.',
555
+ properties: [
556
+ {
557
+ type: 'PrepareStepFunction<TOOLS>',
558
+ parameters: [
559
+ {
560
+ name: 'options',
561
+ type: 'object',
562
+ description: 'The options for the step.',
563
+ properties: [
564
+ {
565
+ type: 'PrepareStepOptions',
566
+ parameters: [
567
+ {
568
+ name: 'steps',
569
+ type: 'Array<StepResult<TOOLS>>',
570
+ description: 'The steps that have been executed so far.',
571
+ },
572
+ {
573
+ name: 'stepNumber',
574
+ type: 'number',
575
+ description:
576
+ 'The number of the step that is being executed.',
577
+ },
578
+ {
579
+ name: 'model',
580
+ type: 'LanguageModel',
581
+ description: 'The model that is being used.',
582
+ },
583
+ {
584
+ name: 'messages',
585
+ type: 'Array<ModelMessage>',
586
+ description:
587
+ 'The messages that will be sent to the model for the current step.',
588
+ },
589
+ {
590
+ name: 'experimental_context',
591
+ type: 'unknown',
592
+ isOptional: true,
593
+ description:
594
+ 'The context passed via the experimental_context setting (experimental).',
595
+ },
596
+ ],
597
+ },
598
+ ],
599
+ },
600
+ ],
601
+ },
602
+ {
603
+ type: 'PrepareStepResult<TOOLS>',
604
+ description:
605
+ 'Return value that can modify settings for the current step.',
606
+ parameters: [
607
+ {
608
+ name: 'model',
609
+ type: 'LanguageModel',
610
+ isOptional: true,
611
+ description:
612
+ 'Optionally override which LanguageModel instance is used for this step.',
613
+ },
614
+ {
615
+ name: 'toolChoice',
616
+ type: 'ToolChoice<TOOLS>',
617
+ isOptional: true,
618
+ description:
619
+ 'Optionally set which tool the model must call, or provide tool call configuration for this step.',
620
+ },
621
+ {
622
+ name: 'activeTools',
623
+ type: 'Array<keyof TOOLS>',
624
+ isOptional: true,
625
+ description:
626
+ 'If provided, only these tools are enabled/available for this step.',
627
+ },
628
+ {
629
+ name: 'system',
630
+ type: 'string | SystemModelMessage | SystemModelMessage[]',
631
+ isOptional: true,
632
+ description:
633
+ 'Optionally override the system message(s) sent to the model for this step.',
634
+ },
635
+ {
636
+ name: 'messages',
637
+ type: 'Array<ModelMessage>',
638
+ isOptional: true,
639
+ description:
640
+ 'Optionally override the full set of messages sent to the model for this step.',
641
+ },
642
+ {
643
+ name: 'experimental_context',
644
+ type: 'unknown',
645
+ isOptional: true,
646
+ description:
647
+ 'Context that is passed into tool execution. Experimental. Changing the context will affect the context in this step and all subsequent steps.',
648
+ },
649
+ {
650
+ name: 'providerOptions',
651
+ type: 'ProviderOptions',
652
+ isOptional: true,
653
+ description:
654
+ 'Additional provider-specific options for this step. Can be used to pass provider-specific configuration such as container IDs for Anthropic code execution.',
655
+ },
656
+ ],
657
+ },
658
+ ],
659
+ },
660
+ {
661
+ name: 'experimental_context',
662
+ type: 'unknown',
663
+ isOptional: true,
664
+ description:
665
+ 'Context that is passed into tool execution. Experimental (can break in patch releases).',
666
+ },
667
+ {
668
+ name: 'experimental_download',
669
+ type: '(requestedDownloads: Array<{ url: URL; isUrlSupportedByModel: boolean }>) => Promise<Array<null | { data: Uint8Array; mediaType?: string }>>',
670
+ isOptional: true,
671
+ description:
672
+ 'Custom download function to control how URLs are fetched when they appear in prompts. By default, files are downloaded if the model does not support the URL for the given media type. Experimental feature. Return null to pass the URL directly to the model (when supported), or return downloaded content with data and media type.',
673
+ },
674
+ {
675
+ name: 'experimental_include',
676
+ type: '{ requestBody?: boolean; responseBody?: boolean }',
677
+ isOptional: true,
678
+ description:
679
+ 'Controls inclusion of request and response bodies in step results. By default, bodies are included. When processing many large payloads (e.g., images), set requestBody and/or responseBody to false to reduce memory usage. Experimental feature.',
680
+ properties: [
681
+ {
682
+ type: 'Object',
683
+ parameters: [
684
+ {
685
+ name: 'requestBody',
686
+ type: 'boolean',
687
+ isOptional: true,
688
+ description:
689
+ 'Whether to include the request body in step results. The request body can be large when sending images or files. Default: true.',
690
+ },
691
+ {
692
+ name: 'responseBody',
693
+ type: 'boolean',
694
+ isOptional: true,
695
+ description:
696
+ 'Whether to include the response body in step results. Default: true.',
697
+ },
698
+ ],
699
+ },
700
+ ],
701
+ },
702
+ {
703
+ name: 'experimental_repairToolCall',
704
+ type: '(options: ToolCallRepairOptions) => Promise<LanguageModelV4ToolCall | null>',
705
+ isOptional: true,
706
+ description:
707
+ 'A function that attempts to repair a tool call that failed to parse. Return either a repaired tool call or null if the tool call cannot be repaired.',
708
+ properties: [
709
+ {
710
+ type: 'ToolCallRepairOptions',
711
+ parameters: [
712
+ {
713
+ name: 'system',
714
+ type: 'string | SystemModelMessage | SystemModelMessage[] | undefined',
715
+ description: 'The system prompt.',
716
+ },
717
+ {
718
+ name: 'messages',
719
+ type: 'ModelMessage[]',
720
+ description: 'The messages in the current generation step.',
721
+ },
722
+ {
723
+ name: 'toolCall',
724
+ type: 'LanguageModelV4ToolCall',
725
+ description: 'The tool call that failed to parse.',
726
+ },
727
+ {
728
+ name: 'tools',
729
+ type: 'TOOLS',
730
+ description: 'The tools that are available.',
731
+ },
732
+ {
733
+ name: 'parameterSchema',
734
+ type: '(options: { toolName: string }) => JSONSchema7',
735
+ description:
736
+ 'A function that returns the JSON Schema for a tool.',
737
+ },
738
+ {
739
+ name: 'error',
740
+ type: 'NoSuchToolError | InvalidToolInputError',
741
+ description:
742
+ 'The error that occurred while parsing the tool call.',
743
+ },
744
+ ],
745
+ },
746
+ ],
747
+ },
748
+ {
749
+ name: 'output',
750
+ type: 'Output',
751
+ isOptional: true,
752
+ description:
753
+ 'Specification for parsing structured outputs from the LLM response.',
754
+ properties: [
755
+ {
756
+ type: 'Output',
757
+ parameters: [
758
+ {
759
+ name: 'Output.text()',
760
+ type: 'Output',
761
+ description:
762
+ 'Output specification for text generation (default).',
763
+ },
764
+ {
765
+ name: 'Output.object()',
766
+ type: 'Output',
767
+ description:
768
+ 'Output specification for typed object generation using schemas. When the model generates a text response, it will return an object that matches the schema.',
769
+ properties: [
770
+ {
771
+ type: 'Options',
772
+ parameters: [
773
+ {
774
+ name: 'schema',
775
+ type: 'Schema<OBJECT>',
776
+ description: 'The schema of the object to generate.',
777
+ },
778
+ {
779
+ name: 'name',
780
+ type: 'string',
781
+ isOptional: true,
782
+ description:
783
+ 'Optional name of the output. Used by some providers for additional LLM guidance.',
784
+ },
785
+ {
786
+ name: 'description',
787
+ type: 'string',
788
+ isOptional: true,
789
+ description:
790
+ 'Optional description of the output. Used by some providers for additional LLM guidance.',
791
+ },
792
+ ],
793
+ },
794
+ ],
795
+ },
796
+ {
797
+ name: 'Output.array()',
798
+ type: 'Output',
799
+ description:
800
+ 'Output specification for array generation. When the model generates a text response, it will return an array of elements.',
801
+ properties: [
802
+ {
803
+ type: 'Options',
804
+ parameters: [
805
+ {
806
+ name: 'element',
807
+ type: 'Schema<ELEMENT>',
808
+ description:
809
+ 'The schema of the array elements to generate.',
810
+ },
811
+ {
812
+ name: 'name',
813
+ type: 'string',
814
+ isOptional: true,
815
+ description:
816
+ 'Optional name of the output. Used by some providers for additional LLM guidance.',
817
+ },
818
+ {
819
+ name: 'description',
820
+ type: 'string',
821
+ isOptional: true,
822
+ description:
823
+ 'Optional description of the output. Used by some providers for additional LLM guidance.',
824
+ },
825
+ ],
826
+ },
827
+ ],
828
+ },
829
+ {
830
+ name: 'Output.choice()',
831
+ type: 'Output',
832
+ description:
833
+ 'Output specification for choice generation. When the model generates a text response, it will return a one of the choice options.',
834
+ properties: [
835
+ {
836
+ type: 'Options',
837
+ parameters: [
838
+ {
839
+ name: 'options',
840
+ type: 'Array<string>',
841
+ description: 'The available choices.',
842
+ },
843
+ {
844
+ name: 'name',
845
+ type: 'string',
846
+ isOptional: true,
847
+ description:
848
+ 'Optional name of the output. Used by some providers for additional LLM guidance.',
849
+ },
850
+ {
851
+ name: 'description',
852
+ type: 'string',
853
+ isOptional: true,
854
+ description:
855
+ 'Optional description of the output. Used by some providers for additional LLM guidance.',
856
+ },
857
+ ],
858
+ },
859
+ ],
860
+ },
861
+ {
862
+ name: 'Output.json()',
863
+ type: 'Output',
864
+ description:
865
+ 'Output specification for unstructured JSON generation. When the model generates a text response, it will return a JSON object.',
866
+ properties: [
867
+ {
868
+ type: 'Options',
869
+ parameters: [
870
+ {
871
+ name: 'name',
872
+ type: 'string',
873
+ isOptional: true,
874
+ description:
875
+ 'Optional name of the output. Used by some providers for additional LLM guidance.',
876
+ },
877
+ {
878
+ name: 'description',
879
+ type: 'string',
880
+ isOptional: true,
881
+ description:
882
+ 'Optional description of the output. Used by some providers for additional LLM guidance.',
883
+ },
884
+ ],
885
+ },
886
+ ],
887
+ },
888
+ ],
889
+ },
890
+ ],
891
+ },
892
+ {
893
+ name: 'experimental_onStart',
894
+ type: '(event: OnStartEvent) => PromiseLike<void> | void',
895
+ isOptional: true,
896
+ description:
897
+ 'Callback that is called when the generateText operation begins, before any LLM calls are made. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).',
898
+ properties: [
899
+ {
900
+ type: 'OnStartEvent',
901
+ parameters: [
902
+ {
903
+ name: 'model',
904
+ type: '{ provider: string; modelId: string }',
905
+ description: 'The model being used for the generation.',
906
+ },
907
+ {
908
+ name: 'system',
909
+ type: 'string | SystemModelMessage | Array<SystemModelMessage> | undefined',
910
+ description: 'The system message(s) provided to the model.',
911
+ },
912
+ {
913
+ name: 'prompt',
914
+ type: 'string | Array<ModelMessage> | undefined',
915
+ description:
916
+ 'The prompt string or array of messages if using the prompt option.',
917
+ },
918
+ {
919
+ name: 'messages',
920
+ type: 'Array<ModelMessage> | undefined',
921
+ description: 'The messages array if using the messages option.',
922
+ },
923
+ {
924
+ name: 'tools',
925
+ type: 'TOOLS | undefined',
926
+ description: 'The tools available for this generation.',
927
+ },
928
+ {
929
+ name: 'toolChoice',
930
+ type: 'ToolChoice<TOOLS> | undefined',
931
+ description: 'The tool choice strategy for this generation.',
932
+ },
933
+ {
934
+ name: 'activeTools',
935
+ type: 'Array<keyof TOOLS> | undefined',
936
+ description:
937
+ 'Limits which tools are available for the model to call.',
938
+ },
939
+ {
940
+ name: 'maxOutputTokens',
941
+ type: 'number | undefined',
942
+ description: 'Maximum number of tokens to generate.',
943
+ },
944
+ {
945
+ name: 'temperature',
946
+ type: 'number | undefined',
947
+ description: 'Sampling temperature for generation.',
948
+ },
949
+ {
950
+ name: 'topP',
951
+ type: 'number | undefined',
952
+ description: 'Top-p (nucleus) sampling parameter.',
953
+ },
954
+ {
955
+ name: 'topK',
956
+ type: 'number | undefined',
957
+ description: 'Top-k sampling parameter.',
958
+ },
959
+ {
960
+ name: 'presencePenalty',
961
+ type: 'number | undefined',
962
+ description: 'Presence penalty for generation.',
963
+ },
964
+ {
965
+ name: 'frequencyPenalty',
966
+ type: 'number | undefined',
967
+ description: 'Frequency penalty for generation.',
968
+ },
969
+ {
970
+ name: 'stopSequences',
971
+ type: 'string[] | undefined',
972
+ description: 'Sequences that will stop generation.',
973
+ },
974
+ {
975
+ name: 'seed',
976
+ type: 'number | undefined',
977
+ description: 'Random seed for reproducible generation.',
978
+ },
979
+ {
980
+ name: 'maxRetries',
981
+ type: 'number',
982
+ description: 'Maximum number of retries for failed requests.',
983
+ },
984
+ {
985
+ name: 'timeout',
986
+ type: 'number | { totalMs?: number; stepMs?: number; chunkMs?: number } | undefined',
987
+ description:
988
+ 'Timeout configuration for the generation. Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs.',
989
+ },
990
+ {
991
+ name: 'headers',
992
+ type: 'Record<string, string | undefined> | undefined',
993
+ description: 'Additional HTTP headers sent with the request.',
994
+ },
995
+ {
996
+ name: 'providerOptions',
997
+ type: 'ProviderOptions | undefined',
998
+ description: 'Additional provider-specific options.',
999
+ },
1000
+ {
1001
+ name: 'stopWhen',
1002
+ type: 'StopCondition<TOOLS> | Array<StopCondition<TOOLS>> | undefined',
1003
+ description:
1004
+ 'Condition(s) for stopping the generation. When the condition is an array, any of the conditions can be met to stop.',
1005
+ },
1006
+ {
1007
+ name: 'output',
1008
+ type: 'OUTPUT | undefined',
1009
+ description:
1010
+ 'The output specification for structured outputs, if configured.',
1011
+ },
1012
+ {
1013
+ name: 'abortSignal',
1014
+ type: 'AbortSignal | undefined',
1015
+ description: 'Abort signal for cancelling the operation.',
1016
+ },
1017
+ {
1018
+ name: 'include',
1019
+ type: '{ requestBody?: boolean; responseBody?: boolean } | undefined',
1020
+ description:
1021
+ 'Settings for controlling what data is included in step results.',
1022
+ },
1023
+ {
1024
+ name: 'functionId',
1025
+ type: 'string | undefined',
1026
+ description:
1027
+ 'Identifier from telemetry settings for grouping related operations.',
1028
+ },
1029
+ {
1030
+ name: 'metadata',
1031
+ type: 'Record<string, unknown> | undefined',
1032
+ description: 'Additional metadata passed to the generation.',
1033
+ },
1034
+ {
1035
+ name: 'experimental_context',
1036
+ type: 'unknown',
1037
+ description:
1038
+ 'User-defined context object that flows through the entire generation lifecycle.',
1039
+ },
1040
+ ],
1041
+ },
1042
+ ],
1043
+ },
1044
+ {
1045
+ name: 'experimental_onStepStart',
1046
+ type: '(event: OnStepStartEvent) => PromiseLike<void> | void',
1047
+ isOptional: true,
1048
+ description:
1049
+ 'Callback that is called when a step (LLM call) begins, before the provider is called. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).',
1050
+ properties: [
1051
+ {
1052
+ type: 'OnStepStartEvent',
1053
+ parameters: [
1054
+ {
1055
+ name: 'stepNumber',
1056
+ type: 'number',
1057
+ description: 'Zero-based index of the current step.',
1058
+ },
1059
+ {
1060
+ name: 'model',
1061
+ type: '{ provider: string; modelId: string }',
1062
+ description: 'The model being used for this step.',
1063
+ },
1064
+ {
1065
+ name: 'system',
1066
+ type: 'string | SystemModelMessage | Array<SystemModelMessage> | undefined',
1067
+ description: 'The system message for this step.',
1068
+ },
1069
+ {
1070
+ name: 'messages',
1071
+ type: 'Array<ModelMessage>',
1072
+ description:
1073
+ 'The messages that will be sent to the model for this step. Uses the user-facing ModelMessage format. May be overridden by prepareStep.',
1074
+ },
1075
+ {
1076
+ name: 'tools',
1077
+ type: 'TOOLS | undefined',
1078
+ description: 'The tools available for this generation.',
1079
+ },
1080
+ {
1081
+ name: 'toolChoice',
1082
+ type: 'LanguageModelV4ToolChoice | undefined',
1083
+ description: 'The tool choice configuration for this step.',
1084
+ },
1085
+ {
1086
+ name: 'activeTools',
1087
+ type: 'Array<keyof TOOLS> | undefined',
1088
+ description: 'Limits which tools are available for this step.',
1089
+ },
1090
+ {
1091
+ name: 'steps',
1092
+ type: 'ReadonlyArray<StepResult<TOOLS>>',
1093
+ description:
1094
+ 'Array of results from previous steps (empty for first step).',
1095
+ },
1096
+ {
1097
+ name: 'providerOptions',
1098
+ type: 'ProviderOptions | undefined',
1099
+ description:
1100
+ 'Additional provider-specific options for this step.',
1101
+ },
1102
+ {
1103
+ name: 'timeout',
1104
+ type: 'number | { totalMs?: number; stepMs?: number; chunkMs?: number } | undefined',
1105
+ description:
1106
+ 'Timeout configuration for the generation. Can be a number (milliseconds) or an object with totalMs, stepMs, chunkMs.',
1107
+ },
1108
+ {
1109
+ name: 'headers',
1110
+ type: 'Record<string, string | undefined> | undefined',
1111
+ description: 'Additional HTTP headers sent with the request.',
1112
+ },
1113
+ {
1114
+ name: 'stopWhen',
1115
+ type: 'StopCondition<TOOLS> | Array<StopCondition<TOOLS>> | undefined',
1116
+ description:
1117
+ 'Condition(s) for stopping the generation. When the condition is an array, any of the conditions can be met to stop.',
1118
+ },
1119
+ {
1120
+ name: 'output',
1121
+ type: 'OUTPUT | undefined',
1122
+ description:
1123
+ 'The output specification for structured outputs, if configured.',
1124
+ },
1125
+ {
1126
+ name: 'abortSignal',
1127
+ type: 'AbortSignal | undefined',
1128
+ description: 'Abort signal for cancelling the operation.',
1129
+ },
1130
+ {
1131
+ name: 'include',
1132
+ type: '{ requestBody?: boolean; responseBody?: boolean } | undefined',
1133
+ description:
1134
+ 'Settings for controlling what data is included in step results.',
1135
+ },
1136
+ {
1137
+ name: 'functionId',
1138
+ type: 'string | undefined',
1139
+ description:
1140
+ 'Identifier from telemetry settings for grouping related operations.',
1141
+ },
1142
+ {
1143
+ name: 'metadata',
1144
+ type: 'Record<string, unknown> | undefined',
1145
+ description: 'Additional metadata from telemetry settings.',
1146
+ },
1147
+ {
1148
+ name: 'experimental_context',
1149
+ type: 'unknown',
1150
+ description:
1151
+ 'User-defined context object. May be updated from prepareStep between steps.',
1152
+ },
1153
+ ],
1154
+ },
1155
+ ],
1156
+ },
1157
+ {
1158
+ name: 'experimental_onToolCallStart',
1159
+ type: '(event: OnToolCallStartEvent) => PromiseLike<void> | void',
1160
+ isOptional: true,
1161
+ description:
1162
+ "Callback that is called right before a tool's execute function runs. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).",
1163
+ properties: [
1164
+ {
1165
+ type: 'OnToolCallStartEvent',
1166
+ parameters: [
1167
+ {
1168
+ name: 'stepNumber',
1169
+ type: 'number | undefined',
1170
+ description:
1171
+ 'The zero-based index of the current step where this tool call occurs. May be undefined in streaming contexts.',
1172
+ },
1173
+ {
1174
+ name: 'model',
1175
+ type: '{ provider: string; modelId: string } | undefined',
1176
+ description:
1177
+ 'Information about the model being used. May be undefined in streaming contexts.',
1178
+ },
1179
+ {
1180
+ name: 'toolCall',
1181
+ type: 'TypedToolCall<TOOLS>',
1182
+ description:
1183
+ 'The full tool call object containing toolName, toolCallId, input, and metadata.',
1184
+ },
1185
+ {
1186
+ name: 'messages',
1187
+ type: 'Array<ModelMessage>',
1188
+ description:
1189
+ 'The conversation messages available at tool execution time.',
1190
+ },
1191
+ {
1192
+ name: 'abortSignal',
1193
+ type: 'AbortSignal | undefined',
1194
+ description: 'Signal for cancelling the operation.',
1195
+ },
1196
+ {
1197
+ name: 'functionId',
1198
+ type: 'string | undefined',
1199
+ description:
1200
+ 'Identifier from telemetry settings for grouping related operations.',
1201
+ },
1202
+ {
1203
+ name: 'metadata',
1204
+ type: 'Record<string, unknown> | undefined',
1205
+ description: 'Additional metadata from telemetry settings.',
1206
+ },
1207
+ {
1208
+ name: 'experimental_context',
1209
+ type: 'unknown',
1210
+ description:
1211
+ 'User-defined context object flowing through the generation.',
1212
+ },
1213
+ ],
1214
+ },
1215
+ ],
1216
+ },
1217
+ {
1218
+ name: 'experimental_onToolCallFinish',
1219
+ type: '(event: OnToolCallFinishEvent) => PromiseLike<void> | void',
1220
+ isOptional: true,
1221
+ description:
1222
+ "Callback that is called right after a tool's execute function completes (or errors). Uses a discriminated union on the `success` field: when `success: true`, `output` contains the tool result; when `success: false`, `error` contains the error. Errors thrown in this callback are silently caught and do not break the generation flow. Experimental (can break in patch releases).",
1223
+ properties: [
1224
+ {
1225
+ type: 'OnToolCallFinishEvent',
1226
+ parameters: [
1227
+ {
1228
+ name: 'stepNumber',
1229
+ type: 'number | undefined',
1230
+ description:
1231
+ 'The zero-based index of the current step where this tool call occurred. May be undefined in streaming contexts.',
1232
+ },
1233
+ {
1234
+ name: 'model',
1235
+ type: '{ provider: string; modelId: string } | undefined',
1236
+ description:
1237
+ 'Information about the model being used. May be undefined in streaming contexts.',
1238
+ },
1239
+ {
1240
+ name: 'toolCall',
1241
+ type: 'TypedToolCall<TOOLS>',
1242
+ description:
1243
+ 'The full tool call object containing toolName, toolCallId, input, and metadata.',
1244
+ },
1245
+ {
1246
+ name: 'messages',
1247
+ type: 'Array<ModelMessage>',
1248
+ description:
1249
+ 'The conversation messages available at tool execution time.',
1250
+ },
1251
+ {
1252
+ name: 'abortSignal',
1253
+ type: 'AbortSignal | undefined',
1254
+ description: 'Signal for cancelling the operation.',
1255
+ },
1256
+ {
1257
+ name: 'durationMs',
1258
+ type: 'number',
1259
+ description:
1260
+ 'The wall-clock duration of the tool execution in milliseconds.',
1261
+ },
1262
+ {
1263
+ name: 'functionId',
1264
+ type: 'string | undefined',
1265
+ description:
1266
+ 'Identifier from telemetry settings for grouping related operations.',
1267
+ },
1268
+ {
1269
+ name: 'metadata',
1270
+ type: 'Record<string, unknown> | undefined',
1271
+ description: 'Additional metadata from telemetry settings.',
1272
+ },
1273
+ {
1274
+ name: 'experimental_context',
1275
+ type: 'unknown',
1276
+ description:
1277
+ 'User-defined context object flowing through the generation.',
1278
+ },
1279
+ {
1280
+ name: 'success',
1281
+ type: 'boolean',
1282
+ description:
1283
+ 'Discriminator indicating whether the tool call succeeded. When true, output is available. When false, error is available.',
1284
+ },
1285
+ {
1286
+ name: 'output',
1287
+ type: 'unknown',
1288
+ description:
1289
+ "The tool's return value (only present when `success: true`).",
1290
+ },
1291
+ {
1292
+ name: 'error',
1293
+ type: 'unknown',
1294
+ description:
1295
+ 'The error that occurred during tool execution (only present when `success: false`).',
1296
+ },
1297
+ ],
1298
+ },
1299
+ ],
1300
+ },
1301
+ {
1302
+ name: 'onStepFinish',
1303
+ type: '(stepResult: StepResult<TOOLS>) => Promise<void> | void',
1304
+ isOptional: true,
1305
+ description:
1306
+ 'Callback that is called when a step is finished. Receives a StepResult object.',
1307
+ properties: [
1308
+ {
1309
+ type: 'StepResult',
1310
+ parameters: [
1311
+ {
1312
+ name: 'stepNumber',
1313
+ type: 'number',
1314
+ description: 'Zero-based index of this step.',
1315
+ },
1316
+ {
1317
+ name: 'model',
1318
+ type: '{ provider: string; modelId: string }',
1319
+ description:
1320
+ 'Information about the model that produced this step.',
1321
+ },
1322
+ {
1323
+ name: 'functionId',
1324
+ type: 'string | undefined',
1325
+ description:
1326
+ 'Identifier from telemetry settings for grouping related operations.',
1327
+ },
1328
+ {
1329
+ name: 'metadata',
1330
+ type: 'Record<string, unknown> | undefined',
1331
+ description: 'Additional metadata from telemetry settings.',
1332
+ },
1333
+ {
1334
+ name: 'experimental_context',
1335
+ type: 'unknown',
1336
+ description:
1337
+ 'User-defined context object flowing through the generation.',
1338
+ },
1339
+ {
1340
+ name: 'content',
1341
+ type: 'Array<ContentPart<TOOLS>>',
1342
+ description: 'The content that was generated in this step.',
1343
+ },
1344
+ {
1345
+ name: 'text',
1346
+ type: 'string',
1347
+ description: 'The generated text.',
1348
+ },
1349
+ {
1350
+ name: 'reasoning',
1351
+ type: 'Array<ReasoningPart | ReasoningFilePart>',
1352
+ description:
1353
+ 'The reasoning that was generated during the generation.',
1354
+ },
1355
+ {
1356
+ name: 'reasoningText',
1357
+ type: 'string | undefined',
1358
+ description:
1359
+ 'The reasoning text that was generated during the generation.',
1360
+ },
1361
+ {
1362
+ name: 'files',
1363
+ type: 'Array<GeneratedFile>',
1364
+ description:
1365
+ 'The files that were generated during the generation.',
1366
+ },
1367
+ {
1368
+ name: 'sources',
1369
+ type: 'Array<Source>',
1370
+ description: 'The sources that were used to generate the text.',
1371
+ },
1372
+ {
1373
+ name: 'toolCalls',
1374
+ type: 'Array<TypedToolCall<TOOLS>>',
1375
+ description:
1376
+ 'The tool calls that were made during the generation.',
1377
+ },
1378
+ {
1379
+ name: 'staticToolCalls',
1380
+ type: 'Array<StaticToolCall<TOOLS>>',
1381
+ description: 'The static tool calls that were made in this step.',
1382
+ },
1383
+ {
1384
+ name: 'dynamicToolCalls',
1385
+ type: 'Array<DynamicToolCall>',
1386
+ description:
1387
+ 'The dynamic tool calls that were made in this step.',
1388
+ },
1389
+ {
1390
+ name: 'toolResults',
1391
+ type: 'Array<TypedToolResult<TOOLS>>',
1392
+ description: 'The results of the tool calls.',
1393
+ },
1394
+ {
1395
+ name: 'staticToolResults',
1396
+ type: 'Array<StaticToolResult<TOOLS>>',
1397
+ description:
1398
+ 'The static tool results that were made in this step.',
1399
+ },
1400
+ {
1401
+ name: 'dynamicToolResults',
1402
+ type: 'Array<DynamicToolResult>',
1403
+ description:
1404
+ 'The dynamic tool results that were made in this step.',
1405
+ },
1406
+ {
1407
+ name: 'finishReason',
1408
+ type: '"stop" | "length" | "content-filter" | "tool-calls" | "error" | "other"',
1409
+ description: 'The unified reason why the generation finished.',
1410
+ },
1411
+ {
1412
+ name: 'rawFinishReason',
1413
+ type: 'string | undefined',
1414
+ description:
1415
+ 'The raw reason why the generation finished (from the provider).',
1416
+ },
1417
+ {
1418
+ name: 'usage',
1419
+ type: 'LanguageModelUsage',
1420
+ description: 'The token usage of the generated text.',
1421
+ properties: [
1422
+ {
1423
+ type: 'LanguageModelUsage',
1424
+ parameters: [
1425
+ {
1426
+ name: 'inputTokens',
1427
+ type: 'number | undefined',
1428
+ description:
1429
+ 'The total number of input (prompt) tokens used.',
1430
+ },
1431
+ {
1432
+ name: 'inputTokenDetails',
1433
+ type: 'LanguageModelInputTokenDetails',
1434
+ description:
1435
+ 'Detailed information about the input (prompt) tokens.',
1436
+ properties: [
1437
+ {
1438
+ type: 'LanguageModelInputTokenDetails',
1439
+ parameters: [
1440
+ {
1441
+ name: 'noCacheTokens',
1442
+ type: 'number | undefined',
1443
+ description:
1444
+ 'The number of non-cached input (prompt) tokens used.',
1445
+ },
1446
+ {
1447
+ name: 'cacheReadTokens',
1448
+ type: 'number | undefined',
1449
+ description:
1450
+ 'The number of cached input (prompt) tokens read.',
1451
+ },
1452
+ {
1453
+ name: 'cacheWriteTokens',
1454
+ type: 'number | undefined',
1455
+ description:
1456
+ 'The number of cached input (prompt) tokens written.',
1457
+ },
1458
+ ],
1459
+ },
1460
+ ],
1461
+ },
1462
+ {
1463
+ name: 'outputTokens',
1464
+ type: 'number | undefined',
1465
+ description:
1466
+ 'The number of total output (completion) tokens used.',
1467
+ },
1468
+ {
1469
+ name: 'outputTokenDetails',
1470
+ type: 'LanguageModelOutputTokenDetails',
1471
+ description:
1472
+ 'Detailed information about the output (completion) tokens.',
1473
+ properties: [
1474
+ {
1475
+ type: 'LanguageModelOutputTokenDetails',
1476
+ parameters: [
1477
+ {
1478
+ name: 'textTokens',
1479
+ type: 'number | undefined',
1480
+ description: 'The number of text tokens used.',
1481
+ },
1482
+ {
1483
+ name: 'reasoningTokens',
1484
+ type: 'number | undefined',
1485
+ description:
1486
+ 'The number of reasoning tokens used.',
1487
+ },
1488
+ ],
1489
+ },
1490
+ ],
1491
+ },
1492
+ {
1493
+ name: 'totalTokens',
1494
+ type: 'number | undefined',
1495
+ description: 'The total number of tokens used.',
1496
+ },
1497
+ {
1498
+ name: 'raw',
1499
+ type: 'object | undefined',
1500
+ isOptional: true,
1501
+ description:
1502
+ "Raw usage information from the provider. This is the provider's original usage information and may include additional fields.",
1503
+ },
1504
+ ],
1505
+ },
1506
+ ],
1507
+ },
1508
+ {
1509
+ name: 'warnings',
1510
+ type: 'CallWarning[] | undefined',
1511
+ description:
1512
+ 'Warnings from the model provider (e.g. unsupported settings).',
1513
+ },
1514
+ {
1515
+ name: 'request',
1516
+ type: 'LanguageModelRequestMetadata',
1517
+ description: 'Additional request information.',
1518
+ },
1519
+ {
1520
+ name: 'response',
1521
+ type: 'LanguageModelResponseMetadata & { messages: Array<ResponseMessage>; body?: unknown }',
1522
+ description: 'Additional response information.',
1523
+ properties: [
1524
+ {
1525
+ type: 'Response',
1526
+ parameters: [
1527
+ {
1528
+ name: 'id',
1529
+ type: 'string',
1530
+ description:
1531
+ 'The response identifier. The AI SDK uses the ID from the provider response when available, and generates an ID otherwise.',
1532
+ },
1533
+ {
1534
+ name: 'modelId',
1535
+ type: 'string',
1536
+ description:
1537
+ 'The model that was used to generate the response.',
1538
+ },
1539
+ {
1540
+ name: 'timestamp',
1541
+ type: 'Date',
1542
+ description: 'The timestamp of the response.',
1543
+ },
1544
+ {
1545
+ name: 'headers',
1546
+ isOptional: true,
1547
+ type: 'Record<string, string>',
1548
+ description: 'Optional response headers.',
1549
+ },
1550
+ {
1551
+ name: 'messages',
1552
+ type: 'Array<ResponseMessage>',
1553
+ description:
1554
+ 'The response messages that were generated during the call.',
1555
+ },
1556
+ {
1557
+ name: 'body',
1558
+ isOptional: true,
1559
+ type: 'unknown',
1560
+ description:
1561
+ 'Response body (available only for providers that use HTTP requests).',
1562
+ },
1563
+ ],
1564
+ },
1565
+ ],
1566
+ },
1567
+ {
1568
+ name: 'providerMetadata',
1569
+ type: 'ProviderMetadata | undefined',
1570
+ isOptional: true,
1571
+ description:
1572
+ 'Additional provider-specific metadata. They are passed through from the provider to the AI SDK and enable provider-specific results that can be fully encapsulated in the provider.',
1573
+ },
1574
+ ],
1575
+ },
1576
+ ],
1577
+ },
1578
+ {
1579
+ name: 'onFinish',
1580
+ type: '(event: StepResult<TOOLS> & { steps: StepResult<TOOLS>[]; totalUsage: LanguageModelUsage }) => PromiseLike<void> | void',
1581
+ isOptional: true,
1582
+ description:
1583
+ 'Callback that is called when the entire generation completes (all steps finished). The event includes the final step result properties along with aggregated data from all steps.',
1584
+ properties: [
1585
+ {
1586
+ type: 'OnFinishEvent',
1587
+ parameters: [
1588
+ {
1589
+ name: 'stepNumber',
1590
+ type: 'number',
1591
+ description: 'Zero-based index of the final step.',
1592
+ },
1593
+ {
1594
+ name: 'model',
1595
+ type: '{ provider: string; modelId: string }',
1596
+ description:
1597
+ 'Information about the model that produced the final step.',
1598
+ },
1599
+ {
1600
+ name: 'functionId',
1601
+ type: 'string | undefined',
1602
+ description:
1603
+ 'Identifier from telemetry settings for grouping related operations.',
1604
+ },
1605
+ {
1606
+ name: 'metadata',
1607
+ type: 'Record<string, unknown> | undefined',
1608
+ description: 'Additional metadata from telemetry settings.',
1609
+ },
1610
+ {
1611
+ name: 'finishReason',
1612
+ type: '"stop" | "length" | "content-filter" | "tool-calls" | "error" | "other"',
1613
+ description: 'The unified reason why the generation finished.',
1614
+ },
1615
+ {
1616
+ name: 'rawFinishReason',
1617
+ type: 'string | undefined',
1618
+ description:
1619
+ 'The raw reason why the generation finished (from the provider).',
1620
+ },
1621
+ {
1622
+ name: 'usage',
1623
+ type: 'LanguageModelUsage',
1624
+ description:
1625
+ 'The token usage from the final step only (not aggregated).',
1626
+ properties: [
1627
+ {
1628
+ type: 'LanguageModelUsage',
1629
+ parameters: [
1630
+ {
1631
+ name: 'inputTokens',
1632
+ type: 'number | undefined',
1633
+ description:
1634
+ 'The total number of input (prompt) tokens used.',
1635
+ },
1636
+ {
1637
+ name: 'inputTokenDetails',
1638
+ type: 'LanguageModelInputTokenDetails',
1639
+ description:
1640
+ 'Detailed information about the input (prompt) tokens.',
1641
+ properties: [
1642
+ {
1643
+ type: 'LanguageModelInputTokenDetails',
1644
+ parameters: [
1645
+ {
1646
+ name: 'noCacheTokens',
1647
+ type: 'number | undefined',
1648
+ description:
1649
+ 'The number of non-cached input (prompt) tokens used.',
1650
+ },
1651
+ {
1652
+ name: 'cacheReadTokens',
1653
+ type: 'number | undefined',
1654
+ description:
1655
+ 'The number of cached input (prompt) tokens read.',
1656
+ },
1657
+ {
1658
+ name: 'cacheWriteTokens',
1659
+ type: 'number | undefined',
1660
+ description:
1661
+ 'The number of cached input (prompt) tokens written.',
1662
+ },
1663
+ ],
1664
+ },
1665
+ ],
1666
+ },
1667
+ {
1668
+ name: 'outputTokens',
1669
+ type: 'number | undefined',
1670
+ description:
1671
+ 'The number of total output (completion) tokens used.',
1672
+ },
1673
+ {
1674
+ name: 'outputTokenDetails',
1675
+ type: 'LanguageModelOutputTokenDetails',
1676
+ description:
1677
+ 'Detailed information about the output (completion) tokens.',
1678
+ properties: [
1679
+ {
1680
+ type: 'LanguageModelOutputTokenDetails',
1681
+ parameters: [
1682
+ {
1683
+ name: 'textTokens',
1684
+ type: 'number | undefined',
1685
+ description: 'The number of text tokens used.',
1686
+ },
1687
+ {
1688
+ name: 'reasoningTokens',
1689
+ type: 'number | undefined',
1690
+ description:
1691
+ 'The number of reasoning tokens used.',
1692
+ },
1693
+ ],
1694
+ },
1695
+ ],
1696
+ },
1697
+ {
1698
+ name: 'totalTokens',
1699
+ type: 'number | undefined',
1700
+ description: 'The total number of tokens used.',
1701
+ },
1702
+ {
1703
+ name: 'raw',
1704
+ type: 'object | undefined',
1705
+ isOptional: true,
1706
+ description:
1707
+ "Raw usage information from the provider. This is the provider's original usage information and may include additional fields.",
1708
+ },
1709
+ ],
1710
+ },
1711
+ ],
1712
+ },
1713
+ {
1714
+ name: 'totalUsage',
1715
+ type: 'LanguageModelUsage',
1716
+ description:
1717
+ 'Aggregated token usage across all steps. This is the sum of the usage from each individual step.',
1718
+ properties: [
1719
+ {
1720
+ type: 'LanguageModelUsage',
1721
+ parameters: [
1722
+ {
1723
+ name: 'inputTokens',
1724
+ type: 'number | undefined',
1725
+ description:
1726
+ 'The total number of input (prompt) tokens used across all steps.',
1727
+ },
1728
+ {
1729
+ name: 'outputTokens',
1730
+ type: 'number | undefined',
1731
+ description:
1732
+ 'The total number of output (completion) tokens used across all steps.',
1733
+ },
1734
+ {
1735
+ name: 'totalTokens',
1736
+ type: 'number | undefined',
1737
+ description:
1738
+ 'The total number of tokens used across all steps.',
1739
+ },
1740
+ ],
1741
+ },
1742
+ ],
1743
+ },
1744
+ {
1745
+ name: 'content',
1746
+ type: 'Array<ContentPart<TOOLS>>',
1747
+ description: 'The content that was generated in the final step.',
1748
+ },
1749
+ {
1750
+ name: 'providerMetadata',
1751
+ type: 'ProviderMetadata | undefined',
1752
+ description:
1753
+ 'Additional provider-specific metadata from the final step.',
1754
+ },
1755
+ {
1756
+ name: 'text',
1757
+ type: 'string',
1758
+ description: 'The full text that has been generated.',
1759
+ },
1760
+ {
1761
+ name: 'reasoningText',
1762
+ type: 'string | undefined',
1763
+ description:
1764
+ 'The reasoning text of the model (only available for some models).',
1765
+ },
1766
+ {
1767
+ name: 'reasoning',
1768
+ type: 'Array<ReasoningDetail>',
1769
+ description:
1770
+ 'The reasoning details of the model (only available for some models).',
1771
+ properties: [
1772
+ {
1773
+ type: 'ReasoningDetail',
1774
+ parameters: [
1775
+ {
1776
+ name: 'type',
1777
+ type: "'text'",
1778
+ description: 'The type of the reasoning detail.',
1779
+ },
1780
+ {
1781
+ name: 'text',
1782
+ type: 'string',
1783
+ description: 'The text content (only for type "text").',
1784
+ },
1785
+ {
1786
+ name: 'signature',
1787
+ type: 'string',
1788
+ isOptional: true,
1789
+ description: 'Optional signature (only for type "text").',
1790
+ },
1791
+ ],
1792
+ },
1793
+ {
1794
+ type: 'ReasoningDetail',
1795
+ parameters: [
1796
+ {
1797
+ name: 'type',
1798
+ type: "'redacted'",
1799
+ description: 'The type of the reasoning detail.',
1800
+ },
1801
+ {
1802
+ name: 'data',
1803
+ type: 'string',
1804
+ description:
1805
+ 'The redacted data content (only for type "redacted").',
1806
+ },
1807
+ ],
1808
+ },
1809
+ ],
1810
+ },
1811
+ {
1812
+ name: 'sources',
1813
+ type: 'Array<Source>',
1814
+ description:
1815
+ 'Sources that have been used as input to generate the response. For multi-step generation, the sources are accumulated from all steps.',
1816
+ properties: [
1817
+ {
1818
+ type: 'Source',
1819
+ parameters: [
1820
+ {
1821
+ name: 'sourceType',
1822
+ type: "'url'",
1823
+ description:
1824
+ 'A URL source. This is return by web search RAG models.',
1825
+ },
1826
+ {
1827
+ name: 'id',
1828
+ type: 'string',
1829
+ description: 'The ID of the source.',
1830
+ },
1831
+ {
1832
+ name: 'url',
1833
+ type: 'string',
1834
+ description: 'The URL of the source.',
1835
+ },
1836
+ {
1837
+ name: 'title',
1838
+ type: 'string',
1839
+ isOptional: true,
1840
+ description: 'The title of the source.',
1841
+ },
1842
+ {
1843
+ name: 'providerMetadata',
1844
+ type: 'SharedV2ProviderMetadata',
1845
+ isOptional: true,
1846
+ description:
1847
+ 'Additional provider metadata for the source.',
1848
+ },
1849
+ ],
1850
+ },
1851
+ ],
1852
+ },
1853
+ {
1854
+ name: 'files',
1855
+ type: 'Array<GeneratedFile>',
1856
+ description: 'Files that were generated in the final step.',
1857
+ properties: [
1858
+ {
1859
+ type: 'GeneratedFile',
1860
+ parameters: [
1861
+ {
1862
+ name: 'base64',
1863
+ type: 'string',
1864
+ description: 'File as a base64 encoded string.',
1865
+ },
1866
+ {
1867
+ name: 'uint8Array',
1868
+ type: 'Uint8Array',
1869
+ description: 'File as a Uint8Array.',
1870
+ },
1871
+ {
1872
+ name: 'mediaType',
1873
+ type: 'string',
1874
+ description: 'The IANA media type of the file.',
1875
+ },
1876
+ ],
1877
+ },
1878
+ ],
1879
+ },
1880
+ {
1881
+ name: 'toolCalls',
1882
+ type: 'Array<TypedToolCall<TOOLS>>',
1883
+ description:
1884
+ 'The tool calls that were made during the generation.',
1885
+ },
1886
+ {
1887
+ name: 'staticToolCalls',
1888
+ type: 'Array<StaticToolCall<TOOLS>>',
1889
+ description:
1890
+ 'The static tool calls that were made in the final step.',
1891
+ },
1892
+ {
1893
+ name: 'dynamicToolCalls',
1894
+ type: 'Array<DynamicToolCall>',
1895
+ description:
1896
+ 'The dynamic tool calls that were made in the final step.',
1897
+ },
1898
+ {
1899
+ name: 'toolResults',
1900
+ type: 'Array<TypedToolResult<TOOLS>>',
1901
+ description: 'The results of the tool calls.',
1902
+ },
1903
+ {
1904
+ name: 'staticToolResults',
1905
+ type: 'Array<StaticToolResult<TOOLS>>',
1906
+ description:
1907
+ 'The static tool results that were made in the final step.',
1908
+ },
1909
+ {
1910
+ name: 'dynamicToolResults',
1911
+ type: 'Array<DynamicToolResult>',
1912
+ description:
1913
+ 'The dynamic tool results that were made in the final step.',
1914
+ },
1915
+ {
1916
+ name: 'warnings',
1917
+ type: 'CallWarning[] | undefined',
1918
+ description:
1919
+ 'Warnings from the model provider (e.g. unsupported settings).',
1920
+ },
1921
+ {
1922
+ name: 'request',
1923
+ type: 'LanguageModelRequestMetadata',
1924
+ description:
1925
+ 'Additional request information from the final step.',
1926
+ },
1927
+ {
1928
+ name: 'response',
1929
+ type: 'LanguageModelResponseMetadata & { messages: Array<ResponseMessage>; body?: unknown }',
1930
+ description:
1931
+ 'Additional response information from the final step.',
1932
+ properties: [
1933
+ {
1934
+ type: 'Response',
1935
+ parameters: [
1936
+ {
1937
+ name: 'id',
1938
+ type: 'string',
1939
+ description:
1940
+ 'The response identifier. The AI SDK uses the ID from the provider response when available, and generates an ID otherwise.',
1941
+ },
1942
+ {
1943
+ name: 'modelId',
1944
+ type: 'string',
1945
+ description:
1946
+ 'The model that was used to generate the response. The AI SDK uses the response model from the provider response when available, and the model from the function call otherwise.',
1947
+ },
1948
+ {
1949
+ name: 'timestamp',
1950
+ type: 'Date',
1951
+ description:
1952
+ 'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
1953
+ },
1954
+ {
1955
+ name: 'headers',
1956
+ isOptional: true,
1957
+ type: 'Record<string, string>',
1958
+ description: 'Optional response headers.',
1959
+ },
1960
+ {
1961
+ name: 'messages',
1962
+ type: 'Array<ResponseMessage>',
1963
+ description:
1964
+ 'The response messages that were generated during the call. It consists of an assistant message, potentially containing tool calls. When there are tool results, there is an additional tool message with the tool results that are available. If there are tools that do not have execute functions, they are not included in the tool results and need to be added separately.',
1965
+ },
1966
+ ],
1967
+ },
1968
+ ],
1969
+ },
1970
+ {
1971
+ name: 'steps',
1972
+ type: 'Array<StepResult>',
1973
+ description:
1974
+ 'Response information for every step. You can use this to get information about intermediate steps, such as the tool calls or the response headers.',
1975
+ },
1976
+ {
1977
+ name: 'experimental_context',
1978
+ type: 'unknown',
1979
+ description:
1980
+ 'The final state of the user-defined context object. This reflects any modifications made during the generation lifecycle via prepareStep or tool execution.',
1981
+ },
1982
+ ],
1983
+ },
1984
+ ],
1985
+ },
1986
+ ]}
1987
+ />
1988
+
1989
+ ### Returns
1990
+
1991
+ <PropertiesTable
1992
+ content={[
1993
+ {
1994
+ name: 'content',
1995
+ type: 'Array<ContentPart<TOOLS>>',
1996
+ description: 'The content that was generated in the last step.',
1997
+ },
1998
+ {
1999
+ name: 'text',
2000
+ type: 'string',
2001
+ description: 'The generated text by the model.',
2002
+ },
2003
+ {
2004
+ name: 'reasoning',
2005
+ type: 'Array<ReasoningOutput | ReasoningFileOutput>',
2006
+ description:
2007
+ 'The full reasoning that the model has generated in the last step.',
2008
+ properties: [
2009
+ {
2010
+ type: 'ReasoningOutput',
2011
+ parameters: [
2012
+ {
2013
+ name: 'type',
2014
+ type: "'reasoning'",
2015
+ description: 'The type of the message part.',
2016
+ },
2017
+ {
2018
+ name: 'text',
2019
+ type: 'string',
2020
+ description: 'The reasoning text.',
2021
+ },
2022
+ {
2023
+ name: 'providerMetadata',
2024
+ type: 'SharedV2ProviderMetadata',
2025
+ isOptional: true,
2026
+ description: 'Additional provider metadata.',
2027
+ },
2028
+ ],
2029
+ },
2030
+ {
2031
+ type: 'ReasoningFileOutput',
2032
+ parameters: [
2033
+ {
2034
+ name: 'type',
2035
+ type: "'reasoning-file'",
2036
+ description: 'The type of the message part.',
2037
+ },
2038
+ {
2039
+ name: 'file',
2040
+ type: 'GeneratedFile',
2041
+ description: 'The generated file.',
2042
+ },
2043
+ {
2044
+ name: 'providerMetadata',
2045
+ type: 'SharedV2ProviderMetadata',
2046
+ isOptional: true,
2047
+ description: 'Additional provider metadata.',
2048
+ },
2049
+ ],
2050
+ },
2051
+ ],
2052
+ },
2053
+ {
2054
+ name: 'reasoningText',
2055
+ type: 'string | undefined',
2056
+ description:
2057
+ 'The reasoning text that the model has generated in the last step. Can be undefined if the model has only generated text.',
2058
+ },
2059
+ {
2060
+ name: 'sources',
2061
+ type: 'Array<Source>',
2062
+ description:
2063
+ 'Sources that have been used as input to generate the response. For multi-step generation, the sources are accumulated from all steps.',
2064
+ properties: [
2065
+ {
2066
+ type: 'Source',
2067
+ parameters: [
2068
+ {
2069
+ name: 'sourceType',
2070
+ type: "'url'",
2071
+ description:
2072
+ 'A URL source. This is return by web search RAG models.',
2073
+ },
2074
+ {
2075
+ name: 'id',
2076
+ type: 'string',
2077
+ description: 'The ID of the source.',
2078
+ },
2079
+ {
2080
+ name: 'url',
2081
+ type: 'string',
2082
+ description: 'The URL of the source.',
2083
+ },
2084
+ {
2085
+ name: 'title',
2086
+ type: 'string',
2087
+ isOptional: true,
2088
+ description: 'The title of the source.',
2089
+ },
2090
+ {
2091
+ name: 'providerMetadata',
2092
+ type: 'SharedV2ProviderMetadata',
2093
+ isOptional: true,
2094
+ description: 'Additional provider metadata for the source.',
2095
+ },
2096
+ ],
2097
+ },
2098
+ ],
2099
+ },
2100
+ {
2101
+ name: 'files',
2102
+ type: 'Array<GeneratedFile>',
2103
+ description: 'Files that were generated in the final step.',
2104
+ properties: [
2105
+ {
2106
+ type: 'GeneratedFile',
2107
+ parameters: [
2108
+ {
2109
+ name: 'base64',
2110
+ type: 'string',
2111
+ description: 'File as a base64 encoded string.',
2112
+ },
2113
+ {
2114
+ name: 'uint8Array',
2115
+ type: 'Uint8Array',
2116
+ description: 'File as a Uint8Array.',
2117
+ },
2118
+ {
2119
+ name: 'mediaType',
2120
+ type: 'string',
2121
+ description: 'The IANA media type of the file.',
2122
+ },
2123
+ ],
2124
+ },
2125
+ ],
2126
+ },
2127
+ {
2128
+ name: 'toolCalls',
2129
+ type: 'ToolCallArray<TOOLS>',
2130
+ description: 'The tool calls that were made in the last step.',
2131
+ },
2132
+ {
2133
+ name: 'toolResults',
2134
+ type: 'ToolResultArray<TOOLS>',
2135
+ description: 'The results of the tool calls from the last step.',
2136
+ },
2137
+ {
2138
+ name: 'staticToolCalls',
2139
+ type: 'Array<StaticToolCall<TOOLS>>',
2140
+ description:
2141
+ 'The static tool calls that have been executed in the last step.',
2142
+ },
2143
+ {
2144
+ name: 'dynamicToolCalls',
2145
+ type: 'Array<DynamicToolCall>',
2146
+ description:
2147
+ 'The dynamic tool calls that have been executed in the last step.',
2148
+ },
2149
+ {
2150
+ name: 'staticToolResults',
2151
+ type: 'Array<StaticToolResult<TOOLS>>',
2152
+ description:
2153
+ 'The static tool results that have been generated in the last step.',
2154
+ },
2155
+ {
2156
+ name: 'dynamicToolResults',
2157
+ type: 'Array<DynamicToolResult>',
2158
+ description:
2159
+ 'The dynamic tool results that have been generated in the last step.',
2160
+ },
2161
+ {
2162
+ name: 'finishReason',
2163
+ type: "'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other'",
2164
+ description: 'The reason the model finished generating the text.',
2165
+ },
2166
+ {
2167
+ name: 'rawFinishReason',
2168
+ type: 'string | undefined',
2169
+ description:
2170
+ 'The raw reason why the generation finished (from the provider).',
2171
+ },
2172
+ {
2173
+ name: 'usage',
2174
+ type: 'LanguageModelUsage',
2175
+ description: 'The token usage of the last step.',
2176
+ properties: [
2177
+ {
2178
+ type: 'LanguageModelUsage',
2179
+ parameters: [
2180
+ {
2181
+ name: 'inputTokens',
2182
+ type: 'number | undefined',
2183
+ description: 'The total number of input (prompt) tokens used.',
2184
+ },
2185
+ {
2186
+ name: 'inputTokenDetails',
2187
+ type: 'LanguageModelInputTokenDetails',
2188
+ description:
2189
+ 'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
2190
+ properties: [
2191
+ {
2192
+ type: 'LanguageModelInputTokenDetails',
2193
+ parameters: [
2194
+ {
2195
+ name: 'noCacheTokens',
2196
+ type: 'number | undefined',
2197
+ description:
2198
+ 'The number of non-cached input (prompt) tokens used.',
2199
+ },
2200
+ {
2201
+ name: 'cacheReadTokens',
2202
+ type: 'number | undefined',
2203
+ description:
2204
+ 'The number of cached input (prompt) tokens read.',
2205
+ },
2206
+ {
2207
+ name: 'cacheWriteTokens',
2208
+ type: 'number | undefined',
2209
+ description:
2210
+ 'The number of cached input (prompt) tokens written.',
2211
+ },
2212
+ ],
2213
+ },
2214
+ ],
2215
+ },
2216
+ {
2217
+ name: 'outputTokens',
2218
+ type: 'number | undefined',
2219
+ description:
2220
+ 'The number of total output (completion) tokens used.',
2221
+ },
2222
+ {
2223
+ name: 'outputTokenDetails',
2224
+ type: 'LanguageModelOutputTokenDetails',
2225
+ description:
2226
+ 'Detailed information about the output (completion) tokens.',
2227
+ properties: [
2228
+ {
2229
+ type: 'LanguageModelOutputTokenDetails',
2230
+ parameters: [
2231
+ {
2232
+ name: 'textTokens',
2233
+ type: 'number | undefined',
2234
+ description: 'The number of text tokens used.',
2235
+ },
2236
+ {
2237
+ name: 'reasoningTokens',
2238
+ type: 'number | undefined',
2239
+ description: 'The number of reasoning tokens used.',
2240
+ },
2241
+ ],
2242
+ },
2243
+ ],
2244
+ },
2245
+ {
2246
+ name: 'totalTokens',
2247
+ type: 'number | undefined',
2248
+ description: 'The total number of tokens used.',
2249
+ },
2250
+ {
2251
+ name: 'raw',
2252
+ type: 'object | undefined',
2253
+ isOptional: true,
2254
+ description:
2255
+ "Raw usage information from the provider. This is the provider's original usage information and may include additional fields.",
2256
+ },
2257
+ ],
2258
+ },
2259
+ ],
2260
+ },
2261
+ {
2262
+ name: 'totalUsage',
2263
+ type: 'LanguageModelUsage',
2264
+ description:
2265
+ 'The total token usage of all steps. When there are multiple steps, the usage is the sum of all step usages.',
2266
+ properties: [
2267
+ {
2268
+ type: 'LanguageModelUsage',
2269
+ parameters: [
2270
+ {
2271
+ name: 'inputTokens',
2272
+ type: 'number | undefined',
2273
+ description: 'The number of input (prompt) tokens used.',
2274
+ },
2275
+ {
2276
+ name: 'outputTokens',
2277
+ type: 'number | undefined',
2278
+ description: 'The number of output (completion) tokens used.',
2279
+ },
2280
+ {
2281
+ name: 'totalTokens',
2282
+ type: 'number | undefined',
2283
+ description:
2284
+ 'The total number of tokens as reported by the provider. This number might be different from the sum of inputTokens and outputTokens and e.g. include reasoning tokens or other overhead.',
2285
+ },
2286
+ {
2287
+ name: 'reasoningTokens',
2288
+ type: 'number | undefined',
2289
+ isOptional: true,
2290
+ description: 'The number of reasoning tokens used.',
2291
+ },
2292
+ {
2293
+ name: 'cachedInputTokens',
2294
+ type: 'number | undefined',
2295
+ isOptional: true,
2296
+ description: 'The number of cached input tokens.',
2297
+ },
2298
+ ],
2299
+ },
2300
+ ],
2301
+ },
2302
+ {
2303
+ name: 'request',
2304
+ type: 'LanguageModelRequestMetadata',
2305
+ isOptional: true,
2306
+ description: 'Request metadata.',
2307
+ properties: [
2308
+ {
2309
+ type: 'LanguageModelRequestMetadata',
2310
+ parameters: [
2311
+ {
2312
+ name: 'body',
2313
+ type: 'string',
2314
+ description:
2315
+ 'Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).',
2316
+ },
2317
+ ],
2318
+ },
2319
+ ],
2320
+ },
2321
+ {
2322
+ name: 'response',
2323
+ type: 'LanguageModelResponseMetadata',
2324
+ isOptional: true,
2325
+ description: 'Response metadata.',
2326
+ properties: [
2327
+ {
2328
+ type: 'LanguageModelResponseMetadata',
2329
+ parameters: [
2330
+ {
2331
+ name: 'id',
2332
+ type: 'string',
2333
+ description:
2334
+ 'The response identifier. The AI SDK uses the ID from the provider response when available, and generates an ID otherwise.',
2335
+ },
2336
+ {
2337
+ name: 'modelId',
2338
+ type: 'string',
2339
+ description:
2340
+ 'The model that was used to generate the response. The AI SDK uses the response model from the provider response when available, and the model from the function call otherwise.',
2341
+ },
2342
+ {
2343
+ name: 'timestamp',
2344
+ type: 'Date',
2345
+ description:
2346
+ 'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
2347
+ },
2348
+ {
2349
+ name: 'headers',
2350
+ isOptional: true,
2351
+ type: 'Record<string, string>',
2352
+ description: 'Optional response headers.',
2353
+ },
2354
+ {
2355
+ name: 'body',
2356
+ isOptional: true,
2357
+ type: 'unknown',
2358
+ description: 'Optional response body.',
2359
+ },
2360
+ {
2361
+ name: 'messages',
2362
+ type: 'Array<ResponseMessage>',
2363
+ description:
2364
+ 'The response messages that were generated during the call. It consists of an assistant message, potentially containing tool calls. When there are tool results, there is an additional tool message with the tool results that are available. If there are tools that do not have execute functions, they are not included in the tool results and need to be added separately.',
2365
+ },
2366
+ ],
2367
+ },
2368
+ ],
2369
+ },
2370
+ {
2371
+ name: 'warnings',
2372
+ type: 'Warning[] | undefined',
2373
+ description:
2374
+ 'Warnings from the model provider (e.g. unsupported settings).',
2375
+ },
2376
+ {
2377
+ name: 'providerMetadata',
2378
+ type: 'ProviderMetadata | undefined',
2379
+ description:
2380
+ 'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
2381
+ },
2382
+ {
2383
+ name: 'output',
2384
+ type: 'Output',
2385
+ isOptional: true,
2386
+ description: 'Experimental setting for generating structured outputs.',
2387
+ },
2388
+ {
2389
+ name: 'steps',
2390
+ type: 'Array<StepResult<TOOLS>>',
2391
+ description:
2392
+ 'Response information for every step. You can use this to get information about intermediate steps, such as the tool calls or the response headers.',
2393
+ properties: [
2394
+ {
2395
+ type: 'StepResult',
2396
+ parameters: [
2397
+ {
2398
+ name: 'stepNumber',
2399
+ type: 'number',
2400
+ description: 'The zero-based index of this step.',
2401
+ },
2402
+ {
2403
+ name: 'model',
2404
+ type: '{ provider: string; modelId: string }',
2405
+ description:
2406
+ 'Information about the model that produced this step.',
2407
+ },
2408
+ {
2409
+ name: 'functionId',
2410
+ type: 'string | undefined',
2411
+ description:
2412
+ 'Identifier from telemetry settings for grouping related operations.',
2413
+ },
2414
+ {
2415
+ name: 'metadata',
2416
+ type: 'Record<string, unknown> | undefined',
2417
+ description: 'Additional metadata from telemetry settings.',
2418
+ },
2419
+ {
2420
+ name: 'experimental_context',
2421
+ type: 'unknown',
2422
+ description:
2423
+ 'User-defined context object flowing through the generation.',
2424
+ },
2425
+ {
2426
+ name: 'content',
2427
+ type: 'Array<ContentPart<TOOLS>>',
2428
+ description: 'The content that was generated in the last step.',
2429
+ },
2430
+ {
2431
+ name: 'text',
2432
+ type: 'string',
2433
+ description: 'The generated text.',
2434
+ },
2435
+ {
2436
+ name: 'reasoning',
2437
+ type: 'Array<ReasoningPart | ReasoningFilePart>',
2438
+ description:
2439
+ 'The reasoning that was generated during the generation.',
2440
+ properties: [
2441
+ {
2442
+ type: 'ReasoningPart',
2443
+ parameters: [
2444
+ {
2445
+ name: 'type',
2446
+ type: "'reasoning'",
2447
+ description: 'The type of the message part.',
2448
+ },
2449
+ {
2450
+ name: 'text',
2451
+ type: 'string',
2452
+ description: 'The reasoning text.',
2453
+ },
2454
+ ],
2455
+ },
2456
+ {
2457
+ type: 'ReasoningFilePart',
2458
+ parameters: [
2459
+ {
2460
+ name: 'type',
2461
+ type: "'reasoning-file'",
2462
+ description: 'The type of the message part.',
2463
+ },
2464
+ {
2465
+ name: 'data',
2466
+ type: 'string | Uint8Array | Buffer | ArrayBuffer | URL',
2467
+ description:
2468
+ 'The file data. String are either base64 encoded content, base64 data URLs, or http(s) URLs.',
2469
+ },
2470
+ {
2471
+ name: 'mediaType',
2472
+ type: 'string',
2473
+ description: 'The IANA media type of the file.',
2474
+ },
2475
+ ],
2476
+ },
2477
+ ],
2478
+ },
2479
+ {
2480
+ name: 'reasoningText',
2481
+ type: 'string | undefined',
2482
+ description:
2483
+ 'The reasoning text that was generated during the generation.',
2484
+ },
2485
+ {
2486
+ name: 'files',
2487
+ type: 'Array<GeneratedFile>',
2488
+ description:
2489
+ 'The files that were generated during the generation.',
2490
+ properties: [
2491
+ {
2492
+ type: 'GeneratedFile',
2493
+ parameters: [
2494
+ {
2495
+ name: 'base64',
2496
+ type: 'string',
2497
+ description: 'File as a base64 encoded string.',
2498
+ },
2499
+ {
2500
+ name: 'uint8Array',
2501
+ type: 'Uint8Array',
2502
+ description: 'File as a Uint8Array.',
2503
+ },
2504
+ {
2505
+ name: 'mediaType',
2506
+ type: 'string',
2507
+ description: 'The IANA media type of the file.',
2508
+ },
2509
+ ],
2510
+ },
2511
+ ],
2512
+ },
2513
+ {
2514
+ name: 'sources',
2515
+ type: 'Array<Source>',
2516
+ description: 'The sources that were used to generate the text.',
2517
+ properties: [
2518
+ {
2519
+ type: 'Source',
2520
+ parameters: [
2521
+ {
2522
+ name: 'sourceType',
2523
+ type: "'url'",
2524
+ description:
2525
+ 'A URL source. This is return by web search RAG models.',
2526
+ },
2527
+ {
2528
+ name: 'id',
2529
+ type: 'string',
2530
+ description: 'The ID of the source.',
2531
+ },
2532
+ {
2533
+ name: 'url',
2534
+ type: 'string',
2535
+ description: 'The URL of the source.',
2536
+ },
2537
+ {
2538
+ name: 'title',
2539
+ type: 'string',
2540
+ isOptional: true,
2541
+ description: 'The title of the source.',
2542
+ },
2543
+ {
2544
+ name: 'providerMetadata',
2545
+ type: 'SharedV2ProviderMetadata',
2546
+ isOptional: true,
2547
+ description:
2548
+ 'Additional provider metadata for the source.',
2549
+ },
2550
+ ],
2551
+ },
2552
+ ],
2553
+ },
2554
+ {
2555
+ name: 'toolCalls',
2556
+ type: 'ToolCallArray<TOOLS>',
2557
+ description:
2558
+ 'The tool calls that were made during the generation.',
2559
+ },
2560
+ {
2561
+ name: 'toolResults',
2562
+ type: 'ToolResultArray<TOOLS>',
2563
+ description: 'The results of the tool calls.',
2564
+ },
2565
+ {
2566
+ name: 'finishReason',
2567
+ type: "'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other'",
2568
+ description: 'The reason why the generation finished.',
2569
+ },
2570
+ {
2571
+ name: 'rawFinishReason',
2572
+ type: 'string | undefined',
2573
+ description:
2574
+ 'The raw reason why the generation finished (from the provider).',
2575
+ },
2576
+ {
2577
+ name: 'usage',
2578
+ type: 'LanguageModelUsage',
2579
+ description: 'The token usage of the generated text.',
2580
+ properties: [
2581
+ {
2582
+ type: 'LanguageModelUsage',
2583
+ parameters: [
2584
+ {
2585
+ name: 'inputTokens',
2586
+ type: 'number | undefined',
2587
+ description:
2588
+ 'The total number of input (prompt) tokens used.',
2589
+ },
2590
+ {
2591
+ name: 'inputTokenDetails',
2592
+ type: 'LanguageModelInputTokenDetails',
2593
+ description:
2594
+ 'Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens.',
2595
+ properties: [
2596
+ {
2597
+ type: 'LanguageModelInputTokenDetails',
2598
+ parameters: [
2599
+ {
2600
+ name: 'noCacheTokens',
2601
+ type: 'number | undefined',
2602
+ description:
2603
+ 'The number of non-cached input (prompt) tokens used.',
2604
+ },
2605
+ {
2606
+ name: 'cacheReadTokens',
2607
+ type: 'number | undefined',
2608
+ description:
2609
+ 'The number of cached input (prompt) tokens read.',
2610
+ },
2611
+ {
2612
+ name: 'cacheWriteTokens',
2613
+ type: 'number | undefined',
2614
+ description:
2615
+ 'The number of cached input (prompt) tokens written.',
2616
+ },
2617
+ ],
2618
+ },
2619
+ ],
2620
+ },
2621
+ {
2622
+ name: 'outputTokens',
2623
+ type: 'number | undefined',
2624
+ description:
2625
+ 'The number of total output (completion) tokens used.',
2626
+ },
2627
+ {
2628
+ name: 'outputTokenDetails',
2629
+ type: 'LanguageModelOutputTokenDetails',
2630
+ description:
2631
+ 'Detailed information about the output (completion) tokens.',
2632
+ properties: [
2633
+ {
2634
+ type: 'LanguageModelOutputTokenDetails',
2635
+ parameters: [
2636
+ {
2637
+ name: 'textTokens',
2638
+ type: 'number | undefined',
2639
+ description: 'The number of text tokens used.',
2640
+ },
2641
+ {
2642
+ name: 'reasoningTokens',
2643
+ type: 'number | undefined',
2644
+ description:
2645
+ 'The number of reasoning tokens used.',
2646
+ },
2647
+ ],
2648
+ },
2649
+ ],
2650
+ },
2651
+ {
2652
+ name: 'totalTokens',
2653
+ type: 'number | undefined',
2654
+ description: 'The total number of tokens used.',
2655
+ },
2656
+ {
2657
+ name: 'raw',
2658
+ type: 'object | undefined',
2659
+ isOptional: true,
2660
+ description:
2661
+ "Raw usage information from the provider. This is the provider's original usage information and may include additional fields.",
2662
+ },
2663
+ ],
2664
+ },
2665
+ ],
2666
+ },
2667
+ {
2668
+ name: 'warnings',
2669
+ type: 'Warning[] | undefined',
2670
+ description:
2671
+ 'Warnings from the model provider (e.g. unsupported settings).',
2672
+ },
2673
+ {
2674
+ name: 'request',
2675
+ type: 'LanguageModelRequestMetadata',
2676
+ description: 'Additional request information.',
2677
+ properties: [
2678
+ {
2679
+ type: 'LanguageModelRequestMetadata',
2680
+ parameters: [
2681
+ {
2682
+ name: 'body',
2683
+ type: 'string',
2684
+ description:
2685
+ 'Raw request HTTP body that was sent to the provider API as a string (JSON should be stringified).',
2686
+ },
2687
+ ],
2688
+ },
2689
+ ],
2690
+ },
2691
+ {
2692
+ name: 'response',
2693
+ type: 'LanguageModelResponseMetadata',
2694
+ description: 'Additional response information.',
2695
+ properties: [
2696
+ {
2697
+ type: 'LanguageModelResponseMetadata',
2698
+ parameters: [
2699
+ {
2700
+ name: 'id',
2701
+ type: 'string',
2702
+ description:
2703
+ 'The response identifier. The AI SDK uses the ID from the provider response when available, and generates an ID otherwise.',
2704
+ },
2705
+ {
2706
+ name: 'modelId',
2707
+ type: 'string',
2708
+ description:
2709
+ 'The model that was used to generate the response. The AI SDK uses the response model from the provider response when available, and the model from the function call otherwise.',
2710
+ },
2711
+ {
2712
+ name: 'timestamp',
2713
+ type: 'Date',
2714
+ description:
2715
+ 'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
2716
+ },
2717
+ {
2718
+ name: 'headers',
2719
+ isOptional: true,
2720
+ type: 'Record<string, string>',
2721
+ description: 'Optional response headers.',
2722
+ },
2723
+ {
2724
+ name: 'body',
2725
+ isOptional: true,
2726
+ type: 'unknown',
2727
+ description:
2728
+ 'Response body (available only for providers that use HTTP requests).',
2729
+ },
2730
+ {
2731
+ name: 'messages',
2732
+ type: 'Array<ResponseMessage>',
2733
+ description:
2734
+ 'The response messages that were generated during the call. Response messages can be either assistant messages or tool messages. They contain a generated id.',
2735
+ },
2736
+ ],
2737
+ },
2738
+ ],
2739
+ },
2740
+ {
2741
+ name: 'providerMetadata',
2742
+ type: 'ProviderMetadata | undefined',
2743
+ description:
2744
+ 'Additional provider-specific metadata. They are passed through from the provider to the AI SDK and enable provider-specific results that can be fully encapsulated in the provider.',
2745
+ },
2746
+ ],
2747
+ },
2748
+ ],
2749
+ },
2750
+ ]}
2751
+ />
2752
+
2753
+ ## Examples
2754
+
2755
+ <ExampleLinks
2756
+ examples={[
2757
+ {
2758
+ title: 'Learn to generate text using a language model in Next.js',
2759
+ link: '/examples/next-app/basics/generating-text',
2760
+ },
2761
+ {
2762
+ title:
2763
+ 'Learn to generate a chat completion using a language model in Next.js',
2764
+ link: '/examples/next-app/basics/generating-text',
2765
+ },
2766
+ {
2767
+ title: 'Learn to call tools using a language model in Next.js',
2768
+ link: '/examples/next-app/tools/call-tool',
2769
+ },
2770
+ {
2771
+ title:
2772
+ 'Learn to render a React component as a tool call using a language model in Next.js',
2773
+ link: '/examples/next-app/tools/render-interface-during-tool-call',
2774
+ },
2775
+ {
2776
+ title: 'Learn to generate text using a language model in Node.js',
2777
+ link: '/examples/node/generating-text/generate-text',
2778
+ },
2779
+ {
2780
+ title:
2781
+ 'Learn to generate chat completions using a language model in Node.js',
2782
+ link: '/examples/node/generating-text/generate-text-with-chat-prompt',
2783
+ },
2784
+ ]}
2785
+ />