ai 7.0.128 → 7.0.130

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 (50) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/index.d.ts +19 -4
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +173 -39
  5. package/dist/index.js.map +1 -1
  6. package/dist/internal/index.d.ts +10 -2
  7. package/dist/internal/index.d.ts.map +1 -1
  8. package/dist/internal/index.js +68 -16
  9. package/dist/internal/index.js.map +1 -1
  10. package/docs/02-foundations/06-provider-options.mdx +11 -10
  11. package/docs/03-agents/02-building-agents.mdx +16 -11
  12. package/docs/03-agents/07-workflow-agent.mdx +3 -3
  13. package/docs/03-ai-sdk-core/17-runtime-and-tool-context.mdx +18 -14
  14. package/docs/03-ai-sdk-core/25-settings.mdx +3 -2
  15. package/docs/03-ai-sdk-core/26-reasoning.mdx +12 -5
  16. package/docs/03-ai-sdk-core/32-decisions.mdx +20 -20
  17. package/docs/03-ai-sdk-core/35-image-generation.mdx +2 -0
  18. package/docs/04-ai-sdk-ui/21-error-handling.mdx +28 -3
  19. package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2 -2
  20. package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +3 -3
  21. package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +2 -1
  22. package/docs/07-reference/05-ai-sdk-errors/ai-decision-refusal-error.mdx +33 -0
  23. package/package.json +15 -15
  24. package/src/decide/decide.ts +11 -0
  25. package/src/decide/validate-decision.ts +1 -0
  26. package/src/error/index.ts +1 -0
  27. package/src/generate-object/generate-object.ts +10 -0
  28. package/src/generate-object/stream-object.ts +10 -0
  29. package/src/generate-speech/index.ts +13 -1
  30. package/src/generate-text/generate-text.ts +3 -1
  31. package/src/generate-text/stream-text.ts +22 -5
  32. package/src/generate-text/tool-approval-signature.ts +7 -4
  33. package/src/global.ts +2 -1
  34. package/src/logger/deprecations.ts +72 -0
  35. package/src/logger/log-warnings.ts +25 -3
  36. package/src/model/as-language-model-v3.ts +4 -0
  37. package/src/prompt/convert-to-language-model-prompt.ts +7 -1
  38. package/src/realtime/encode-realtime-frame.ts +7 -2
  39. package/src/transcribe/index.ts +13 -1
  40. package/src/types/index.ts +1 -0
  41. package/src/types/language-model.ts +9 -1
  42. package/src/types/usage.ts +21 -0
  43. package/src/ui/chat.ts +16 -8
  44. package/src/ui/convert-to-model-messages.ts +40 -8
  45. package/src/ui/http-chat-transport.ts +5 -3
  46. package/src/ui/process-text-stream.ts +5 -1
  47. package/src/ui/text-stream-chat-transport.ts +3 -1
  48. package/src/ui/ui-messages.ts +8 -0
  49. package/src/ui/unavailable-tool.ts +17 -0
  50. package/src/ui/validate-ui-messages.ts +10 -2
@@ -69,18 +69,19 @@ console.log(
69
69
  );
70
70
  ```
71
71
 
72
- | Value | Behavior |
73
- | ----------- | ------------------------------------------ |
74
- | `'none'` | No reasoning (GPT-5.1 models only) |
75
- | `'minimal'` | Bare-minimum reasoning |
76
- | `'low'` | Fast, concise reasoning |
77
- | `'medium'` | Balanced (default) |
78
- | `'high'` | Thorough reasoning |
79
- | `'xhigh'` | Maximum reasoning (GPT-5.1-Codex-Max only) |
72
+ | Value | Behavior |
73
+ | ----------- | ---------------------------------------- |
74
+ | `'none'` | No reasoning (GPT-5.1 models only) |
75
+ | `'minimal'` | Bare-minimum reasoning |
76
+ | `'low'` | Fast, concise reasoning |
77
+ | `'medium'` | Balanced (default) |
78
+ | `'high'` | Thorough reasoning |
79
+ | `'xhigh'` | Extra-high reasoning on supported models |
80
+ | `'max'` | Maximum reasoning on supported models |
80
81
 
81
82
  <Note>
82
- `'none'` and `'xhigh'` are only supported on specific models. Using them with
83
- unsupported models will result in an error.
83
+ Supported effort levels vary by model. Using an effort with an unsupported
84
+ model will result in an error.
84
85
  </Note>
85
86
 
86
87
  ### Reasoning Summary
@@ -85,7 +85,9 @@ results. If a tool needs server-side values such as credentials, scoped
85
85
  permissions, or default settings, pass them through `toolsContext` and declare
86
86
  them with the tool's `contextSchema`.
87
87
 
88
- ```ts highlight="12-15,20-27,31-40"
88
+ Set `runtimeContext` and `toolsContext` in the `ToolLoopAgent` constructor.
89
+
90
+ ```ts
89
91
  import { ToolLoopAgent, tool } from 'ai';
90
92
  import { z } from 'zod';
91
93
 
@@ -105,6 +107,16 @@ const agent = new ToolLoopAgent({
105
107
  searchTickets(query, context.accountId, context.apiKey),
106
108
  }),
107
109
  },
110
+ runtimeContext: {
111
+ requestId: 'req_abc',
112
+ escalated: false,
113
+ },
114
+ toolsContext: {
115
+ searchTickets: {
116
+ apiKey: process.env.SUPPORT_API_KEY!,
117
+ accountId: 'acct_123',
118
+ },
119
+ },
108
120
  prepareStep: async ({ runtimeContext }) => {
109
121
  if (runtimeContext.escalated) {
110
122
  return { temperature: 0.1 };
@@ -116,19 +128,12 @@ const agent = new ToolLoopAgent({
116
128
 
117
129
  const result = await agent.generate({
118
130
  prompt: 'Find open billing tickets for this account.',
119
- runtimeContext: {
120
- requestId: 'req_abc',
121
- escalated: false,
122
- },
123
- toolsContext: {
124
- searchTickets: {
125
- apiKey: process.env.SUPPORT_API_KEY!,
126
- accountId: 'acct_123',
127
- },
128
- },
129
131
  });
130
132
  ```
