ai 7.0.127 → 7.0.129
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.
- package/CHANGELOG.md +53 -0
- package/dist/index.d.ts +230 -155
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +386 -209
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +288 -70
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +407 -76
- package/dist/internal/index.js.map +1 -1
- package/dist/test/index.d.ts +25 -17
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +27 -21
- package/dist/test/index.js.map +1 -1
- package/docs/02-foundations/06-provider-options.mdx +11 -10
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +1 -1
- package/docs/02-getting-started/07-expo.mdx +1 -1
- package/docs/03-agents/02-building-agents.mdx +16 -11
- package/docs/03-agents/07-workflow-agent.mdx +83 -15
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +44 -0
- package/docs/03-ai-sdk-core/17-runtime-and-tool-context.mdx +18 -14
- package/docs/03-ai-sdk-core/25-settings.mdx +3 -2
- package/docs/03-ai-sdk-core/26-reasoning.mdx +12 -5
- package/docs/03-ai-sdk-core/{32-evaluation.mdx → 32-decisions.mdx} +64 -67
- package/docs/03-ai-sdk-core/35-image-generation.mdx +3 -1
- package/docs/03-ai-sdk-core/45-provider-management.mdx +8 -8
- package/docs/03-ai-sdk-core/60-telemetry.mdx +40 -31
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +21 -22
- package/docs/03-ai-sdk-harnesses/08-terminal-ui.mdx +2 -2
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +28 -3
- package/docs/06-advanced/09-multistep-interfaces.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +74 -0
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +58 -4
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +11 -11
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +9 -9
- package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +24 -8
- package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +1 -1
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +1 -0
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +39 -2
- package/docs/07-reference/05-ai-sdk-errors/ai-decision-unsupported-question-type-error.mdx +31 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +3 -3
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +3 -3
- package/docs/08-migration-guides/23-migration-guide-7-0.mdx +1 -1
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1 -1
- package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +2 -2
- package/package.json +15 -15
- package/src/decide/decide-events.ts +129 -0
- package/src/{evaluate/evaluate.ts → decide/decide.ts} +36 -38
- package/src/decide/decision-provider.ts +11 -0
- package/src/decide/decision-result.ts +39 -0
- package/src/decide/index.ts +64 -0
- package/src/{evaluate → decide}/restricted-telemetry-dispatcher.ts +7 -7
- package/src/{evaluate/validate-evaluation.ts → decide/validate-decision.ts} +9 -9
- package/src/error/index.ts +10 -1
- package/src/generate-object/generate-object.ts +10 -0
- package/src/generate-object/stream-object.ts +10 -0
- package/src/generate-speech/generated-audio-file.ts +5 -4
- package/src/generate-speech/index.ts +13 -1
- package/src/generate-text/default-generate-text-result.ts +127 -0
- package/src/generate-text/generate-text.ts +5 -123
- package/src/generate-text/tool-approval-signature.ts +7 -4
- package/src/global.ts +3 -2
- package/src/index.ts +1 -1
- package/src/logger/deprecations.ts +72 -0
- package/src/logger/log-warnings.ts +25 -3
- package/src/middleware/extract-reasoning-middleware.ts +25 -6
- package/src/model/as-language-model-v3.ts +4 -0
- package/src/model/resolve-model.ts +45 -14
- package/src/prompt/convert-to-language-model-prompt.ts +7 -1
- package/src/realtime/encode-realtime-frame.ts +7 -2
- package/src/registry/custom-provider.ts +38 -26
- package/src/registry/index.ts +13 -1
- package/src/registry/no-such-provider-error.ts +2 -0
- package/src/registry/provider-registry.ts +56 -29
- package/src/telemetry/create-telemetry-dispatcher.ts +17 -5
- package/src/telemetry/telemetry.ts +35 -19
- package/src/telemetry/tracing-channel.ts +1 -1
- package/src/test/decision-mock-model-v4.ts +35 -0
- package/src/transcribe/index.ts +13 -1
- package/src/transcribe/transcribe.ts +1 -1
- package/src/types/index.ts +1 -0
- package/src/types/language-model.ts +9 -1
- package/src/types/usage.ts +21 -0
- package/src/ui/chat.ts +25 -9
- package/src/ui/convert-to-model-messages.ts +40 -8
- package/src/ui/http-chat-transport.ts +5 -3
- package/src/ui/process-text-stream.ts +5 -1
- package/src/ui/process-ui-message-stream.ts +21 -0
- package/src/ui/text-stream-chat-transport.ts +3 -1
- package/src/ui/ui-messages.ts +8 -0
- package/src/ui/unavailable-tool.ts +17 -0
- package/src/ui/validate-ui-messages.ts +10 -2
- package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +0 -74
- package/docs/07-reference/05-ai-sdk-errors/ai-evaluation-unsupported-question-type-error.mdx +0 -31
- package/src/evaluate/evaluate-events.ts +0 -131
- package/src/evaluate/evaluation-provider.ts +0 -6
- package/src/evaluate/evaluation-result.ts +0 -39
- package/src/evaluate/index.ts +0 -13
- package/src/test/evaluation-mock-model-v4.ts +0 -27
|
@@ -203,6 +203,11 @@ authorization and reads the stored tokens again.
|
|
|
203
203
|
The SDK also provides this context when invalidating stored tokens that lack an
|
|
204
204
|
authorization server pin. Other invalidations can omit the context.
|
|
205
205
|
|
|
206
|
+
If an authorization-code exchange returns `invalid_grant`, the SDK propagates
|
|
207
|
+
the error without invalidating stored credentials or retrying the rejected code.
|
|
208
|
+
A rejected authorization code does not indicate that existing access or refresh
|
|
209
|
+
tokens are invalid.
|
|
210
|
+
|
|
206
211
|
### OAuth Authorization Server Validation
|
|
207
212
|
|
|
208
213
|
When using MCP OAuth in server-side applications, the MCP server can advertise
|
|
@@ -314,6 +319,45 @@ invalid tool arguments, are surfaced immediately without retrying. Successful
|
|
|
314
319
|
MCP tool responses with `isError: true` are also returned to the model without
|
|
315
320
|
retrying.
|
|
316
321
|
|
|
322
|
+
`maxRetries` applies to `tools/call` requests, not to client initialization.
|
|
323
|
+
The following example identifies potentially transient HTTP initialization
|
|
324
|
+
failures using the exported `MCPClientError` type guard:
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
import { createMCPClient, MCPClientError } from '@ai-sdk/mcp';
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
await createMCPClient({
|
|
331
|
+
transport: {
|
|
332
|
+
type: 'http',
|
|
333
|
+
url: 'https://your-server.com/mcp',
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
} catch (error) {
|
|
337
|
+
if (
|
|
338
|
+
!MCPClientError.isInstance(error) ||
|
|
339
|
+
error.code != null ||
|
|
340
|
+
error.statusCode == null ||
|
|
341
|
+
!(
|
|
342
|
+
error.statusCode === 408 ||
|
|
343
|
+
error.statusCode === 409 ||
|
|
344
|
+
error.statusCode === 429 ||
|
|
345
|
+
error.statusCode >= 500
|
|
346
|
+
)
|
|
347
|
+
) {
|
|
348
|
+
throw error;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Retry according to your application's backoff policy.
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
This example only considers HTTP statuses. A missing `statusCode` does not
|
|
356
|
+
establish that a failure is transient: configuration errors, protocol errors,
|
|
357
|
+
and cancelled requests can also lack an HTTP status. Network and timeout
|
|
358
|
+
retries require a separate application policy. OAuth errors such as
|
|
359
|
+
`UnauthorizedError` and `MCPClientOAuthError` are rethrown by this example.
|
|
360
|
+
|
|
317
361
|
<Note type="warning">
|
|
318
362
|
Only enable retries for MCP tools where retrying is safe. Retrying
|
|
319
363
|
non-idempotent tools, such as tools that send emails or create records, can
|
|
@@ -16,14 +16,14 @@ should affect execution.
|
|
|
16
16
|
|
|
17
17
|
## Context Types
|
|
18
18
|
|
|
19
|
-
| Concept | Where you define it
|
|
20
|
-
| --------------------------------- |
|
|
21
|
-
| `runtimeContext` | `generateText
|
|
22
|
-
| `toolsContext` | `generateText
|
|
23
|
-
| tool `context` | Each tool's `toolsContext` entry, validated by its `contextSchema`
|
|
24
|
-
| `toolContext` | Derived from one tool's context
|
|
25
|
-
| `telemetry.includeRuntimeContext` | The generation or
|
|
26
|
-
| `telemetry.includeToolsContext` | The generation or
|
|
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
|
|
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'` |
|
|
104
|
+
| `'xhigh'` | Extra-high reasoning |
|
|
105
|
+
| `'max'` | Maximum reasoning |
|
|
105
106
|
|
|
106
|
-
|
|
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'` |
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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.
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
3
|
-
description:
|
|
2
|
+
title: Decisions
|
|
3
|
+
description: Decide answers to Choice, Score, and Boolean questions against shared state.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# Decisions
|
|
7
7
|
|
|
8
|
-
`
|
|
9
|
-
|
|
8
|
+
`experimental_decide` decides answers to named questions against one shared state using
|
|
9
|
+
a decision model. State can be a string, JSON object, or JSON array. An array
|
|
10
10
|
is one state, not a batch of unrelated inputs.
|
|
11
11
|
|
|
12
|
-
This API and the
|
|
13
|
-
in patch releases. Pass
|
|
12
|
+
This API and the decision model specification are experimental and may change
|
|
13
|
+
in patch releases. Pass a decision model instance, resolve a model through a
|
|
14
14
|
provider registry, or use a string ID. Strings resolve through Vercel AI Gateway
|
|
15
|
-
unless you configure
|
|
15
|
+
unless you configure a decision-capable default provider.
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import {
|
|
18
|
+
import { experimental_decide, type Experimental_DecisionModel } from 'ai';
|
|
19
19
|
|
|
20
|
-
async function triage(model:
|
|
21
|
-
return
|
|
20
|
+
async function triage(model: Experimental_DecisionModel, message: string) {
|
|
21
|
+
return experimental_decide({
|
|
22
22
|
model,
|
|
23
23
|
state: { message },
|
|
24
24
|
questions: {
|
|
@@ -46,34 +46,31 @@ async function triage(model: Experimental_EvaluationModel, message: string) {
|
|
|
46
46
|
|
|
47
47
|
## Provider models
|
|
48
48
|
|
|
49
|
-
Use a provider's `
|
|
50
|
-
|
|
51
|
-
| Provider | Example model
|
|
52
|
-
| ----------- |
|
|
53
|
-
| TypeSafe AI | `typeSafeAi.
|
|
54
|
-
| OpenAI | `openai.
|
|
55
|
-
| Anthropic | `anthropic.
|
|
56
|
-
| Google | `google.
|
|
57
|
-
|
|
58
|
-
TypeSafe AI's [Jev](https://vercel.com/i/what-is-jev)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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.
|
|
49
|
+
Use a provider's `decisionModel` factory:
|
|
50
|
+
|
|
51
|
+
| Provider | Example model |
|
|
52
|
+
| ----------- | ------------------------------------------------------ |
|
|
53
|
+
| TypeSafe AI | `typeSafeAi.decisionModel('jev-latest')` |
|
|
54
|
+
| OpenAI | `openai.decisionModel('gpt-6-luna')` |
|
|
55
|
+
| Anthropic | `anthropic.decisionModel('claude-haiku-4-5-20251001')` |
|
|
56
|
+
| Google | `google.decisionModel('gemini-3.5-flash-lite')` |
|
|
57
|
+
|
|
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
|
|
|
@@ -86,22 +83,22 @@ import { openai } from '@ai-sdk/openai';
|
|
|
86
83
|
import {
|
|
87
84
|
customProvider,
|
|
88
85
|
createProviderRegistry,
|
|
89
|
-
|
|
86
|
+
experimental_decide,
|
|
90
87
|
} from 'ai';
|
|
91
88
|
|
|
92
89
|
const registry = createProviderRegistry({
|
|
93
90
|
triage: customProvider({
|
|
94
|
-
|
|
95
|
-
native: typeSafeAi.
|
|
96
|
-
compact: openai.
|
|
91
|
+
decisionModels: {
|
|
92
|
+
native: typeSafeAi.decisionModel('jev-latest'),
|
|
93
|
+
compact: openai.decisionModel('gpt-6-luna'),
|
|
97
94
|
},
|
|
98
95
|
fallbackProvider: typeSafeAi,
|
|
99
96
|
}),
|
|
100
97
|
openai,
|
|
101
98
|
});
|
|
102
99
|
|
|
103
|
-
const result = await
|
|
104
|
-
model: registry.
|
|
100
|
+
const result = await experimental_decide({
|
|
101
|
+
model: registry.decisionModel('triage:native'),
|
|
105
102
|
state: 'I was charged twice.',
|
|
106
103
|
questions: {
|
|
107
104
|
department: {
|
|
@@ -118,10 +115,10 @@ result.answers.department.choice; // 'billing' | 'support'
|
|
|
118
115
|
Registry IDs use `providerId:modelId`; the `separator` option changes the
|
|
119
116
|
separator. Only the first separator is used, so model IDs can contain it.
|
|
120
117
|
Custom aliases take precedence over a fallback provider. A fallback only resolves
|
|
121
|
-
unknown model IDs; it does not retry failed
|
|
118
|
+
unknown model IDs; it does not retry failed decisions or substitute a model
|
|
122
119
|
when a question type is unsupported. Registered providers keep their own
|
|
123
120
|
credentials and settings. Registry language/image middleware does not wrap
|
|
124
|
-
|
|
121
|
+
decision models.
|
|
125
122
|
|
|
126
123
|
### Default-provider strings
|
|
127
124
|
|
|
@@ -129,9 +126,9 @@ String IDs use Vercel AI Gateway by default. Configure Gateway authentication
|
|
|
129
126
|
with `AI_GATEWAY_API_KEY` or Vercel OIDC, then pass a Gateway model ID:
|
|
130
127
|
|
|
131
128
|
```ts
|
|
132
|
-
import {
|
|
129
|
+
import { experimental_decide } from 'ai';
|
|
133
130
|
|
|
134
|
-
const result = await
|
|
131
|
+
const result = await experimental_decide({
|
|
135
132
|
model: 'typesafe-ai/jev',
|
|
136
133
|
state: 'I was charged twice. Please refund the extra charge.',
|
|
137
134
|
questions: {
|
|
@@ -149,10 +146,10 @@ provider once at application startup:
|
|
|
149
146
|
```ts
|
|
150
147
|
// Using the registry above, expose an alias through a custom provider:
|
|
151
148
|
globalThis.AI_SDK_DEFAULT_PROVIDER = customProvider({
|
|
152
|
-
|
|
149
|
+
decisionModels: { native: registry.decisionModel('triage:native') },
|
|
153
150
|
});
|
|
154
151
|
|
|
155
|
-
const result = await
|
|
152
|
+
const result = await experimental_decide({
|
|
156
153
|
model: 'native',
|
|
157
154
|
state: 'I was charged twice.',
|
|
158
155
|
questions: {
|
|
@@ -165,20 +162,20 @@ const result = await experimental_evaluate({
|
|
|
165
162
|
```
|
|
166
163
|
|
|
167
164
|
A direct provider such as `typeSafeAi` can also be the default; then use its
|
|
168
|
-
unprefixed model ID, such as `'jev-latest'`. String values in `
|
|
165
|
+
unprefixed model ID, such as `'jev-latest'`. String values in `decisionModels`
|
|
169
166
|
also resolve through this global default. Prefer model instances in aliases to
|
|
170
167
|
avoid resolution cycles. Global configuration affects other AI SDK functions
|
|
171
168
|
too; avoid changing it per request in a shared process.
|
|
172
169
|
|
|
173
|
-
An explicitly configured default provider must expose
|
|
170
|
+
An explicitly configured default provider must expose a `decisionModel`
|
|
174
171
|
method; Gateway is used only when no default provider is configured. Missing
|
|
175
|
-
registry providers throw `NoSuchProviderError`; missing models or
|
|
172
|
+
registry providers throw `NoSuchProviderError`; missing models or decision
|
|
176
173
|
capabilities throw
|
|
177
|
-
`NoSuchModelError` with `modelType: '
|
|
174
|
+
`NoSuchModelError` with `modelType: 'decisionModel'`. Unsupported model versions
|
|
178
175
|
throw `UnsupportedModelVersionError`, including models returned by registries.
|
|
179
176
|
The stable `ProviderV4` and `ProviderRegistryProvider` interfaces are unchanged;
|
|
180
|
-
keep the inferred registry type, or use `
|
|
181
|
-
to retain its experimental `
|
|
177
|
+
keep the inferred registry type, or use `Experimental_DecisionProviderRegistry`,
|
|
178
|
+
to retain its experimental `decisionModel` method.
|
|
182
179
|
|
|
183
180
|
## Question types
|
|
184
181
|
|
|
@@ -214,7 +211,7 @@ are preserved, never silently normalized.
|
|
|
214
211
|
Choice and Score distributions are optional. Boolean probability is required:
|
|
215
212
|
`0.98` means a strong yes and `0.02` means a strong no. It is not confidence in
|
|
216
213
|
either outcome. The SDK does not promise calibration across providers. Structured
|
|
217
|
-
language-model adapters prompt the model to estimate P(true); native
|
|
214
|
+
language-model adapters prompt the model to estimate P(true); native decision providers return
|
|
218
215
|
their API probabilities. Provider-specific confidence statistics belong
|
|
219
216
|
in `providerMetadata`. TypeSafe exposes its separate Choice/Score confidence
|
|
220
217
|
statistic at `result.providerMetadata?.typesafe?.confidence`, keyed by question
|
|
@@ -245,34 +242,34 @@ if (result.answers.requestsRefund.probability >= 0.8) {
|
|
|
245
242
|
|
|
246
243
|
The model's `supportedQuestionTypes` are checked before calling the provider.
|
|
247
244
|
Any unsupported question fails the entire call with
|
|
248
|
-
`
|
|
245
|
+
`Experimental_DecisionUnsupportedQuestionTypeError`. Successful calls return
|
|
249
246
|
an answer for every question; there is no partial success, and Core does not
|
|
250
247
|
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`.
|
|
254
251
|
Transient provider failures use the normal retry policy (`maxRetries: 2` by
|
|
255
|
-
default). Use `abortSignal` to cancel
|
|
252
|
+
default). Use `abortSignal` to cancel the decisions request, `headers` for request headers,
|
|
256
253
|
and `providerOptions` for provider-specific settings.
|
|
257
254
|
|
|
258
255
|
The result includes `usage`, `warnings`, `providerMetadata`, and `response`.
|
|
259
256
|
Unknown token counts stay `undefined`; `totalTokens` is available only when both
|
|
260
257
|
input and output counts are known.
|
|
261
258
|
|
|
262
|
-
For tests, use `
|
|
259
|
+
For tests, use `Experimental_DecisionMockModelV4` from `ai/test`.
|
|
263
260
|
|
|
264
261
|
## Scope and examples
|
|
265
262
|
|
|
266
|
-
|
|
263
|
+
`experimental_decide` currently returns one complete result for one shared state. It does
|
|
267
264
|
not stream answers, perform multilabel classification, or batch unrelated
|
|
268
265
|
states. Run separate calls for separate states. Provider support and judgment
|
|
269
266
|
quality depend on the chosen model. Core does not choose another model, but a
|
|
270
267
|
provider can implement routing through its provider options. For example, AI
|
|
271
|
-
Gateway supports conditional
|
|
268
|
+
Gateway supports conditional decision fallbacks under
|
|
272
269
|
`providerOptions.gateway.models`.
|
|
273
270
|
|
|
274
271
|
Runnable examples are in
|
|
275
|
-
[`examples/ai-functions/src/
|
|
272
|
+
[`examples/ai-functions/src/decide`](https://github.com/vercel/ai/tree/main/examples/ai-functions/src/decide),
|
|
276
273
|
including basic examples for TypeSafe, OpenAI, Anthropic, and Google, model
|
|
277
274
|
registries, custom aliases, default-provider strings, and probability-based routing.
|
|
278
275
|
|
|
@@ -281,7 +278,7 @@ registries, custom aliases, default-provider strings, and probability-based rout
|
|
|
281
278
|
Explore use cases, implementation guides, and a deployable template for using
|
|
282
279
|
Jev from TypeSafe AI with the AI SDK:
|
|
283
280
|
|
|
284
|
-
- [Jev use cases](https://vercel.com/i/jev-use-cases): Explore ideas for applying
|
|
285
|
-
- [Classify, route, and score with Jev and AI SDK](https://vercel.com/kb/guide/typesafe-jev-and-ai-sdk): Learn how to ask typed questions, route answers using probabilities, and test routing logic with a mock
|
|
281
|
+
- [Jev use cases](https://vercel.com/i/jev-use-cases): Explore ideas for applying decisions in your application.
|
|
282
|
+
- [Classify, route, and score with Jev and AI SDK](https://vercel.com/kb/guide/typesafe-jev-and-ai-sdk): Learn how to ask typed questions, route answers using probabilities, and test routing logic with a mock decision model.
|
|
286
283
|
- [Jev and AI SDK form router guide](https://vercel.com/kb/guide/jev-ai-sdk-form-router): Explore form routing with Jev and the AI SDK.
|
|
287
|
-
- [Jev and AI SDK form router template](https://vercel.com/templates/next.js/jev-and-ai-sdk): Deploy a Next.js application that routes form submissions with Jev and uses a language model fallback for uncertain or failed
|
|
284
|
+
- [Jev and AI SDK form router template](https://vercel.com/templates/next.js/jev-and-ai-sdk): Deploy a Next.js application that routes form submissions with Jev and uses a language model fallback for uncertain or failed decisions.
|
|
@@ -308,7 +308,7 @@ __PROVIDER_IMPORT__;
|
|
|
308
308
|
const model = wrapImageModel({
|
|
309
309
|
model: __IMAGE_MODEL__,
|
|
310
310
|
middleware: {
|
|
311
|
-
specificationVersion: '
|
|
311
|
+
specificationVersion: 'v4',
|
|
312
312
|
transformParams: async ({ params }) => ({
|
|
313
313
|
...params,
|
|
314
314
|
size: params.size ?? '1024x1024',
|
|
@@ -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 |
|
|
@@ -469,12 +469,12 @@ const result = await streamText({
|
|
|
469
469
|
|
|
470
470
|
This simplifies provider usage and makes it easier to switch between providers without changing your model references throughout your codebase.
|
|
471
471
|
|
|
472
|
-
## Experimental
|
|
473
|
-
|
|
474
|
-
Custom providers accept `
|
|
475
|
-
`
|
|
476
|
-
`
|
|
477
|
-
explicitly configured default provider with
|
|
478
|
-
middleware for language and image models does not apply to
|
|
479
|
-
See [
|
|
472
|
+
## Experimental decision models
|
|
473
|
+
|
|
474
|
+
Custom providers accept `decisionModels` aliases, and registries expose
|
|
475
|
+
`decisionModel('provider:model')`. These methods return model instances for
|
|
476
|
+
`experimental_decide`. Direct string IDs use Gateway by default, or an
|
|
477
|
+
explicitly configured default provider with a `decisionModel` method. Registry
|
|
478
|
+
middleware for language and image models does not apply to decision.
|
|
479
|
+
See [Decisions](/docs/ai-sdk-core/decisions#model-aliases-and-registries)
|
|
480
480
|
for aliases, default-provider configuration, and capability differences.
|