ai 7.0.172 → 7.0.174

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 (55) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/index.d.ts +68 -21
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +325 -100
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +109 -9
  7. package/dist/internal/index.d.ts.map +1 -1
  8. package/dist/internal/index.js +68 -18
  9. package/dist/internal/index.js.map +1 -1
  10. package/docs/02-foundations/02-providers-and-models.mdx +1 -0
  11. package/docs/02-foundations/03-prompts.mdx +1 -1
  12. package/docs/03-agents/04-loop-control.mdx +1 -1
  13. package/docs/03-agents/06-memory.mdx +28 -1
  14. package/docs/03-agents/06-tool-approvals.mdx +1 -1
  15. package/docs/03-agents/07-workflow-agent.mdx +87 -34
  16. package/docs/03-ai-sdk-core/05-generating-text.mdx +7 -2
  17. package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +4 -0
  18. package/docs/03-ai-sdk-core/16-mcp-tools.mdx +3 -0
  19. package/docs/03-ai-sdk-core/26-reasoning.mdx +3 -3
  20. package/docs/03-ai-sdk-core/32-decisions.mdx +4 -0
  21. package/docs/03-ai-sdk-core/33-extractions.mdx +59 -2
  22. package/docs/03-ai-sdk-core/35-image-generation.mdx +2 -0
  23. package/docs/03-ai-sdk-core/36-transcription.mdx +3 -0
  24. package/docs/03-ai-sdk-core/37-speech.mdx +3 -0
  25. package/docs/03-ai-sdk-core/42-batch.mdx +54 -0
  26. package/docs/03-ai-sdk-core/45-provider-management.mdx +8 -0
  27. package/docs/07-reference/01-ai-sdk-core/14-extract.mdx +13 -13
  28. package/docs/07-reference/01-ai-sdk-core/20-start-batch.mdx +7 -0
  29. package/docs/07-reference/01-ai-sdk-core/22-get-batch-results.mdx +7 -0
  30. package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +6 -0
  31. package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +3 -0
  32. package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +14 -0
  33. package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +13 -0
  34. package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +62 -5
  35. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +3 -0
  36. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +3 -0
  37. package/package.json +12 -12
  38. package/src/agent/default-stop-condition.ts +28 -13
  39. package/src/batch/batch-types.ts +70 -18
  40. package/src/batch/batch.ts +93 -7
  41. package/src/extract/extract.ts +23 -4
  42. package/src/extract/extraction-provider.ts +5 -0
  43. package/src/extract/extraction-result.ts +1 -1
  44. package/src/generate-text/stream-text.ts +1 -1
  45. package/src/generate-text/validate-tool-approvals.ts +23 -19
  46. package/src/global.ts +1 -0
  47. package/src/model/resolve-model.ts +25 -0
  48. package/src/registry/custom-provider.ts +37 -0
  49. package/src/registry/index.ts +1 -0
  50. package/src/registry/no-such-provider-error.ts +1 -0
  51. package/src/registry/provider-registry.ts +59 -5
  52. package/src/telemetry/redact-telemetry-credentials.ts +22 -4
  53. package/src/types/citation.ts +41 -25
  54. package/src/ui/validate-ui-messages.ts +46 -91
  55. package/src/util/normalize-json-value.ts +182 -0
@@ -100,6 +100,7 @@ The open-source community has created the following providers:
100
100
  - [Interfaze Provider](/providers/community-providers/interfaze) (`@interfaze-ai/ai-sdk`)
101
101
  - [Telnyx Provider](/providers/community-providers/telnyx) (`@telnyx/ai-sdk-provider`)
102
102
  - [ZeroGPU Provider](/providers/community-providers/zerogpu) (`@zerogpu/ai-sdk-provider`)
103
+ - [Upstash AgentKit Provider](/providers/community-providers/upstash-agentkit) (`@upstash/agentkit-ai-sdk`)
103
104
 
104
105
  ## Self-Hosted Models
105
106
 
@@ -321,7 +321,7 @@ import { google } from '@ai-sdk/google';
321
321
  import { generateText } from 'ai';
322
322
 