131
133
 
134
+ For context that changes with each invocation, use `callOptionsSchema` and
135
+ `prepareCall`. See [Configuring Call Options](/docs/agents/configuring-call-options).
136
+
132
137
  Model call settings returned from `prepareStep`, such as `temperature`, apply
133
138
  only to the current step. Later steps use the agent's top-level setting unless
134
139
  they return another override.
@@ -36,10 +36,10 @@ For simpler use cases that don't need durability, use [`ToolLoopAgent`](/docs/ag
36
36
  ## Installation
37
37
 
38
38
  ```bash
39
- npm install @ai-sdk/workflow workflow@beta
39
+ npm install @ai-sdk/workflow workflow@5
40
40
  ```
41
41
 
42
- `@ai-sdk/workflow` requires Workflow 5, which is currently available under the `beta` tag, as well as the `ai` package and `zod` peer dependencies. The `workflow` package provides the Workflow DevKit runtime (`getWritable`, `'use workflow'`, `'use step'`).
42
+ `@ai-sdk/workflow` requires Workflow 5, as well as the `ai` package and `zod` peer dependencies. The `workflow` package provides the Workflow DevKit runtime (`getWritable`, `'use workflow'`, `'use step'`).
43
43
 
44
44
  ## Creating a WorkflowAgent
45
45
 
@@ -691,7 +691,7 @@ export type MyAgentUIMessage = InferWorkflowAgentUIMessage<typeof myAgent>;
691
691
  Install the new package alongside `workflow`:
692
692
 
693
693
  ```bash
694
- npm install @ai-sdk/workflow workflow@beta
694
+ npm install @ai-sdk/workflow workflow@5
695
695
  ```
696
696
 
697
697
  ### Write `ModelCallStreamPart`, not `UIMessageChunk`
@@ -16,14 +16,14 @@ should affect execution.
16
16
 
17
17
  ## Context Types
18
18
 
19
- | Concept | Where you define it | Where you read it | Use it for |
20
- | --------------------------------- | ------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
21
- | `runtimeContext` | `generateText`, `streamText`, or `ToolLoopAgent` calls | `prepareStep`, lifecycle callbacks, step results, and telemetry | Shared generation or agent state |
22
- | `toolsContext` | `generateText`, `streamText`, or `ToolLoopAgent` calls | `prepareStep`, approval callbacks, tool context resolution, and tool description functions | A map of per-tool context values keyed by tool name |
23
- | tool `context` | Each tool's `toolsContext` entry, validated by its `contextSchema` | Tool description functions, tool `execute`, `needsApproval`, and tool input lifecycle callbacks | Values needed by one tool |
24
- | `toolContext` | Derived from one tool's context | Tool approval callbacks and tool execution events | The event/callback name for one tool's context |
25
- | `telemetry.includeRuntimeContext` | The generation or agent call | Telemetry filtering | Top-level `runtimeContext` properties to include in telemetry |
26
- | `telemetry.includeToolsContext` | The generation or agent call | Telemetry filtering | Top-level tool context properties to include in telemetry |
19
+ | Concept | Where you define it | Where you read it | Use it for |
20
+ | --------------------------------- | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
21
+ | `runtimeContext` | `generateText` or `streamText` calls; `ToolLoopAgent` settings or `prepareCall` | `prepareStep`, lifecycle callbacks, step results, and telemetry | Shared generation or agent state |
22
+ | `toolsContext` | `generateText` or `streamText` calls; `ToolLoopAgent` settings or `prepareCall` | `prepareStep`, approval callbacks, tool context resolution, and tool description functions | A map of per-tool context values keyed by tool name |
23
+ | tool `context` | Each tool's `toolsContext` entry, validated by its `contextSchema` | Tool description functions, tool `execute`, `needsApproval`, and tool input lifecycle callbacks | Values needed by one tool |
24
+ | `toolContext` | Derived from one tool's context | Tool approval callbacks and tool execution events | The event/callback name for one tool's context |
25
+ | `telemetry.includeRuntimeContext` | The generation call or `ToolLoopAgent` settings | Telemetry filtering | Top-level `runtimeContext` properties to include in telemetry |
26
+ | `telemetry.includeToolsContext` | The generation call or `ToolLoopAgent` settings | Telemetry filtering | Top-level tool context properties to include in telemetry |
27
27
 
