ai 7.0.96 → 7.0.98

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 (33) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/index.d.ts +558 -472
  3. package/dist/index.js +1371 -1183
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +13 -5
  6. package/dist/internal/index.js +16 -14
  7. package/dist/internal/index.js.map +1 -1
  8. package/docs/03-ai-sdk-core/42-batch.mdx +48 -9
  9. package/docs/03-ai-sdk-core/60-telemetry.mdx +28 -5
  10. package/docs/04-ai-sdk-ui/03-chatbot-tool-usage.mdx +16 -1
  11. package/docs/07-reference/01-ai-sdk-core/05-embed.mdx +31 -5
  12. package/docs/07-reference/01-ai-sdk-core/06-embed-many.mdx +31 -5
  13. package/docs/07-reference/01-ai-sdk-core/06-rerank.mdx +19 -5
  14. package/docs/07-reference/01-ai-sdk-core/20-start-batch.mdx +1 -2
  15. package/docs/07-reference/01-ai-sdk-core/31-ui-message.mdx +28 -0
  16. package/package.json +12 -12
  17. package/src/batch/batch-types.ts +64 -5
  18. package/src/batch/batch.ts +100 -4
  19. package/src/batch/index.ts +3 -0
  20. package/src/embed/embed-events.ts +9 -3
  21. package/src/embed/embed-many.ts +20 -9
  22. package/src/embed/embed.ts +19 -9
  23. package/src/embed/restricted-telemetry-dispatcher.ts +44 -0
  24. package/src/generate-image/generate-image.ts +2 -2
  25. package/src/generate-text/restricted-telemetry-dispatcher.ts +1 -22
  26. package/src/generate-video/generate-video.ts +4 -2
  27. package/src/rerank/rerank-events.ts +9 -3
  28. package/src/rerank/rerank.ts +53 -14
  29. package/src/rerank/restricted-telemetry-dispatcher.ts +44 -0
  30. package/src/telemetry/filter-included-context.ts +24 -0
  31. package/src/ui/index.ts +2 -0
  32. package/src/ui/ui-messages.ts +24 -2
  33. package/src/ui/validate-ui-messages.ts +13 -4
@@ -15,8 +15,8 @@ application does not need to keep the request open while the model generates
15
15
  the results. This is useful for workloads such as classification,
16
16
  summarization, and content generation that do not need an immediate response.
17
17
 
18
- The batch API is designed to support multiple request types. Currently, only
19
- `type: 'text'` is supported.
18
+ The batch API supports text generation with `type: 'text'` and image generation
19
+ with `type: 'image'`.
20
20
 
21
21
  The AI SDK provides five functions for the batch lifecycle:
22
22
 
@@ -56,13 +56,13 @@ Batch processing requires a provider that implements the batch interface.
56
56
  Support is provider- and model-specific. The first-party providers with
57
57
  support are:
58
58
 