323
323
  const result = await generateText({
324
- model: google('gemini-3.8-flash'),
324
+ model: google('gemini-4-hydrogen'),
325
325
  messages: [
326
326
  {
327
327
  role: 'user',
@@ -22,7 +22,7 @@ The `stopWhen` parameter controls when to stop execution when there are tool res
22
22
 
23
23
  If this default limit stops a tool loop that could otherwise continue, the SDK logs a warning with guidance on configuring `stopWhen`. Set `stopWhen` explicitly to choose a limit, even if you want to keep `isStepCount(20)`. Explicit stop conditions do not produce this warning.
24
24
 
25
- `WorkflowAgent.stream()` does not apply a default step limit. It continues until the model stops calling tools or another natural termination condition is met. Configure an explicit condition such as `isStepCount(20)` when you need to bound its model calls. `WorkflowAgent.generate()` stops after 20 steps by default and does not log the warning. See [WorkflowAgent Loop Control](/docs/agents/workflow-agent#loop-control) for details.
25
+ `WorkflowAgent.stream()` does not apply a default step limit. It continues until the model stops calling tools or another natural termination condition is met. Configure an explicit condition such as `isStepCount(20)` when you need to bound its model calls. `WorkflowAgent.generate()` stops after 20 steps by default and logs the same warning. See [WorkflowAgent Loop Control](/docs/agents/workflow-agent#loop-control) for details.
26
26
 
27
27
  When you provide `stopWhen`, the agent continues executing after tool calls until a stopping condition is met. When the condition is an array, execution stops when any of the conditions are met.
28
28
 
@@ -260,7 +260,7 @@ MongoDB memory works with any AI SDK model and embedding provider, with no vendo
260
260
 
261
261
  ### Redis Agent Memory
262
262
 
263
- [Redis Agent Memory](https://redis.io/agent-memory/) is a managed memory layer that combines session history with long-term memories. The [`ai-sdk-redis-agent-memory`](https://www.npmjs.com/package/ai-sdk-redis-agent-memory) package wraps a model you have already configured, restores the user's session and recalls relevant long-term memories before each call, and records the conversation afterwards. The model does not need memory tools. It also exposes memory tools for agents that should manage their own memory.
263
+ [Redis Agent Memory](https://redis.io/agent-memory/) is a managed memory layer that combines session history with long-term memories. The [`@redis/vercel-ai-sdk`](https://www.npmjs.com/package/@redis/vercel-ai-sdk) package wraps a model you have already configured, restores the user's session and recalls relevant long-term memories before each call, and records the conversation afterwards. The model does not need memory tools. It also exposes memory tools for agents that should manage their own memory.
264
264
 
265
265
  ```bash
266
266
  pnpm add @redis/vercel-ai-sdk
@@ -300,6 +300,33 @@ The package requires AI SDK 7. It accepts configured model objects, not model-na
300
300
 
301
301
  See the [Redis Agent Memory provider documentation](/providers/community-providers/redis-agent-memory) for full setup and configuration.
302
302
 
303
+ ### Upstash AgentKit
304
+
305
+ [Upstash AgentKit](https://upstash.com/docs/redis/sdks/agentkit/ai-sdk) stores long-term memory in Upstash Redis. The [`@upstash/agentkit-ai-sdk`](https://www.npmjs.com/package/@upstash/agentkit-ai-sdk) package provides `recall_memory` and `save_memory` tools, so the model decides what to save and when to look it up. Recall runs on Upstash Redis Search, so you do not need a separate vector database.
306
+
307
+ ```bash
308
+ pnpm add @upstash/agentkit-ai-sdk
309
+ ```
310
+
311
+ ```ts
312
+ __PROVIDER_IMPORT__;
313
+ import { createMemoryTools } from '@upstash/agentkit-ai-sdk';
314
+ import { ToolLoopAgent } from 'ai';
315
+
316
+ const agent = new ToolLoopAgent({
317
+ model: __MODEL__,
318
+ tools: createMemoryTools({ userId: 'user-123' }),
319
+ });
320
+
321
+ const result = await agent.generate({
322
+ prompt: 'Remember that my favorite editor is Neovim',
323
+ });
324
+ ```
325
+
326
+ The tools read `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from the environment by default. `userId` is the only tenant boundary, so take it from your authenticated session. In multi-user apps, call `createMemoryTools` inside your request handler so each request uses the right user. The package requires AI SDK 7 and works with any AI SDK provider.
327
+
328
+ See the [Upstash AgentKit provider documentation](/providers/community-providers/upstash-agentkit) for full setup and configuration. It also covers chat history, search tools for RAG, rate limiting, and tool caching.
329
+
303
330
  ## Custom Tool
304
331
 
305
332
  Building your own memory tool from scratch is the most flexible approach. You control the storage format, the interface, and the retrieval logic. This requires the most upfront work but gives you full ownership of how memory works, with no provider lock-in and no external dependencies.
@@ -352,6 +352,6 @@ Every serverless instance that might handle a request needs the same secret, sin
352
352
 
353
353
  - Use `toolApproval` with `ToolLoopAgent`, `generateText`, and `streamText`.
354
354
  - Author approval rules as code with [Policy-Based Tool Approvals](/docs/agents/policy-tool-approvals) (`@ai-sdk/policy-opa`).
355
- - Use `needsApproval` only with [`WorkflowAgent`](/docs/agents/workflow-agent), where approvals suspend and resume durable workflow execution.
355
+ - [`WorkflowAgent`](/docs/agents/workflow-agent) supports `toolApproval` and `needsApproval`. Approvals suspend and resume durable workflow execution.
356
356
  - Subagent tools cannot use `toolApproval`; see [Subagents](/docs/agents/subagents#no-tool-approvals-in-subagents).
357
357
  - Chat SDK's `createChatTools` marks its write tools and `getUser` as needing approval. A `toolApproval` rule overrides those defaults; see [Chat Platforms](/docs/agents/chat-platforms#give-the-agent-chat-tools).
@@ -322,11 +322,11 @@ Tools without `'use step'` still work but run as regular in-memory functions wit
322
322
 
323
323
  ## Tool Approval
324
324
 
325
- For `WorkflowAgent`, human approval is configured on the tool definition with
326
- `needsApproval`. This is specific to `WorkflowAgent`; for `generateText`,
327
- `streamText`, and `ToolLoopAgent`, use `toolApproval` instead. When a workflow
328
- tool has `needsApproval` set, the agent pauses and emits an approval request to
329
- the writable stream. The workflow suspends until the user approves or denies:
325
+ Human approval is configured on the tool definition with `needsApproval` or on
326
+ the agent with `toolApproval`. The `toolApproval` configuration takes precedence
327
+ over `needsApproval`. When a tool call needs user approval, the agent pauses and
328
+ emits an approval request to the writable stream. The workflow suspends until
329
+ the user approves or denies:
330
330
 
331
331
  ```ts
332
332
  const agent = new WorkflowAgent({
@@ -356,6 +356,36 @@ const agent = new WorkflowAgent({
356
356
 
357
357
  Because the workflow is durable, the approval request survives process restarts — the user can approve hours later and the agent will resume.
358
358
 
359
+ Use `toolApproval` when approval depends on the tool set, the call, or the
360
+ runtime context, or when a tool does not set `needsApproval`. The functions in
361
+ the configuration run in workflow context, outside of the durable model steps:
362
+
363
+ ```ts
364
+ const agent = new WorkflowAgent({
365
+ model: 'anthropic/claude-sonnet-5.5',
366
+ tools: {
367
+ bookFlight: tool({
368
+ description: 'Book a flight',
369
+ inputSchema: z.object({ flightId: z.string() }),
370
+ execute: bookFlightStep,
371
+ }),
372
+ },
373
+ toolApproval: {
374
+ bookFlight: 'user-approval',
375
+ },
376
+ });
377
+ ```
378
+
379
+ A call that the configuration marks as `'approved'` runs in the same step. A
380
+ call that it marks as `'denied'` does not run: the model receives an
381
+ `execution-denied` tool result and the loop continues. Neither decision pauses
382
+ the workflow. `step.content` records both decisions with an automatic approval
383
+ request and an approval response. Two details differ from `ToolLoopAgent`. The
384
+ tool message in `step.response.messages` holds only the tool result, while
385
+ `ToolLoopAgent` also adds the approval response part there. In `stream()`, the
386
+ approval parts follow the tool results in `step.content`, while `ToolLoopAgent`
387
+ places them next to the tool calls.
388
+
359
389
  ### Signed Tool Approvals
360
390
 
361
391
  Client-supplied message history can be modified before it is replayed to the
@@ -404,7 +434,7 @@ The stream-level value overrides the constructor default.
404
434
  `stream()` does not apply a default step limit. When `stopWhen` is omitted, it
405
435
  continues until the model stops calling tools or another natural termination
406
436
  condition is met. `generate()` stops after 20 steps by default, like
407
- `ToolLoopAgent`, but does not log a warning when it reaches that limit.
437
+ `ToolLoopAgent`, and logs the same warning when it reaches that limit.
408
438
 
409
439
  <Note>
410
440
  A model that repeatedly calls tools can make an unlimited number of model
@@ -596,8 +626,8 @@ const agent = new WorkflowAgent({
596
626
  A `model`, `toolChoice`, `activeTools`, or generation setting returned from
597
627
  `prepareStep` applies to the current step only, as in `ToolLoopAgent`. Later
598
628
  steps use the agent or call values again unless `prepareStep` returns an
599
- override for them too. Returned `messages`, `system`, `runtimeContext`, and
600
- `toolsContext` values stay in effect for later steps.
629
+ override for them too. Returned `messages`, `instructions`, `runtimeContext`,
630
+ and `toolsContext` values stay in effect for later steps.
601
631
 
602
632
  `prepareStep` can also be passed per call in `generate()` and `stream()`.
603
633
  `prepareCall` is a constructor option only.
@@ -689,37 +719,35 @@ TypeScript rejects these options on `WorkflowAgent`. If you pass them anyway, fo
689
719
 
690
720
  | ToolLoopAgent option | With WorkflowAgent |
691
721
  | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
692
- | `toolApproval` | Set `needsApproval` on each tool. See [Tool Approval](#tool-approval). |
693
722
  | `toolOrder` | Not supported. Tools are sent in the order of the `tools` object. |
694
723
  | `callOptionsSchema` and the `options` call parameter | Not supported. Pass settings to `generate()` or `stream()` directly. |
695
- | `experimental_refineToolInput` | Not supported. |
696
724
  | `experimental_toolCallers` | Not supported. |
697
725
  | `experimental_steering` | Not supported. To add messages between steps, return `messages` from `prepareStep`. |
698
726
  | `experimental_transform` | Not supported. Transform `run.readable` with `pipeThrough()` where you create the response. |
699
727
  | `onStepError` | Not supported. Use `onError`. |
700
728
  | `onLanguageModelCallStart`, `onLanguageModelCallEnd` | Not supported. |
701
729
  | `include` in the constructor | Pass `include` to `generate()`. `stream()` has no `include` option and does not record request data in its steps. Use `includeRawChunks` to receive raw provider chunks. |
702
- | `timeout` in the constructor, and `timeout` as an object | Pass `timeout` as a number of milliseconds to `generate()` or `stream()`. An object value fails with a `TypeError`. |
730
+ | `timeout` in the constructor | Pass `timeout` to `generate()` or `stream()`. |
703
731
  | `experimental_telemetry` | Use `telemetry`. |
704
732
  | `experimental_onToolCallStart`, `experimental_onToolCallFinish` | Use `onToolExecutionStart` and `onToolExecutionEnd`. |
705
733
 
706
734
  ### Options with a different shape
707
735
 
708
- | Option | ToolLoopAgent | WorkflowAgent |
709
- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
710
- | Generation settings, `instructions`, `toolChoice`, `activeTools`, `stopWhen`, `output`, `telemetry`, `prepareStep`, `repairToolCall` | Constructor only. Use `prepareCall` to change them per call. | Constructor, or per call in `generate()` and `stream()`. The per-call value overrides the constructor value. |
711
- | `abortSignal` | Per call. | Constructor or per call. |
712
- | `experimental_sandbox` | Per call. | Constructor or per call. |
713
- | `timeout` | A number or an object, in the constructor or per call. | A number, per call. It sets a deadline for model calls and does not cancel a tool that waits on a hook. See [Deadlines, cancellation, and replay](#deadlines-cancellation-and-replay). |
714
- | `experimental_toolApprovalSecret` | The secret, as a `string` or `Uint8Array`. | `{ environmentVariable: string }`, the name of an environment variable that holds the secret. See [Signed Tool Approvals](#signed-tool-approvals). |
715
- | `runtimeContext`, `toolsContext` | Any JavaScript value. | Serializable values. See [runtimeContext and toolsContext](#runtimecontext-and-toolscontext). |
736
+ | Option | ToolLoopAgent | WorkflowAgent |
737
+ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
738
+ | Generation settings, `instructions`, `toolChoice`, `activeTools`, `stopWhen`, `output`, `telemetry`, `prepareStep`, `repairToolCall` | Constructor only. Use `prepareCall` to change them per call. | Constructor, or per call in `generate()` and `stream()`. The per-call value overrides the constructor value. |
739
+ | `abortSignal` | Per call. | Constructor or per call. |
740
+ | `experimental_sandbox` | Per call. | Constructor or per call. |
741
+ | `timeout` | A number or an object, in the constructor or per call. | A number or an object, per call. The object has no tool timeouts, and `stepMs` covers the model call without tool execution. See [Deadlines, cancellation, and replay](#deadlines-cancellation-and-replay). |
742
+ | `experimental_toolApprovalSecret` | The secret, as a `string` or `Uint8Array`. | `{ environmentVariable: string }`, the name of an environment variable that holds the secret. See [Signed Tool Approvals](#signed-tool-approvals). |
743
+ | `runtimeContext`, `toolsContext` | Any JavaScript value. | Serializable values. See [runtimeContext and toolsContext](#runtimecontext-and-toolscontext). |
716
744
 
717
745
  ### Default step limit
718
746
 
719
747
  | | `generate()` | `stream()` |
720
748
  | --------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
721
749
  | `ToolLoopAgent` | 20 steps. A warning is logged when the limit stops the loop. | 20 steps. A warning is logged when the limit stops the loop. |
722
- | `WorkflowAgent` | 20 steps. No warning is logged. | No limit. |
750
+ | `WorkflowAgent` | 20 steps. A warning is logged when the limit stops the loop. | No limit. |
723
751
 
724
752
  ### prepareCall
725
753
 
@@ -732,11 +760,8 @@ In `ToolLoopAgent`, `prepareCall` receives the settings together with the `promp
732
760
  ### prepareStep
733
761
 
734
762
  - `messages` uses the provider prompt format (`LanguageModelV4Prompt`) in the argument and in the return value, and it includes the system message. `ToolLoopAgent` uses `ModelMessage[]` without the system message.
735
- - The argument has no `instructions` and no `responseMessages`. `initialInstructions` and `initialMessages` are available.
736
- - To change the system prompt, return `system` as a string. A returned `instructions` value is ignored.
737
- - A returned `providerOptions` object replaces the `providerOptions` of the agent. `ToolLoopAgent` merges the two objects.
738
- - You can return `headers`. They replace all headers of the call, including the `user-agent` value that identifies the agent. `ToolLoopAgent` does not accept `headers` from `prepareStep`.
739
- - You cannot return `toolOrder`.
763
+ - The argument has no `responseMessages`. `initialInstructions`, `instructions`, and `initialMessages` are available.
764
+ - You can return `headers`. They are merged over the headers of the call, and the request keeps the `user-agent` value that identifies the agent. `ToolLoopAgent` does not accept `headers` from `prepareStep`.
740
765
 
741
766
  ### Callbacks
742
767
 
@@ -758,7 +783,6 @@ The callbacks also run at different times:
758
783
  - After a failed run, `stream()` calls `onEnd` before it rejects. `generate()` and `ToolLoopAgent` do not call `onEnd` for a failed run.
759
784
  - `onAbort` is called by `generate()` and by `stream()`, and its event has only `steps`. `ToolLoopAgent` calls `onAbort` only for `stream()`, with `callId`, `reason`, and `steps`.
760
785
  - An aborted `stream()` call resolves with the steps that finished. An aborted `generate()` call rejects.
761
- - If `generate()` is aborted during a step with a custom abort reason, it calls `onError` with that reason. `ToolLoopAgent` does not report aborts to `onError`.
762
786
 
763
787
  ### Results
764
788
 
@@ -772,22 +796,25 @@ The callbacks also run at different times:
772
796
  - `output` is `undefined` unless you set an `output` specification. `ToolLoopAgent` defaults to the generated text.
773
797
  - If the structured output cannot be parsed, the `stream()` call rejects. In `ToolLoopAgent`, the call resolves and only `result.output` rejects.
774
798
  - If the model call throws, the `stream()` call rejects with that error. In `ToolLoopAgent`, the call resolves and the error is reported through the stream and `onError`.
775
- - Each step is a plain object. Its `request` is empty, its `model.provider` is derived from the model ID of the response and can differ from the provider name, and its `providerMetadata` is `{}` when the provider sends none. Steps from `generate()` match `ToolLoopAgent`.
776
- - A tool call for an unknown tool, or with input that does not match the schema, is missing from `content` and `toolCalls` of the step. The model still receives the error as a tool result and the loop continues. `generate()` and `ToolLoopAgent` keep the call in the step, marked `invalid`, with a `tool-error` part.
777
-
778
- `WorkflowAgent` does not log provider warnings. Read them from `warnings` on each step.
799
+ - Each step is a plain object. Its `request` is empty, and its `providerMetadata` is `{}` when the provider sends none. Steps from `generate()` match `ToolLoopAgent`.
779
800
 
780
801
  ### Tools
781
802
 
782
- - Approval is configured with `needsApproval` on the tool. Approval request IDs have the form `approval-<toolCallId>`. `ToolLoopAgent` generates random IDs.
783
- - A tool whose `execute` function is an async generator is not supported. `ToolLoopAgent` treats every yielded value except the last one as a preliminary result. `WorkflowAgent` does not iterate the generator, and the tool result is an empty object.
784
- - In `stream()`, the `onInputStart` and `onInputAvailable` hooks of a tool are not called when the provider sends the tool call without streaming its input first. They are called in `generate()`.
803
+ - Approval is configured with `needsApproval` on the tool or `toolApproval` on the agent. Approval request IDs have the form `approval-<toolCallId>`. `ToolLoopAgent` generates random IDs.
804
+ - For a tool whose `execute` function is an async generator, the last yielded value is the tool result, as in `ToolLoopAgent`. `ToolLoopAgent` also reports the earlier values as preliminary results. `WorkflowAgent` does not send them to the `writable`.
785
805
  - Tool timeouts (`toolMs` and `tools` in the `timeout` object) are not supported.
806
+ - `experimental_refineToolInput` functions run in the workflow context after the model step returns. The `tool-call` chunk that `stream()` writes to `writable` for a tool without its own runtime validator, and the input of provider-executed tool calls, keep the unrefined value.
786
807
 
787
808
  ### Requests
788
809
 
789
810
  Requests carry `ai-sdk-agent/workflow` in the `user-agent` header. `ToolLoopAgent` sends `ai-sdk-agent/tool-loop`.
790
811
 
812
+ ### Timeouts
813
+
814
+ - `stepMs` limits one model call. In `ToolLoopAgent` it also covers the tool calls of the step.
815
+ - `generate()` ignores `firstChunkMs` and `chunkMs`. `ToolLoopAgent` also logs a warning for them.
816
+ - A timeout value that is not a finite number, or that is larger than 2147483647, is rejected with an `InvalidArgumentError`. So is a negative `stepMs`, `firstChunkMs`, or `chunkMs`. `ToolLoopAgent` does not validate the values.
817
+
791
818
  ## Migrating from `DurableAgent`
792
819
 
793
820
  `WorkflowAgent` replaces the Workflow DevKit's [`DurableAgent`](https://workflow-sdk.dev/docs/api-reference/workflow-ai/durable-agent). The two share the same core idea — a durable agent loop that runs inside a workflow — but `WorkflowAgent` moves the class into the AI SDK, tightens typing, and introduces first-class tool approval. If you are using `DurableAgent` today, follow the steps below to switch.
@@ -955,7 +982,33 @@ Local tools execute only after approval validation; denied tools produce an exec
955
982
 
956
983
  #### Deadlines, cancellation, and replay
957
984
 
958
- Inside a workflow, `timeout` sets an absolute deadline for model calls. Each model step checks it before dispatch, before SDK retry attempts, and after the provider returns. The same deadline remains in effect after a tool suspends and resumes. SDK `maxRetries` governs model retries; the durable model step does not add another retry layer. Expiration before dispatch rejects with `TimeoutError`; expiration during SDK retry backoff rejects with `AbortError`. Neither starts a new retry.
985
+ `timeout` accepts a number of milliseconds or an object:
986
+
987
+ ```ts
988
+ const result = await agent.stream({
989
+ messages,
990
+ timeout: {
991
+ totalMs: 5 * 60_000,
992
+ stepMs: 60_000,
993
+ firstChunkMs: 15_000,
994
+ chunkMs: 10_000,
995
+ },
996
+ });
997
+ ```
998
+
999
+ A number has the same meaning as `totalMs`. Inside a workflow, it sets an absolute deadline for model calls. Each model step checks it before dispatch, before SDK retry attempts, and after the provider returns. The same deadline remains in effect after a tool suspends and resumes. SDK `maxRetries` governs model retries; the durable model step does not add another retry layer. Expiration before dispatch rejects with `TimeoutError`; expiration during SDK retry backoff rejects with `AbortError`. Neither starts a new retry.
1000
+
1001
+ The other values apply to one model call and start again for the next one:
1002
+
1003
+ - `stepMs` limits the whole model call: dispatch, SDK retries, and reading the response. Tool execution is not part of it.
1004
+ - `firstChunkMs` limits the wait for the first output of the model call, counted from the start of the response stream.
1005
+ - `chunkMs` limits the wait between two outputs.
1006
+
1007
+ `firstChunkMs` and `chunkMs` are used by `stream()` only. Only generated output counts for them: files, tool calls, and text, reasoning, or tool-input deltas that are not empty. Response metadata, start and end markers, and empty deltas do not start or reset these timers.
1008
+
1009
+ When one of these limits is reached, the model call is aborted with a `TimeoutError` and the run ends like an aborted run: `stream()` resolves with the steps that finished, `generate()` rejects with the error, and both call `onAbort`. The timers run inside the durable model step. A model step that has completed is not timed again on replay.
1010
+
1011
+ Each value must be a finite number of at most 2147483647, which is about 24.8 days. A negative `timeout` or `totalMs` is a deadline that has already passed. Any other invalid value is rejected with an `InvalidArgumentError` before the first model call.
959
1012
 
960
1013
  A model deadline does not cancel a tool waiting on a Workflow hook. The run can remain suspended after that deadline. Once the hook resumes, any subsequent model call fails before dispatch if the deadline has expired. To stop the suspended run, use the Workflow runtime's `run.cancel()` API. Cancellation does not undo external side effects that already happened.
961
1014
 
@@ -1,6 +1,11 @@
1
1
  ---
2
2
  title: Generating Text
3
3
  description: Learn how to generate text with the AI SDK.
4
+ keywords:
5
+ - text generation
6
+ - generate text
7
+ - stream text
8
+ - streaming text
4
9
  ---
5
10
 
6
11
  # Generating and Streaming Text
@@ -722,7 +727,7 @@ When you use `generateText`, you can access the sources using the `sources` prop
722
727
 
723
728
  ```ts
724
729
  const result = await generateText({
725
- model: 'google/gemini-3.8-flash',
730
+ model: 'google/gemini-4-hydrogen',
726
731
  tools: {
727
732
  google_search: google.tools.googleSearch({}),
728
733
  },
@@ -744,7 +749,7 @@ When you use `streamText`, you can access the sources using the `stream` propert
744
749
 
745
750
  ```tsx
746
751
  const result = streamText({
747
- model: 'google/gemini-3.8-flash',
752
+ model: 'google/gemini-4-hydrogen',
748
753
  tools: {
749
754
  google_search: google.tools.googleSearch({}),
750
755
  },
@@ -1,6 +1,10 @@
1
1
  ---
2
2
  title: Generating Structured Data
3
3
  description: Learn how to generate structured data with the AI SDK.
4
+ keywords:
5
+ - structured output
6
+ - structured outputs
7
+ - structured data
4
8
  ---
5
9
 
6
10
  # Generating Structured Data
@@ -1,6 +1,9 @@
1
1
  ---
2
2
  title: Model Context Protocol (MCP)
3
3
  description: Learn how to connect to Model Context Protocol (MCP) servers and use their tools with AI SDK Core.
4
+ keywords:
5
+ - mcp
6
+ - model context protocol
4
7
  ---
5
8
 
6
9
  # Model Context Protocol (MCP)
@@ -40,7 +40,7 @@ The `reasoning` parameter works the same way with `streamText`:
40
40
  import { streamText } from 'ai';
41
41
 
42
42
  const result = streamText({
43
- model: 'google/gemini-3.8-flash',
43
+ model: 'google/gemini-4-hydrogen',
44
44
  reasoning: 'high',
45
45
  prompt: 'Explain the Riemann hypothesis in simple terms.',
46
46
  });
@@ -153,7 +153,7 @@ If you need to enforce an exact token budget (e.g. exactly 12000 tokens), keep u
153
153
 
154
154
  ```ts
155
155
  const { text } = await generateText({
156
- model: google('gemini-3.8-flash'),
156
+ model: google('gemini-4-hydrogen'),
157
157
  providerOptions: {
158
158
  google: {
159
159
  thinkingConfig: { thinkingLevel: 'high', includeThoughts: true },
@@ -167,7 +167,7 @@ const { text } = await generateText({
167
167
 
168
168
  ```ts
169
169
  const { text } = await generateText({
170
- model: google('gemini-3.8-flash'),
170
+ model: google('gemini-4-hydrogen'),
171
171
  reasoning: 'high',
172
172
  providerOptions: {
173
173
  google: { thinkingConfig: { includeThoughts: true } },
@@ -109,6 +109,7 @@ Use a provider's `decisionModel` factory:
109
109
  | OpenAI | `openai.decisionModel('gpt-6-luna')` |
110
110
  | Anthropic | `anthropic.decisionModel('claude-haiku-4-5-20251001')` |
111
111
  | Google | `google.decisionModel('gemini-decision-1')` |
112
+ | HeyGen | `heygen.decisionModel('heygen-decision-1')` |
112
113
 
113
114
  TypeSafe AI's [Jev](https://vercel.com/i/what-is-jev), OpenAI's
114
115
  [Decisions API](https://developers.openai.com/api/docs/guides/decisions),
@@ -296,6 +297,9 @@ Perplexity exposes Choice/Score confidence at
296
297
  Google exposes confidence for all three question types at
297
298
  `result.providerMetadata?.google?.confidence` and Score legends at
298
299
  `result.providerMetadata?.google?.legend`, also keyed by question ID.
300
+ HeyGen exposes Choice/Score confidence at
301
+ `result.providerMetadata?.heygen?.confidence` and Score legends at
302
+ `result.providerMetadata?.heygen?.legend`, also keyed by question ID.
299
303
 
300
304
  Check for optional distributions before using them. For example, an application
301
305
  can route only when a provider supplies a sufficiently high selected-option
@@ -12,7 +12,8 @@ string, JSON object, or an array of ordered text, file, and JSON parts, the same
12
12
  as [decisions](/docs/ai-sdk-core/decisions).
13
13
 
14
14
  This API and the extraction model specification are experimental and may change
15
- in patch releases. Pass an extraction model instance.
15
+ in patch releases. Pass an extraction model instance, resolve a model through a
16
+ provider registry, or use a string ID resolved by a configured default provider.
16
17
 
17
18
  ```ts
18
19
  import { experimental_extract, type Experimental_ExtractionModel } from 'ai';
@@ -109,7 +110,7 @@ Use a provider's `extractionModel` factory:
109
110
  | --------- | ------------------------------------------------ |
110
111
  | OpenAI | `openai.extractionModel('gpt-6.1-sol')` |
111
112
  | Anthropic | `anthropic.extractionModel('claude-sonnet-5-5')` |
112
- | Google | `google.extractionModel('gemini-3.8-flash')` |
113
+ | Google | `google.extractionModel('gemini-4-hydrogen')` |
113
114
 
114
115
  These adapt structured language-model output and extract every field in one
115
116
  prompt. Anthropic sends more than 16 fields as parallel calls, see
@@ -124,6 +125,62 @@ choosing a model for a task.
124
125
  as refused and `experimental_extract` throws
125
126
  `Experimental_ExtractionRefusalError`.
126
127
 
128
+ ## Model aliases and registries
129
+
130
+ Use `customProvider` to give extraction models application-specific names, then
131
+ register providers with `createProviderRegistry`:
132
+
133
+ ```ts
134
+ import { anthropic } from '@ai-sdk/anthropic';
135
+ import { openai } from '@ai-sdk/openai';
136
+ import {
137
+ createProviderRegistry,
138
+ customProvider,
139
+ experimental_extract,
140
+ } from 'ai';
141
+
142
+ const registry = createProviderRegistry({
143
+ invoices: customProvider({
144
+ extractionModels: {
145
+ fast: openai.extractionModel('gpt-6.1-sol'),
146
+ careful: anthropic.extractionModel('claude-sonnet-5-5'),
147
+ },
148
+ fallbackProvider: openai,
149
+ }),
150
+ anthropic,
151
+ });
152
+
153
+ const { answers } = await experimental_extract({
154
+ model: registry.extractionModel('invoices:fast'),
155
+ state: 'Invoice INV-2041, total due $1,250.00.',
156
+ fields: { total: { type: 'number', decimals: 2 } },
157
+ });
158
+ ```
159
+
160
+ Registry IDs use `providerId:modelId`. Custom aliases take precedence over a
161
+ fallback provider, and a fallback only resolves unknown model IDs.
162
+
163
+ String IDs passed directly to `experimental_extract` resolve through
164
+ `globalThis.AI_SDK_DEFAULT_PROVIDER.extractionModel(id)`. Vercel AI Gateway does
165
+ not provide extraction models yet, so configure a default provider with an
166
+ `extractionModel` method to use strings. This exposes an alias from the registry
167
+ above through a custom provider:
168
+
169
+ ```ts
170
+ globalThis.AI_SDK_DEFAULT_PROVIDER = customProvider({
171
+ extractionModels: { careful: registry.extractionModel('invoices:careful') },
172
+ });
173
+
174
+ await experimental_extract({
175
+ model: 'careful',
176
+ state: 'Invoice INV-2041, total due $1,250.00.',
177
+ fields: { total: { type: 'number', decimals: 2 } },
178
+ });
179
+ ```
180
+
181
+ Resolution errors use `NoSuchModelError` and `NoSuchProviderError` with
182
+ `modelType: 'extractionModel'`.
183
+
127
184
  ## Answers
128
185
 
129
186
  Every answer has the field's `type` and a `value`. `value` is `null` when the
@@ -1,6 +1,8 @@
1
1
  ---
2
2
  title: Image Generation
3
3
  description: Learn how to generate images with the AI SDK.
4
+ keywords:
5
+ - generate images
4
6
  ---
5
7
 
6
8
  # Image Generation
@@ -1,6 +1,9 @@
1
1
  ---
2
2
  title: Transcription
3
3
  description: Learn how to transcribe audio with the AI SDK.
4
+ keywords:
5
+ - speech to text
6
+ - audio transcription
4
7
  ---
5
8
 
6
9
  # Transcription
@@ -1,6 +1,9 @@
1
1
  ---
2
2
  title: Speech
3
3
  description: Learn how to generate speech from text with the AI SDK.
4
+ keywords:
5
+ - text to speech
6
+ - speech generation
4
7
  ---
5
8
 
6
9
  # Speech
@@ -224,6 +224,60 @@ the provider when supported by that provider's batch API. Their tool calls and
224
224
  results are returned as normalized `content` parts. See the provider
225
225
  documentation for the tools and models available in batches.
226
226
 
227
+ ## Structured output
228
+
229
+ `startBatch` accepts an `output` option for structured output. It is used by every
230
+ text request in the batch. Other batch formats, like image requests, ignore it.
231
+
232
+ ```ts
233
+ import {
234
+ experimental_getBatchResults as getBatchResults,
235
+ experimental_startBatch as startBatch,
236
+ Output,
237
+ } from 'ai';
238
+ import { z } from 'zod';
239
+
240
+ const output = Output.object({
241
+ schema: z.object({ translation: z.string() }),
242
+ });
243
+
244
+ const batch = await startBatch({
245
+ output,
246
+ requests: [
247
+ {
248
+ id: 'translate-1',
249
+ type: 'text',
250
+ model: 'openai/gpt-5-mini',
251
+ prompt: 'Translate to English: Directeur commercial',
252
+ },
253
+ ],
254
+ });
255
+ ```
256
+
257
+ Results are retrieved separately, so the AI SDK cannot carry the output type
258
+ across the two calls. Pass the same `output` to `getBatchResults` to parse and
259
+ validate each successful item:
260
+
261
+ ```ts
262
+ for await (const item of getBatchResults({ batch, output })) {
263
+ if (item.type === 'text' && item.status === 'succeeded') {
264
+ if (item.outputError == null) {
265
+ console.log(item.id, item.output); // typed from the schema
266
+ } else {
267
+ console.error(item.id, item.outputError.message, item.text);
268
+ }
269
+ }
270
+ }
271
+ ```
272
+
273
+ Parsing or validation failures don't fail the entire item. Instead, items get
274
+ an `outputError` instead of `output`. This lets you resubmit only the
275
+ requests whose response was not valid. Without `output`, the raw JSON is
276
+ available in `text`.
277
+
278
+ Because `output` applies to the whole batch, all text items are parsed with the
279
+ same specification. To use different schemas, start separate batches.
280
+
227
281
  ## Checking batch status
228
282
 
229
283
  The start result includes the initial status. Use `getBatchStatus` to retrieve
@@ -478,3 +478,11 @@ explicitly configured default provider with a `decisionModel` method. Registry
478
478
  middleware for language and image models does not apply to decision.
479
479
  See [Decisions](/docs/ai-sdk-core/decisions#model-aliases-and-registries)
480
480
  for aliases, default-provider configuration, and capability differences.
481
+
482
+ ## Experimental extraction models
483
+
484
+ Custom providers accept `extractionModels` aliases, and registries expose
485
+ `extractionModel('provider:model')`. These methods return model instances for
486
+ `experimental_extract`. Direct string IDs use an explicitly configured default
487
+ provider with an `extractionModel` method. See
488
+ [Extractions](/docs/ai-sdk-core/extractions#model-aliases-and-registries).