28
28
  In agents, `runtimeContext` is the agent's shared runtime state. It flows
29
29
  through the loop and can be read or updated in `prepareStep` between model
@@ -31,7 +31,7 @@ calls. Tool-specific data stays in `toolsContext`, where each tool receives only
31
31
  its own validated `context`.
32
32
 
33
33
  ```txt
34
- generateText / streamText / ToolLoopAgent
34
+ generateText / streamText / ToolLoopAgent settings
35
35
  -> runtimeContext
36
36
  -> prepareStep, lifecycle callbacks, step results
37
37
  -> telemetry, filtered by telemetry.includeRuntimeContext
@@ -123,6 +123,10 @@ Treat tool context as immutable inside tools. If you need to change tool context
123
123
  between steps, inspect the previous step in `prepareStep` and return an updated
124
124
  `toolsContext`.
125
125
 
126
+ For `ToolLoopAgent`, set context in the constructor. For context that changes
127
+ with each invocation, use `callOptionsSchema` and `prepareCall`. See
128
+ [Configuring Call Options](/docs/agents/configuring-call-options).
129
+
126
130
  ## Telemetry Context Filtering
127
131
 
128
132
  Context often contains values that are useful inside your application but should
@@ -131,7 +135,7 @@ include selected top-level runtime context properties in telemetry, and
131
135
  `telemetry.includeToolsContext` to include selected top-level tool context
132
136
  properties per tool.
133
137
 
134
- ```ts highlight="34-43"
138
+ ```ts
135
139
  import { ToolLoopAgent, tool } from 'ai';
136
140
  import { z } from 'zod';
137
141
 
@@ -156,10 +160,6 @@ const customerLookup = tool({
156
160
  const agent = new ToolLoopAgent({
157
161
  model: __MODEL__,
158
162
  tools: { customerLookup },
159
- });
160
-
161
- const result = await agent.generate({
162
- prompt: 'Check whether customer cust_123 is eligible for priority support.',
163
163
  runtimeContext: {
164
164
  requestId: 'req_abc',
165
165
  tenantId: 'tenant_123',
@@ -182,6 +182,10 @@ const result = await agent.generate({
182
182
  },
183
183
  },
184
184
  });
185
+
186
+ const result = await agent.generate({
187
+ prompt: 'Check whether customer cust_123 is eligible for priority support.',
188
+ });
185
189
  ```
186
190
 
187
191
  In this example, telemetry receives `runtimeContext` with only `requestId` and the
@@ -101,9 +101,10 @@ Controls how much reasoning the model performs before generating a response.
101
101
  | `'low'` | Fast, concise reasoning |
102
102
  | `'medium'` | Balanced reasoning |
103
103
  | `'high'` | Thorough reasoning |
104
- | `'xhigh'` | Maximum reasoning |
104
+ | `'xhigh'` | Extra-high reasoning |
105
+ | `'max'` | Maximum reasoning |
105
106
 
106
- If you also set reasoning-related options in `providerOptions` (e.g. `openai.reasoningEffort` or `anthropic.thinking`), the provider-specific options take precedence and the top-level `reasoning` parameter is ignored.
107
+ Provider-specific settings take precedence over the corresponding fields derived from `reasoning`. Partial configurations can still use portable reasoning to fill missing fields; summary and display options can be used alongside it. For example, Bedrock preserves an explicit thinking budget while deriving a missing enabled type from portable reasoning.
107
108
 
108
109
  See the [reasoning guide](/docs/ai-sdk-core/reasoning) for details on per-provider mapping and migration from `providerOptions`.
109
110
 
@@ -29,7 +29,8 @@ The `reasoning` parameter accepts the following values:
29
29
  | `'low'` | Fast, concise reasoning |