59
- | Provider | Provider value | Model example | Provider API |
60
- | ---------------------------------------------------- | -------------- | ------------------------------ | --------------------------------------------------------------------------------------------- |
61
- | [Anthropic](/providers/ai-sdk-providers/anthropic) | `anthropic` | `'claude-haiku-4-5'` | [Message Batches API](https://platform.claude.com/docs/en/build-with-claude/batch-processing) |
62
- | [Google](/providers/ai-sdk-providers/google) | `google` | `'gemini-3.6-flash'` | [Gemini Batch API](https://ai.google.dev/gemini-api/docs/batch-api) |
63
- | [OpenAI](/providers/ai-sdk-providers/openai) | `openai` | `'gpt-4.1-nano'` | [Batch API](https://developers.openai.com/api/docs/guides/batch) |
64
- | [xAI](/providers/ai-sdk-providers/xai) | `xai` | `'grok-4.3'` | [Batch API](https://docs.x.ai/developers/advanced-api-usage/batch-api) |
65
- | [AI Gateway](/providers/ai-sdk-providers/ai-gateway) | global default | `'anthropic/claude-haiku-4.5'` | [Batch processing](https://vercel.com/docs/ai-gateway/models-and-providers/batch-processing) |
59
+ | Provider | Provider value | Request types | Provider API |
60
+ | ---------------------------------------------------- | -------------- | ------------- | --------------------------------------------------------------------------------------------- |
61
+ | [Anthropic](/providers/ai-sdk-providers/anthropic) | `anthropic` | text | [Message Batches API](https://platform.claude.com/docs/en/build-with-claude/batch-processing) |
62
+ | [Google](/providers/ai-sdk-providers/google) | `google` | text, image | [Gemini Batch API](https://ai.google.dev/gemini-api/docs/batch-api) |
63
+ | [OpenAI](/providers/ai-sdk-providers/openai) | `openai` | text | [Batch API](https://developers.openai.com/api/docs/guides/batch) |
64
+ | [xAI](/providers/ai-sdk-providers/xai) | `xai` | text, image | [Batch API](https://docs.x.ai/developers/advanced-api-usage/batch-api) |
65
+ | [AI Gateway](/providers/ai-sdk-providers/ai-gateway) | global default | text | [Batch processing](https://vercel.com/docs/ai-gateway/models-and-providers/batch-processing) |
66
66
 
67
67
  See the provider documentation for the supported models, limits, and native
68
68
  batch behavior. For example, OpenAI batch support is available through the
@@ -125,6 +125,45 @@ at a later time. When retrieving a batch, pass the same provider. The AI SDK
125
125
  uses the reference to ensure that a batch is not read through an incompatible
126
126
  provider.
127
127
 
128
+ ### Image requests
129
+
130
+ Image requests use the same prompt and generation settings as `generateImage`:
131
+ `prompt`, `n`, `size`, `aspectRatio`, `seed`, and `providerOptions`. A prompt
132
+ can also contain input images and a mask for providers that support image
133
+ editing. Provider batch endpoints may support only a subset of these options;
134
+ unsupported options produce warnings or errors.
135
+
136
+ ```ts
137
+ import { google } from '@ai-sdk/google';
138
+ import { experimental_startBatch as startBatch } from 'ai';
139
+
140
+ const batch = await startBatch({
141
+ provider: google,
142
+ requests: [
143
+ {
144
+ id: 'red-panda',
145
+ type: 'image',
146
+ model: 'gemini-2.5-flash-image',
147
+ prompt: 'A red panda reading beside a cabin window',
148
+ aspectRatio: '16:9',
149
+ },
150
+ ],
151
+ });
152
+ ```
153
+
154
+ Successful image items have an `images` array of `GeneratedFile` values, plus
155
+ image warnings, response metadata, usage, and provider metadata when the
156
+ provider supplies them. Successful text items have `text` and `content`
157
+ properties. Use the `type` property to narrow mixed results:
158
+
159
+ ```ts
160
+ for await (const item of getBatchResults({ provider: google, batch })) {
161
+ if (item.type === 'image' && item.status === 'succeeded') {
162
+ console.log(item.images);
163
+ }
164
+ }
165
+ ```
166
+
128
167
  ## Batch tools
129
168
 
130
169
  Batch text requests support both client-defined tools and provider-defined
@@ -126,7 +126,7 @@ const result = await generateText({
126
126
  });
127
127
  ```
128
128
 
129
- In this example, telemetry integrations receive `runtimeContext` as `{ requestId: 'req_abc' }`. Properties set to `false` or omitted are excluded. If `telemetry.includeRuntimeContext` is omitted, no runtime context properties are included. `telemetry.includeRuntimeContext` is supported by `generateText`, `streamText`, and `ToolLoopAgent`.
129
+ In this example, telemetry integrations receive `runtimeContext` as `{ requestId: 'req_abc' }`. Properties set to `false` or omitted are excluded. If `telemetry.includeRuntimeContext` is omitted, no runtime context properties are included. `telemetry.includeRuntimeContext` is supported by `generateText`, `streamText`, `ToolLoopAgent`, `embed`, `embedMany`, and `rerank`.
130
130
 
131
131
  <Note>
132
132
  `telemetry.includeRuntimeContext` only filters telemetry integrations,
@@ -582,14 +582,37 @@ The callback runs when each span is created and receives:
582
582
  - `spanType`: the type of span being created (`operation`, `step`, `languageModel`, `tool`, `embedding`, or `reranking`).
583
583
  - `operationId`: the AI SDK operation ID for the current call, such as `ai.generateText` or `ai.streamText`.
584
584
  - `callId`: the unique ID for the current AI SDK call.
585
- - `runtimeContext`: the telemetry-filtered runtime context for text generation spans, including updates from `prepareStep`.
585
+ - `runtimeContext`: the telemetry-filtered runtime context for text generation, embedding, and reranking spans. Text generation spans also reflect updates from `prepareStep`.
586
586
 
587
587
  Custom attributes are merged with AI SDK attributes on the span. AI SDK-owned
588
588
  attributes take precedence when a custom attribute uses the same key.
589
589
 
590
- `sensitiveRuntimeContext` is applied before telemetry integrations receive
591
- `runtimeContext`, so custom span enrichment does not receive top-level runtime
592
- context properties marked as sensitive.
590
+ `telemetry.includeRuntimeContext` is applied before telemetry integrations receive
591
+ `runtimeContext`, so custom span enrichment only receives top-level runtime context
592
+ properties explicitly set to `true`. If the option is omitted, no runtime context
593
+ properties are included.
594
+
595
+ Embedding and reranking operations can share the same runtime context with text
596
+ generation to attribute their spans to the same application request:
597
+
598
+ ```ts
599
+ await embed({
600
+ model: 'openai/text-embedding-3-small',
601
+ value: 'sunny day at the beach',
602
+ runtimeContext: {
603
+ requestId: 'req_abc',
604
+ userId: 'user_123',
605
+ },
606
+ telemetry: {
607
+ includeRuntimeContext: { requestId: true },
608
+ },
609
+ });
610
+ ```
611
+
612
+ A globally registered `OpenTelemetry({ enrichSpan })` integration receives
613
+ `{ requestId: 'req_abc' }` for the operation span and its embedding model span.
614
+ The same applies to every chunk in `embedMany` and to the operation and model
615
+ spans in `rerank`. The `onStart` and `onEnd` callbacks receive the full context.
593
616
 
594
617
  ### Supplemental AI SDK attributes on OpenTelemetry spans
595
618
 
@@ -329,7 +329,7 @@ export default function Chat() {
329
329
 
330
330
  ### Error handling
331
331
 
332
- Sometimes an error may occur during client-side tool execution. Use the `addToolOutput` method with a `state` of `output-error` and `errorText` value instead of `output` record the error.
332
+ Sometimes an error may occur during client-side tool execution. Use the `addToolOutput` method with a `state` of `output-error` and `errorText` value instead of `output` to record the error.
333
333
 
334
334
  ```tsx filename='app/page.tsx' highlight="19,36-41"
335
335
  'use client';
@@ -380,6 +380,21 @@ export default function Chat() {
380
380
  }
381
381
  ```
382
382
 
383
+ When rendering messages, use `isToolOutputErrorUIPart` to identify failed
384
+ static and dynamic tool parts without checking the tool state directly:
385
+
386
+ ```tsx
387
+ import { isToolOutputErrorUIPart, type UIMessage } from 'ai';
388
+
389
+ function ToolError({ part }: { part: UIMessage['parts'][number] }) {
390
+ if (!isToolOutputErrorUIPart(part)) {
391
+ return null;
392
+ }
393
+
394
+ return <div role="alert">{part.errorText}</div>;
395
+ }
396
+ ```
397
+
383
398
  ## Tool Execution Approval
384
399
 
385
400
  Tool execution approval lets you require user confirmation before a server-side tool runs. Unlike [client-side tools](#example) that execute in the browser, tools with approval still execute on the server—but only after the user approves.
@@ -67,9 +67,16 @@ const { embedding } = await embed({
67
67
  description:
68
68
  'Provider-specific options that are passed through to the provider.',
69
69
  },
70
+ {
71
+ name: 'runtimeContext',
72
+ type: 'RUNTIME_CONTEXT',
73
+ isOptional: true,
74
+ description:
75
+ 'User-defined runtime context passed to lifecycle callbacks. Defaults to an empty object. Telemetry integrations only receive top-level properties explicitly included with telemetry.includeRuntimeContext.',
76
+ },
70
77
  {
71
78
  name: 'telemetry',
72
- type: 'TelemetryOptions',
79
+ type: 'TelemetryOptions<RUNTIME_CONTEXT>',
73
80
  isOptional: true,
74
81
  description: 'Telemetry configuration.',
75
82
  properties: [
@@ -104,6 +111,13 @@ const { embedding } = await embed({
104
111
  description:
105
112
  'Identifier for this function. Used to group telemetry data by function.',
106
113
  },
114
+ {
115
+ name: 'includeRuntimeContext',
116
+ type: '{ [KEY in keyof RUNTIME_CONTEXT]?: boolean }',
117
+ isOptional: true,
118
+ description:
119
+ 'Top-level runtime context properties to include in telemetry. Only properties set to true are included. All properties are excluded by default. User callbacks still receive the full context.',
120
+ },
107
121
  {
108
122
  name: 'integrations',
109
123
  isOptional: true,
@@ -117,14 +131,20 @@ const { embedding } = await embed({
117
131
  },
118
132
  {
119
133
  name: 'onStart',
120
- type: '(event: EmbedStartEvent) => PromiseLike<void> | void',
134
+ type: '(event: EmbedStartEvent<RUNTIME_CONTEXT>) => PromiseLike<void> | void',
121
135
  isOptional: true,
122
136
  description:
123
137
  'Callback that is called when the embed operation begins, before the embedding model is called. Errors thrown in this callback are silently caught and do not break the embedding flow.',
124
138
  properties: [
125
139
  {
126
- type: 'EmbedStartEvent',
140
+ type: 'EmbedStartEvent<RUNTIME_CONTEXT>',
127
141
  parameters: [
142
+ {
143
+ name: 'runtimeContext',
144
+ type: 'RUNTIME_CONTEXT',
145
+ description:
146
+ 'The full, unfiltered runtime context supplied to the operation.',
147
+ },
128
148
  {
129
149
  name: 'callId',
130
150
  type: 'string',
@@ -171,14 +191,20 @@ const { embedding } = await embed({
171
191
  },
172
192
  {
173
193
  name: 'onEnd',
174
- type: '(event: EmbedEndEvent) => PromiseLike<void> | void',
194
+ type: '(event: EmbedEndEvent<RUNTIME_CONTEXT>) => PromiseLike<void> | void',
175
195
  isOptional: true,
176
196
  description:
177
197
  'Callback that is called when the embed operation completes, after the embedding model returns. Errors thrown in this callback are silently caught and do not break the embedding flow.',
178
198
  properties: [
179
199
  {
180
- type: 'EmbedEndEvent',
200
+ type: 'EmbedEndEvent<RUNTIME_CONTEXT>',
181
201
  parameters: [
202
+ {
203
+ name: 'runtimeContext',
204
+ type: 'RUNTIME_CONTEXT',
205
+ description:
206
+ 'The full, unfiltered runtime context supplied to the operation.',
207
+ },
182
208
  {
183
209
  name: 'callId',
184
210
  type: 'string',
@@ -83,9 +83,16 @@ const { embeddings } = await embedMany({
83
83
  description:
84
84
  'Maximum number of concurrent requests to the provider. Default: Infinity.',
85
85
  },
86
+ {
87
+ name: 'runtimeContext',
88
+ type: 'RUNTIME_CONTEXT',
89
+ isOptional: true,
90
+ description:
91
+ 'User-defined runtime context passed to lifecycle callbacks. Defaults to an empty object. Telemetry integrations only receive top-level properties explicitly included with telemetry.includeRuntimeContext.',
92
+ },
86
93
  {
87
94
  name: 'telemetry',
88
- type: 'TelemetryOptions',
95
+ type: 'TelemetryOptions<RUNTIME_CONTEXT>',
89
96
  isOptional: true,
90
97
  description: 'Telemetry configuration.',
91
98
  properties: [
@@ -120,6 +127,13 @@ const { embeddings } = await embedMany({
120
127
  description:
121
128
  'Identifier for this function. Used to group telemetry data by function.',
122
129
  },
130
+ {
131
+ name: 'includeRuntimeContext',
132
+ type: '{ [KEY in keyof RUNTIME_CONTEXT]?: boolean }',
133
+ isOptional: true,
134
+ description:
135
+ 'Top-level runtime context properties to include in telemetry. Only properties set to true are included. All properties are excluded by default. User callbacks still receive the full context.',
136
+ },
123
137
  {
124
138
  name: 'integrations',
125
139
  isOptional: true,
@@ -133,14 +147,20 @@ const { embeddings } = await embedMany({
133
147
  },
134
148
  {
135
149
  name: 'onStart',
136
- type: '(event: EmbedStartEvent) => PromiseLike<void> | void',
150
+ type: '(event: EmbedStartEvent<RUNTIME_CONTEXT>) => PromiseLike<void> | void',
137
151
  isOptional: true,
138
152
  description:
139
153
  'Callback that is called when the embedMany operation begins, before the embedding model is called. Errors thrown in this callback are silently caught and do not break the embedding flow.',
140
154
  properties: [
141
155
  {
142
- type: 'EmbedStartEvent',
156
+ type: 'EmbedStartEvent<RUNTIME_CONTEXT>',
143
157
  parameters: [
158
+ {
159
+ name: 'runtimeContext',
160
+ type: 'RUNTIME_CONTEXT',
161
+ description:
162
+ 'The full, unfiltered runtime context supplied to the operation.',
163
+ },
144
164
  {
145
165
  name: 'callId',
146
166
  type: 'string',
@@ -188,14 +208,20 @@ const { embeddings } = await embedMany({
188
208
  },
189
209
  {
190
210
  name: 'onEnd',
191
- type: '(event: EmbedEndEvent) => PromiseLike<void> | void',
211
+ type: '(event: EmbedEndEvent<RUNTIME_CONTEXT>) => PromiseLike<void> | void',
192
212
  isOptional: true,
193
213
  description:
194
214
  'Callback that is called when the embedMany operation completes, after all embedding model calls return. Errors thrown in this callback are silently caught and do not break the embedding flow.',
195
215
  properties: [
196
216
  {
197
- type: 'EmbedEndEvent',
217
+ type: 'EmbedEndEvent<RUNTIME_CONTEXT>',
198
218
  parameters: [
219
+ {
220
+ name: 'runtimeContext',
221
+ type: 'RUNTIME_CONTEXT',
222
+ description:
223
+ 'The full, unfiltered runtime context supplied to the operation.',
224
+ },
199
225
  {
200
226
  name: 'callId',
201
227
  type: 'string',
@@ -81,9 +81,16 @@ const { ranking } = await rerank({
81
81
  isOptional: true,
82
82
  description: 'Provider-specific options for the reranking request.',
83
83
  },
84
+ {
85
+ name: 'runtimeContext',
86
+ type: 'RUNTIME_CONTEXT',
87
+ isOptional: true,
88
+ description:
89
+ 'User-defined runtime context passed to lifecycle callbacks. Defaults to an empty object. Telemetry integrations only receive top-level properties explicitly included with telemetry.includeRuntimeContext.',
90
+ },
84
91
  {
85
92
  name: 'telemetry',
86
- type: 'TelemetryOptions',
93
+ type: 'TelemetryOptions<RUNTIME_CONTEXT>',
87
94
  isOptional: true,
88
95
  description: 'Telemetry configuration.',
89
96
  properties: [
@@ -118,6 +125,13 @@ const { ranking } = await rerank({
118
125
  description:
119
126
  'Identifier for this function. Used to group telemetry data by function.',
120
127
  },
128
+ {
129
+ name: 'includeRuntimeContext',
130
+ type: '{ [KEY in keyof RUNTIME_CONTEXT]?: boolean }',
131
+ isOptional: true,
132
+ description:
133
+ 'Top-level runtime context properties to include in telemetry. Only properties set to true are included. All properties are excluded by default. User callbacks still receive the full context.',
134
+ },
121
135
  {
122
136
  name: 'integrations',
123
137
  isOptional: true,
@@ -131,17 +145,17 @@ const { ranking } = await rerank({
131
145
  },
132
146
  {
133
147
  name: 'onStart',
134
- type: '(event: RerankStartEvent) => void | Promise<void>',
148
+ type: '(event: RerankStartEvent<RUNTIME_CONTEXT>) => void | Promise<void>',
135
149
  isOptional: true,
136
150
  description:
137
- 'Called when the rerank operation begins, before the reranking model is called.',
151
+ 'Called when the rerank operation begins, before the reranking model is called. The event includes the full, unfiltered runtimeContext.',
138
152
  },
139
153
  {
140
154
  name: 'onEnd',
141
- type: '(event: RerankEndEvent) => void | Promise<void>',
155
+ type: '(event: RerankEndEvent<RUNTIME_CONTEXT>) => void | Promise<void>',
142
156
  isOptional: true,
143
157
  description:
144
- 'Called when the rerank operation completes, after the reranking model returns.',
158
+ 'Called when the rerank operation completes, after the reranking model returns. The event includes the full, unfiltered runtimeContext.',
145
159
  },
146
160
  ]}
147
161
  />
@@ -9,8 +9,7 @@ description: API Reference for experimental_startBatch.
9
9
  Batch support is experimental and the API may change in patch releases.
10
10
  </Note>
11
11
 
12
- Starts an asynchronous batch. Currently, only `type: 'text'` requests are
13
- supported. For a complete guide to the batch lifecycle, see
12
+ Starts an asynchronous batch of text or image generation requests. For a complete guide to the batch lifecycle, see
14
13
  [Batch](/docs/ai-sdk-core/batch).
15
14
 
16
15
  ```ts
@@ -203,6 +203,34 @@ type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
203
203
  the tool part transitions from `approval-requested` to `approval-responded` and
204
204
  in later approval-bearing output states.
205
205
 
206
+ ### `ToolOutputErrorUIPart`
207
+
208
+ A static or dynamic tool part whose execution failed. Use the
209
+ `isToolOutputErrorUIPart` type guard when rendering messages so your code does
210
+ not need to check the tool state discriminator directly.
211
+
212
+ ```tsx
213
+ import { isToolOutputErrorUIPart, type UIMessage } from 'ai';
214
+
215
+ function ToolError({ part }: { part: UIMessage['parts'][number] }) {
216
+ if (!isToolOutputErrorUIPart(part)) {
217
+ return null;
218
+ }
219
+
220
+ return <div role="alert">{part.errorText}</div>;
221
+ }
222
+ ```
223
+
224
+ The generic `ToolOutputErrorUIPart<TOOLS>` type preserves the input types of
225
+ static tools and also includes dynamic tool errors:
226
+
227
+ ```typescript
228
+ type ToolOutputErrorUIPart<TOOLS extends UITools = UITools> = Extract<
229
+ ToolUIPart<TOOLS> | DynamicToolUIPart,
230
+ { state: 'output-error' }
231
+ >;
232
+ ```
233
+
206
234
  ### `CustomContentUIPart`
207
235
 
208
236
  A provider-specific custom content part of a message.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "7.0.96",
3
+ "version": "7.0.98",
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,20 +42,20 @@
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "@ai-sdk/gateway": "4.0.77",
46
- "@ai-sdk/provider": "4.0.12",
47
- "@ai-sdk/provider-utils": "5.0.38"
45
+ "@ai-sdk/gateway": "4.0.79",
46
+ "@ai-sdk/provider": "4.0.14",
47
+ "@ai-sdk/provider-utils": "5.0.40"
48
48
  },
49
49
  "devDependencies": {
50
- "@ai-sdk/amazon-bedrock": "5.0.80",
51
- "@ai-sdk/deepseek": "3.0.41",
52
- "@ai-sdk/google": "4.0.66",
53
- "@ai-sdk/groq": "4.0.39",
54
- "@ai-sdk/huggingface": "2.0.46",
55
- "@ai-sdk/moonshotai": "3.0.47",
56
- "@ai-sdk/openai": "4.0.64",
50
+ "@ai-sdk/amazon-bedrock": "5.0.82",
51
+ "@ai-sdk/deepseek": "3.0.43",
52
+ "@ai-sdk/google": "4.0.68",
53
+ "@ai-sdk/groq": "4.0.41",
54
+ "@ai-sdk/huggingface": "2.0.48",
55
+ "@ai-sdk/moonshotai": "3.0.49",
56
+ "@ai-sdk/openai": "4.0.66",
57
57
  "@ai-sdk/test-server": "2.0.1",
58
- "@ai-sdk/xai": "4.0.56",
58
+ "@ai-sdk/xai": "4.0.58",
59
59
  "@edge-runtime/vm": "^5.0.0",
60
60
  "@smithy/eventstream-codec": "^4.3.3",
61
61
  "@smithy/util-utf8": "^4.3.3",
@@ -4,6 +4,7 @@ import type {
4
4
  Experimental_BatchV4ModelIds as BatchV4ModelIds,
5
5
  Experimental_BatchV4StartResult as BatchV4StartResult,
6
6
  Experimental_BatchV4Status as BatchV4Status,
7
+ ImageModelV4ProviderMetadata,
7
8
  ProviderV4,
8
9
  } from '@ai-sdk/provider';
9
10
  import type {
@@ -17,7 +18,11 @@ import type { LanguageModelCallOptions } from '../prompt/language-model-call-opt
17
18
  import type { Prompt } from '../prompt/prompt';
18
19
  import type { FinishReason, ToolChoice } from '../types/language-model';
19
20
  import type { ProviderMetadata } from '../types/provider-metadata';
20
- import type { LanguageModelUsage } from '../types/usage';
21
+ import type { ImageModelUsage, LanguageModelUsage } from '../types/usage';
22
+ import type { GenerateImagePrompt } from '../generate-image/generate-image';
23
+ import type { GeneratedFile } from '../generate-text/generated-file';
24
+ import type { ImageModelResponseMetadata } from '../types/image-model-response-metadata';
25
+ import type { Warning } from '../types/warning';
21
26
 
22
27
  /**
23
28
  * Provider or lower-level batch interface used for batch processing.
@@ -73,13 +78,30 @@ export type TextBatchRequest<
73
78
  providerOptions?: ProviderOptions;
74
79
  };
75
80
 
81
+ /**
82
+ * One image generation request within a batch.
83
+ */
84
+ export type ImageBatchRequest<ModelId extends string = string> = {
85
+ id: string;
86
+ type: 'image';
87
+ model: ModelId;
88
+ prompt: GenerateImagePrompt;
89
+ n?: number;
90
+ size?: `${number}x${number}`;
91
+ aspectRatio?: `${number}:${number}`;
92
+ seed?: number;
93
+ providerOptions?: ProviderOptions;
94
+ };
95
+
76
96
  /**
77
97
  * One request within a batch, discriminated by modality.
78
98
  */
79
99
  export type BatchRequest<
80
100
  ModelIds extends BatchV4ModelIds = BatchV4ModelIds,
81
101
  TOOLS extends ToolSet = ToolSet,
82
- > = TextBatchRequest<ModelIds['text'], TOOLS>;
102
+ > =
103
+ | TextBatchRequest<ModelIds['text'] & string, TOOLS>
104
+ | ImageBatchRequest<ModelIds['image'] & string>;
83
105
 
84
106
  type BatchCallOptions = {
85
107
  abortSignal?: AbortSignal;
@@ -203,7 +225,9 @@ export type TextBatchGenerationResult<TOOLS extends ToolSet = ToolSet> = {
203
225
  /**
204
226
  * A complete terminal result for one request in a text batch.
205
227
  */
206
- export type TextBatchItemResult<TOOLS extends ToolSet = ToolSet> =
228
+ export type TextBatchItemResult<TOOLS extends ToolSet = ToolSet> = {
229
+ readonly type: 'text';
230
+ } & (
207
231
  | (TextBatchGenerationResult<TOOLS> & {
208
232
  readonly id: string;
209
233
  readonly status: 'succeeded';
@@ -219,10 +243,45 @@ export type TextBatchItemResult<TOOLS extends ToolSet = ToolSet> =
219
243
  readonly status: 'cancelled' | 'expired';
220
244
  readonly error?: BatchError;
221
245
  readonly providerMetadata?: ProviderMetadata;
222
- };
246
+ }
247
+ );
248
+
249
+ /**
250
+ * A normalized result for a successful image batch item.
251
+ */
252
+ export type ImageBatchGenerationResult = {
253
+ readonly images: Array<GeneratedFile>;
254
+ readonly warnings: Array<Warning>;
255
+ readonly response: ImageModelResponseMetadata;
256
+ readonly providerMetadata?: ImageModelV4ProviderMetadata;
257
+ readonly usage?: ImageModelUsage;
258
+ };
259
+
260
+ /**
261
+ * A complete terminal result for one request in an image batch.
262
+ */
263
+ export type ImageBatchItemResult = { readonly type: 'image' } & (
264
+ | (ImageBatchGenerationResult & {
265
+ readonly id: string;
266
+ readonly status: 'succeeded';
267
+ })
268
+ | {
269
+ readonly id: string;
270
+ readonly status: 'failed';
271
+ readonly error: BatchError;
272
+ readonly providerMetadata?: ProviderMetadata;
273
+ }
274
+ | {
275
+ readonly id: string;
276
+ readonly status: 'cancelled' | 'expired';
277
+ readonly error?: BatchError;
278
+ readonly providerMetadata?: ProviderMetadata;
279
+ }
280
+ );
223
281
 
224
282
  /**
225
283
  * A complete terminal result for one request in a batch.
226
284
  */
227
285
  export type BatchItemResult<TOOLS extends ToolSet = ToolSet> =
228
- TextBatchItemResult<TOOLS>;
286
+ | TextBatchItemResult<TOOLS>
287
+ | ImageBatchItemResult;