30
30
  | `'medium'` | Balanced reasoning |
31
31
  | `'high'` | Thorough reasoning |
32
- | `'xhigh'` | Maximum reasoning |
32
+ | `'xhigh'` | Extra-high reasoning |
33
+ | `'max'` | Maximum reasoning |
33
34
 
34
35
  ## Streaming
35
36
 
@@ -55,7 +56,7 @@ for await (const part of result.stream) {
55
56
 
56
57
  ## Precedence Rules
57
58
 
58
- The top-level `reasoning` parameter and provider-specific `providerOptions` are **never merged**. If you set reasoning-related options in `providerOptions`, they take full precedence and the top-level `reasoning` parameter is ignored.
59
+ Provider-specific settings take precedence over the corresponding fields derived from `reasoning`. Partial configurations may still use portable reasoning to fill missing fields; summary and display settings can be used alongside it.
59
60
 
60
61
  ```ts
61
62
  import { generateText } from 'ai';
@@ -77,9 +78,15 @@ This design lets you use the portable `reasoning` parameter by default and fall
77
78
 
78
79
  ## Provider Support
79
80
 
80
- The `reasoning` parameter is supported by the following providers: OpenAI, Anthropic, Google, xAI, Groq, DeepSeek, Fireworks, Amazon Bedrock, and Perplexity. Each provider translates the value to its native reasoning API. Some providers support all six levels natively, while others coerce to fewer levels (a warning is emitted when coercion occurs). Some providers use a numeric token budget instead of an enum for reasoning control; in those cases the top-level `reasoning` value is mapped to a budget calculated as a percentage of the model's maximum output tokens.
81
+ The `reasoning` parameter is supported by providers including OpenAI, Anthropic, Google, xAI, Groq, DeepSeek, Moonshot AI, Fireworks, Amazon Bedrock, Mistral, Cohere, Alibaba, Open Responses, OpenAI Compatible, and Perplexity. Each provider translates the value to its native reasoning API.
81
82
 
82
- Providers that do not support reasoning (e.g. Mistral and Cohere) emit an `unsupported` warning and ignore the parameter.
83
+ Providers with a distinct native maximum tier, such as supported OpenAI, Anthropic, DeepSeek, and Moonshot AI models, receive `'max'` directly. Amazon Bedrock preserves `'max'` for its Anthropic and OpenAI effort mappings, while Amazon Nova 2 maps `'xhigh'` and `'max'` to `'high'` with a compatibility warning. Providers whose highest native tier is lower coerce `'max'` to their closest supported tier and emit a compatibility warning when their adapter supports warning propagation. OpenAI-compatible and Open Responses endpoints receive `'max'` directly so compatible servers can interpret it.
84
+
85
+ Some providers use a numeric token budget instead of an enum for reasoning control. In those cases, `'max'` maps to 95% of the model's maximum output tokens by default, subject to the provider's minimum and maximum reasoning budget limits.
86
+
87
+ Maximum reasoning can substantially increase token usage, latency, cost, and the chance of reaching request or output limits. Use it when the model's additional reasoning depth is worth those tradeoffs.
88
+
89
+ Providers and models that do not support reasoning configuration emit an `unsupported` warning and ignore the parameter.
83
90
 
84
91
  ## Migrating from `providerOptions`
85
92
 
@@ -188,4 +195,4 @@ const { text } = await generateText({
188
195
  });
189
196
  ```
190
197
 
191
- Note that `providerOptions` can still be used alongside `reasoning` for provider-specific features unrelated to reasoning effort. However, if `providerOptions` includes reasoning effort/budget settings (e.g. `reasoningEffort`, `thinking`, `thinkingConfig.thinkingBudget`), those take full precedence and the top-level `reasoning` parameter is ignored.
198
+ You can combine `providerOptions` with `reasoning` for provider-specific features such as reasoning summaries or display settings. Explicit effort or budget values override the corresponding mapped fields; partial configurations may still use portable reasoning to fill missing fields. See [Precedence Rules](#precedence-rules) for details.
@@ -51,29 +51,26 @@ Use a provider's `decisionModel` factory:
51
51
  | Provider | Example model |
52
52
  | ----------- | ------------------------------------------------------ |
53
53
  | TypeSafe AI | `typeSafeAi.decisionModel('jev-latest')` |
54
- | OpenAI | `openai.decisionModel('gpt-5.6-luna')` |
54
+ | OpenAI | `openai.decisionModel('gpt-6-luna')` |
55
55
  | Anthropic | `anthropic.decisionModel('claude-haiku-4-5-20251001')` |
56
56
  | Google | `google.decisionModel('gemini-3.5-flash-lite')` |
57
57
 
58
- TypeSafe AI's [Jev](https://vercel.com/i/what-is-jev) supplies native Choice, Score, and Boolean decisions. OpenAI,
59
- Anthropic, and Google adapt structured language-model output for all three types.
60
- Boolean answers contain prompted estimates of P(true), validated to be finite
61
- and in `[0, 1]`. These estimates are not guaranteed to be calibrated. Choice and
62
- Score answers do not include probability distributions. Select a model that
63
- supports the provider's structured-output API; judge quality against your own
64
- labeled examples before choosing a model for a task.
65
-
66
- The language-model adapters decide all answers in one prompt. They do not
67
- provide TypeSafe's native independent-question execution semantics. The example
68
- model IDs demonstrate API compatibility; they are not benchmark-selected defaults.
69
-
70
- Language-model adapters request `reasoning: 'none'` by default. Each provider
71
- maps this setting to its model's reasoning controls; it does not guarantee that
72
- every model runs without thinking. To enable reasoning for more demanding
73
- decisions, pass the model's supported reasoning settings through
74
- `providerOptions`, which take precedence over this default. For example, use
75
- `providerOptions: { openai: { reasoningEffort: 'high' } }` with an OpenAI model
76
- that supports that effort.
58
+ TypeSafe AI's [Jev](https://vercel.com/i/what-is-jev) and OpenAI's
59
+ [Decisions API](https://developers.openai.com/api/docs/guides/decisions)
60
+ supply native Choice, Score, and Boolean decisions. Each question is evaluated
61
+ independently. Choice and Score answers include native probability distributions.
62
+
63
+ Anthropic and Google adapt structured language-model output for all three types,
64
+ evaluating all questions in one prompt. Their Boolean answers contain prompted
65
+ estimates of P(true), and Choice and Score answers omit probability distributions.
66
+ Select a model that supports the provider's structured-output API and judge quality
67
+ against your own labeled examples before choosing a model for a task.
68
+
69
+ The Anthropic and Google language-model adapters request `reasoning: 'none'` by
70
+ default. Each provider maps this setting to its model's reasoning controls. Pass
71
+ supported reasoning settings through `providerOptions` to override this default.
72
+ OpenAI decision models use the Decisions endpoint and do not accept Responses
73
+ API reasoning options.
77
74
 
78
75
  ## Model aliases and registries
79
76
 
@@ -251,6 +248,9 @@ substitute models automatically.
251
248
 
252
249
  Invalid inputs throw `InvalidArgumentError`. Missing answers, mismatched answer
253
250
  types, invalid options, scores, or probabilities throw `InvalidResponseDataError`.
251
+ If the model refuses any question, the call throws
252
+ `Experimental_DecisionRefusalError` with the refused question IDs, and is not
253
+ retried.
254
254
  Transient provider failures use the normal retry policy (`maxRetries: 2` by
255
255
  default). Use `abortSignal` to cancel the decisions request, `headers` for request headers,
256
256
  and `providerOptions` for provider-specific settings.
@@ -378,9 +378,11 @@ for (const file of result.files) {
378
378
  | [Google](/providers/ai-sdk-providers/google#image-models) | `gemini-2.5-flash-image` | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
379
379
  | [Google](/providers/ai-sdk-providers/google#image-models) | `gemini-3-pro-image-preview` | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
380
380
  | [Google](/providers/ai-sdk-providers/google#image-models) | `gemini-3.1-flash-image-preview` | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
381
+ | [Google](/providers/ai-sdk-providers/google#image-models) | `gemini-nano-banana-2.1` | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, 1:8, 8:1, 1:4, 4:1 |
381
382
  | [Google Vertex](/providers/ai-sdk-providers/google-vertex#image-models) | `gemini-2.5-flash-image` | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
382
383
  | [Google Vertex](/providers/ai-sdk-providers/google-vertex#image-models) | `gemini-3-pro-image-preview` | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
383
384
  | [Google Vertex](/providers/ai-sdk-providers/google-vertex#image-models) | `gemini-3.1-flash-image-preview` | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
385
+ | [Google Vertex](/providers/ai-sdk-providers/google-vertex#image-models) | `gemini-nano-banana-2.1` | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, 1:8, 8:1, 1:4, 4:1 |
384
386
  | [Fireworks](/providers/ai-sdk-providers/fireworks#image-models) | `accounts/fireworks/models/flux-1-dev-fp8` | 1:1, 2:3, 3:2, 4:5, 5:4, 16:9, 9:16, 9:21, 21:9 |
385
387
  | [Fireworks](/providers/ai-sdk-providers/fireworks#image-models) | `accounts/fireworks/models/flux-1-schnell-fp8` | 1:1, 2:3, 3:2, 4:5, 5:4, 16:9, 9:16, 9:21, 21:9 |
386
388
  | [Fireworks](/providers/ai-sdk-providers/fireworks#image-models) | `accounts/fireworks/models/playground-v2-5-1024px-aesthetic` | 640x1536, 768x1344, 832x1216, 896x1152, 1024x1024, 1152x896, 1216x832, 1344x768, 1536x640 |
@@ -12,15 +12,17 @@ These warnings help you fix problems before they cause errors.
12
12
 
13
13
  ### When Warnings Appear
14
14
 
15
- Warnings are shown in the browser console when:
15
+ Warnings use Node.js `process.emitWarning` when available and `console.warn` in
16
+ browser/edge runtimes. They appear when:
16
17
 
17
18
  - **Unsupported features**: You use a feature or setting that is not supported by the AI model (e.g., certain options or parameters).
18
19
  - **Compatibility warnings**: A feature is used in a compatibility mode, which might work differently or less optimally than intended.
20
+ - **Deprecations**: You use a deprecated API, option, or message format.
19
21
  - **Other warnings**: The AI model reports another type of issue, such as general problems or advisory messages.
20
22
 
21
23
  ### Warning Messages
22
24
 
23
- All warnings start with "AI SDK Warning:" so you can easily find them. For example:
25
+ All warnings include "AI SDK Warning" so you can easily find them. For example:
24
26
 
25
27
  ```
26
28
  AI SDK Warning: The feature "temperature" is not supported by this model
@@ -41,7 +43,8 @@ globalThis.AI_SDK_LOG_WARNINGS = false;
41
43
  #### Custom Warning Handler
42
44
 
43
45
  You can also provide your own function to handle warnings.
44
- It receives provider id, model id, and a list of warnings.
46
+ It receives a list of warnings and optional provider and model ids. Custom
47
+ handlers receive every warning, including repeated deprecations.
45
48
 
46
49
  ```ts
47
50
  globalThis.AI_SDK_LOG_WARNINGS = ({ warnings, provider, model }) => {
@@ -49,6 +52,28 @@ globalThis.AI_SDK_LOG_WARNINGS = ({ warnings, provider, model }) => {
49
52
  };
50
53
  ```
51
54
 
55
+ ### Deprecation Warnings
56
+
57
+ The default logger emits each deprecation code once per loaded SDK instance.
58
+ In Node.js, these warnings have the type `DeprecationWarning` and a stable
59
+ `AISDK_DEP_*` code, available as `warning.code` on `process.on('warning', handler)`.
60
+ Browser/edge console messages include the code in brackets.
61
+
62
+ | Code | Deprecated usage / replacement |
63
+ | ---------------------------------------- | -------------------------------------------------------------------------- |
64
+ | `AISDK_DEP_GENERATE_OBJECT` | Use `generateText` with `output` instead of `generateObject`. |
65
+ | `AISDK_DEP_STREAM_OBJECT` | Use `streamText` with `output` instead of `streamObject`. |
66
+ | `AISDK_DEP_EXPERIMENTAL_GENERATE_SPEECH` | Use `generateSpeech` instead of `experimental_generateSpeech`. |
67
+ | `AISDK_DEP_EXPERIMENTAL_TRANSCRIBE` | Use `transcribe` instead of `experimental_transcribe`. |
68
+ | `AISDK_DEP_TOOL_RESULT_*` | Use `file` with tagged `data` instead of legacy tool-result content types. |
69
+ | `AISDK_DEP_UI_MESSAGE_RAW_INPUT` | Use `input` instead of `rawInput` in UI tool parts. |
70
+ | `AISDK_DEP_IMAGE_CONTENT_PART` | Use `file` with an image `mediaType` instead of `image` message parts. |
71
+
72
+ Run Node.js with `--throw-deprecation` to fail on deprecated usage,
73
+ `--no-deprecation` to suppress deprecations, or `--trace-deprecation` for stack
74
+ traces. These flags affect all `DeprecationWarning`s, rather than individual
75
+ codes, and apply only to the default Node.js logger.
76
+
52
77
  ## Error Handling
53
78
 
54
79
  ### Error Helper Object
@@ -455,10 +455,10 @@ To see `generateText` in action, check out [these examples](#examples).
455
455
  },
456
456
  {
457
457
  name: 'reasoning',
458
- type: "'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'",
458
+ type: "'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'",
459
459
  isOptional: true,
460
460
  description:
461
- "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.",
461
+ "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. Provider-specific settings take precedence over corresponding mapped fields. Partial configurations may still use portable reasoning to fill missing fields; summary and display settings can be combined with it. See the [reasoning guide](/docs/ai-sdk-core/reasoning) for provider-specific mapping details.",
462
462
  },
463
463
  {
464
464
  name: 'maxRetries',
@@ -456,10 +456,10 @@ To see `streamText` in action, check out [these examples](#examples).
456
456
  },
457
457
  {
458
458
  name: 'reasoning',
459
- type: "'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'",
459
+ type: "'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'",
460
460
  isOptional: true,
461
461
  description:
462
- "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.",
462
+ "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. Provider-specific settings take precedence over corresponding mapped fields. Partial configurations may still use portable reasoning to fill missing fields; summary and display settings can be combined with it. See the [reasoning guide](/docs/ai-sdk-core/reasoning) for provider-specific mapping details.",
463
463
  },
464
464
  {
465
465
  name: 'maxRetries',
@@ -480,7 +480,7 @@ To see `streamText` in action, check out [these examples](#examples).
480
480
  type: 'AbortSignal',
481
481
  isOptional: true,
482
482
  description:
483
- 'An optional abort signal that can be used to cancel the call.',
483
+ 'An optional abort signal that can be used to cancel the call. When it fires during streaming, pending result promises such as text and steps reject with the abort reason without waiting for onAbort or provider cancellation. Completed steps are available through onAbort.',
484
484
  },
485
485
  {
486
486
  name: 'timeout',
@@ -57,7 +57,8 @@ The public core types are `Experimental_DecisionModel`,
57
57
 
58
58
  Unsupported types throw `Experimental_DecisionUnsupportedQuestionTypeError`
59
59
  before provider I/O. Invalid inputs throw `InvalidArgumentError`; malformed
60
- answers throw `InvalidResponseDataError`. Invalid answers are not retried.
60
+ answers throw `InvalidResponseDataError`. Questions the model refuses throw
61
+ `Experimental_DecisionRefusalError`. Invalid answers and refusals are not retried.
61
62
  Neither partial results nor missing probability synthesis are supported.
62
63
 
63
64
  ## Model resolution
@@ -0,0 +1,33 @@
1
+ ---
2
+ title: AI_DecisionRefusalError
3
+ description: Identify decision questions that a model declined to answer.
4
+ ---
5
+
6
+ # AI_DecisionRefusalError
7
+
8
+ This experimental error identifies questions that a decision model declined to
9
+ answer, such as a question the provider's safety policy refuses. It is exported
10
+ from `ai` and `@ai-sdk/provider` as `Experimental_DecisionRefusalError`.
11
+
12
+ Decision models report a refusal as an answer with `type: 'refusal'`.
13
+ `experimental_decide` throws this error when any answer is a refusal, after the
14
+ provider call and without retrying it.
15
+
16
+ ## Properties
17
+
18
+ - `questionIds`: The IDs of the refused questions.
19
+ - `provider`: The provider of the decision model.
20
+ - `modelId`: The decision model ID.
21
+ - `message`: A description of the refused questions and model.
22
+
23
+ ## Checking for this Error
24
+
25
+ Use the marker-based `isInstance` check, which works across package copies:
26
+
27
+ ```typescript
28
+ import { Experimental_DecisionRefusalError as DecisionRefusalError } from 'ai';
29
+
30
+ if (DecisionRefusalError.isInstance(error)) {
31
+ console.log(error.questionIds, error.modelId);
32
+ }
33
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "7.0.128",
3
+ "version": "7.0.130",
4
4
  "type": "module",
5
5
  "description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
6
6
  "license": "Apache-2.0",
@@ -42,30 +42,30 @@
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "@ai-sdk/gateway": "4.0.104",
46
- "@ai-sdk/provider": "4.0.22",
47
- "@ai-sdk/provider-utils": "5.0.54"
45
+ "@ai-sdk/gateway": "4.0.106",
46
+ "@ai-sdk/provider": "4.0.24",
47
+ "@ai-sdk/provider-utils": "5.0.56"
48
48
  },
49
49
  "devDependencies": {
50
- "@ai-sdk/amazon-bedrock": "5.0.106",
51
- "@ai-sdk/deepseek": "3.0.59",
52
- "@ai-sdk/google": "4.0.88",
53
- "@ai-sdk/groq": "4.0.55",
54
- "@ai-sdk/huggingface": "2.0.63",
55
- "@ai-sdk/moonshotai": "3.0.63",
56
- "@ai-sdk/openai": "4.0.84",
57
- "@ai-sdk/test-server": "2.0.3",
58
- "@ai-sdk/xai": "5.0.15",
50
+ "@ai-sdk/amazon-bedrock": "5.0.108",
51
+ "@ai-sdk/deepseek": "3.0.61",
52
+ "@ai-sdk/google": "4.0.90",
53
+ "@ai-sdk/groq": "4.0.57",
54
+ "@ai-sdk/huggingface": "2.0.65",
55
+ "@ai-sdk/moonshotai": "3.0.65",
56
+ "@ai-sdk/openai": "4.0.86",
57
+ "@ai-sdk/test-server": "2.0.4",
58
+ "@ai-sdk/xai": "5.0.17",
59
59
  "@edge-runtime/vm": "^5.0.0",
60
60
  "@smithy/eventstream-codec": "^4.3.3",
61
61
  "@smithy/util-utf8": "^4.3.3",
62
62
  "@types/json-schema": "7.0.15",
63
63
  "@types/node": "22.19.19",
64
64
  "@vercel/ai-tsconfig": "0.0.0",
65
- "esbuild": "^0.28.1",
65
+ "esbuild": "^0.28.2",
66
66
  "tsdown": "^0.23.0",
67
67
  "tsx": "4.23.12",
68
- "typescript": "5.8.3",
68
+ "typescript": "6.0.3",
69
69
  "zod": "3.25.76"
70
70
  },
71
71
  "peerDependencies": {
@@ -1,4 +1,5 @@
1
1
  import {
2
+ Experimental_DecisionRefusalError as DecisionRefusalError,
2
3
  Experimental_DecisionUnsupportedQuestionTypeError as DecisionUnsupportedQuestionTypeError,
3
4
  type Experimental_DecisionModelV4CallOptions as DecisionModelV4CallOptions,
4
5
  } from '@ai-sdk/provider';
@@ -152,6 +153,16 @@ export async function decide<
152
153
  answers: result.answers,
153
154
  rounding: result.rounding,
154
155
  });
156
+ const refusedQuestionIds = Object.keys(questions).filter(
157
+ id => result.answers[id]?.type === 'refusal',
158
+ );
159
+ if (refusedQuestionIds.length > 0) {
160
+ throw new DecisionRefusalError({
161
+ questionIds: refusedQuestionIds,
162
+ provider: model.provider,
163
+ modelId: model.modelId,
164
+ });
165
+ }
155
166
  await notify({
156
167
  event: { ...modelCallEvent, ...result },
157
168
  callbacks: [telemetryDispatcher.experimental_onDecisionModelCallEnd],
@@ -203,6 +203,7 @@ export function validateDecisionAnswers({
203
203
 
204
204
  for (const [id, question] of Object.entries(questions)) {
205
205
  const answer = answers[id];
206
+ if (isRecord(answer) && answer.type === 'refusal') continue;
206
207
  if (!isRecord(answer) || answer.type !== question.type) {
207
208
  invalidAnswer(
208
209
  answers,
@@ -4,6 +4,7 @@ export {
4
4
  AISDKError,
5
5
  APICallError,
6
6
  EmptyResponseBodyError,
7
+ Experimental_DecisionRefusalError,
7
8
  Experimental_DecisionUnsupportedQuestionTypeError,
8
9
  InvalidPromptError,
9
10
  InvalidResponseDataError,
@@ -263,6 +263,16 @@ export async function generateObject<
263
263
  };
264
264
  },
265
265
  ): Promise<GenerateObjectResult<RESULT>> {
266
+ logWarnings({
267
+ warnings: [
268
+ {
269
+ type: 'deprecated',
270
+ setting: 'generateObject',
271
+ message: 'Use generateText with an output setting instead.',
272
+ },
273
+ ],
274
+ });
275
+
266
276
  const {
267
277
  model: modelArg,
268
278
  output = 'object',
@@ -353,6 +353,16 @@ export function streamObject<
353
353
  : never
354
354
  : never
355
355
  > {
356
+ logWarnings({
357
+ warnings: [
358
+ {
359
+ type: 'deprecated',
360
+ setting: 'streamObject',
361
+ message: 'Use streamText with an output setting instead.',
362
+ },
363
+ ],
364
+ });
365
+
356
366
  const {
357
367
  model,
358
368
  output = 'object',
@@ -1,5 +1,6 @@
1
1
  import type { SpeechResult } from './generate-speech-result';
2
2
  import { generateSpeech } from './generate-speech';
3
+ import { logWarnings } from '../logger/log-warnings';
3
4
 
4
5
  export { generateSpeech } from './generate-speech';
5
6
  export type { SpeechResult } from './generate-speech-result';
@@ -14,7 +15,18 @@ export type {
14
15
  /**
15
16
  * @deprecated Use `generateSpeech` instead.
16
17
  */
17
- const experimental_generateSpeech = generateSpeech;
18
+ const experimental_generateSpeech: typeof generateSpeech = options => {
19
+ logWarnings({
20
+ warnings: [
21
+ {
22
+ type: 'deprecated',
23
+ setting: 'experimental_generateSpeech',
24
+ message: 'Use generateSpeech instead.',
25
+ },
26
+ ],
27
+ });
28
+ return generateSpeech(options);
29
+ };
18
30
  export { experimental_generateSpeech };
19
31
 
20
32
  /**