ai 7.0.93 → 7.0.95

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.
@@ -0,0 +1,133 @@
1
+ ---
2
+ title: experimental_getBatchStatus
3
+ description: API Reference for experimental_getBatchStatus.
4
+ ---
5
+
6
+ # `experimental_getBatchStatus()`
7
+
8
+ <Note type="warning">
9
+ Batch support is experimental and the API may change in patch releases.
10
+ </Note>
11
+
12
+ Retrieves the latest status of an asynchronous batch. For a complete guide to
13
+ the batch lifecycle, see [Batch](/docs/ai-sdk-core/batch).
14
+
15
+ ```ts
16
+ import { anthropic } from '@ai-sdk/anthropic';
17
+ import { experimental_getBatchStatus as getBatchStatus } from 'ai';
18
+
19
+ const status = await getBatchStatus({
20
+ provider: anthropic,
21
+ batch,
22
+ });
23
+
24
+ console.log(status.status, status.requestCounts);
25
+ ```
26
+
27
+ ## Import
28
+
29
+ <Snippet
30
+ text={`import { experimental_getBatchStatus } from "ai"`}
31
+ prompt={false}
32
+ />
33
+
34
+ ## API Signature
35
+
36
+ ### Parameters
37
+
38
+ <PropertiesTable
39
+ content={[
40
+ {
41
+ name: 'provider',
42
+ type: 'Experimental_BatchProvider',
43
+ isOptional: true,
44
+ description:
45
+ 'The provider used to access the batch. Defaults to the global provider, or the AI Gateway when no global provider is configured.',
46
+ },
47
+ {
48
+ name: 'batch',
49
+ type: 'Experimental_BatchReference',
50
+ description:
51
+ 'The serializable reference returned by experimental_startBatch.',
52
+ },
53
+ {
54
+ name: 'providerOptions',
55
+ type: 'ProviderOptions',
56
+ isOptional: true,
57
+ description: 'Additional provider-specific options for status retrieval.',
58
+ },
59
+ {
60
+ name: 'maxRetries',
61
+ type: 'number',
62
+ isOptional: true,
63
+ description:
64
+ 'Maximum number of retries for status retrieval. Set to 0 to disable retries. Default: 2.',
65
+ },
66
+ {
67
+ name: 'abortSignal',
68
+ type: 'AbortSignal',
69
+ isOptional: true,
70
+ description: 'An optional abort signal to cancel the request.',
71
+ },
72
+ {
73
+ name: 'timeout',
74
+ type: 'number | { totalMs?: number }',
75
+ isOptional: true,
76
+ description: 'Maximum time allowed for the status request.',
77
+ },
78
+ {
79
+ name: 'headers',
80
+ type: 'Record<string, string | undefined>',
81
+ isOptional: true,
82
+ description: 'Additional HTTP headers for the request.',
83
+ },
84
+ ]}
85
+ />
86
+
87
+ ### Returns
88
+
89
+ <PropertiesTable
90
+ content={[
91
+ {
92
+ name: 'status',
93
+ type: "'pending' | 'completed' | 'failed'",
94
+ description: 'The latest normalized batch status.',
95
+ },
96
+ {
97
+ name: 'rawStatus',
98
+ type: 'string',
99
+ isOptional: true,
100
+ description: 'The provider-specific batch status, when available.',
101
+ },
102
+ {
103
+ name: 'requestCounts',
104
+ type: '{ total: number; pending: number; completed: number; failed: number }',
105
+ isOptional: true,
106
+ description: 'Provider-reported request counts.',
107
+ },
108
+ {
109
+ name: 'error',
110
+ type: 'Experimental_BatchError',
111
+ isOptional: true,
112
+ description: 'Error details when the batch fails.',
113
+ },
114
+ {
115
+ name: 'createdAt',
116
+ type: 'string',
117
+ isOptional: true,
118
+ description: 'Creation timestamp, when provided by the provider.',
119
+ },
120
+ {
121
+ name: 'expiresAt',
122
+ type: 'string',
123
+ isOptional: true,
124
+ description: 'Expiration timestamp, when provided by the provider.',
125
+ },
126
+ {
127
+ name: 'providerMetadata',
128
+ type: 'ProviderMetadata',
129
+ isOptional: true,
130
+ description: 'Provider-specific metadata for the batch.',
131
+ },
132
+ ]}
133
+ />
@@ -0,0 +1,109 @@
1
+ ---
2
+ title: experimental_getBatchResults
3
+ description: API Reference for experimental_getBatchResults.
4
+ ---
5
+
6
+ # `experimental_getBatchResults()`
7
+
8
+ <Note type="warning">
9
+ Batch support is experimental and the API may change in patch releases.
10
+ </Note>
11
+
12
+ Returns an async iterable of terminal results for the requests in an
13
+ asynchronous batch. For a complete guide to the batch lifecycle, see
14
+ [Batch](/docs/ai-sdk-core/batch).
15
+
16
+ ```ts
17
+ import { anthropic } from '@ai-sdk/anthropic';
18
+ import { experimental_getBatchResults as getBatchResults } from 'ai';
19
+
20
+ for await (const item of getBatchResults({ provider: anthropic, batch })) {
21
+ if (item.status === 'succeeded') {
22
+ console.log(item.id, item.text);
23
+ } else {
24
+ console.error(item.id, item.error);
25
+ }
26
+ }
27
+ ```
28
+
29
+ ## Import
30
+
31
+ <Snippet
32
+ text={`import { experimental_getBatchResults } from "ai"`}
33
+ prompt={false}
34
+ />
35
+
36
+ ## API Signature
37
+
38
+ ### Parameters
39
+
40
+ <PropertiesTable
41
+ content={[
42
+ {
43
+ name: 'provider',
44
+ type: 'Experimental_BatchProvider',
45
+ isOptional: true,
46
+ description:
47
+ 'The provider used to access the batch. Defaults to the global provider, or the AI Gateway when no global provider is configured.',
48
+ },
49
+ {
50
+ name: 'batch',
51
+ type: 'Experimental_BatchReference',
52
+ description:
53
+ 'The serializable reference returned by experimental_startBatch.',
54
+ },
55
+ {
56
+ name: 'tools',
57
+ type: 'ToolSet',
58
+ isOptional: true,
59
+ description:
60
+ 'The client-defined tools provided on requests in the batch. Used to validate and normalize returned tool calls; execute functions are never invoked.',
61
+ },
62
+ {
63
+ name: 'providerOptions',
64
+ type: 'ProviderOptions',
65
+ isOptional: true,
66
+ description: 'Additional provider-specific options for result retrieval.',
67
+ },
68
+ {
69
+ name: 'maxRetries',
70
+ type: 'number',
71
+ isOptional: true,
72
+ description:
73
+ 'Maximum number of retries for result retrieval. Set to 0 to disable retries. Default: 2.',
74
+ },
75
+ {
76
+ name: 'abortSignal',
77
+ type: 'AbortSignal',
78
+ isOptional: true,
79
+ description: 'An optional abort signal to cancel result retrieval.',
80
+ },
81
+ {
82
+ name: 'timeout',
83
+ type: 'number | { totalMs?: number }',
84
+ isOptional: true,
85
+ description: 'Maximum time allowed for result retrieval.',
86
+ },
87
+ {
88
+ name: 'headers',
89
+ type: 'Record<string, string | undefined>',
90
+ isOptional: true,
91
+ description: 'Additional HTTP headers for the request.',
92
+ },
93
+ ]}
94
+ />
95
+
96
+ ### Returns
97
+
98
+ An `AsyncIterableStream<Experimental_BatchItemResult>` of succeeded,
99
+ failed, cancelled, or expired request results. You can consume the stream as
100
+ either an async iterable or a `ReadableStream`.
101
+
102
+ Successful items contain `id`, `status: 'succeeded'`, `text`, normalized
103
+ `content` (including text, reasoning, sources, files, tool calls, and tool
104
+ results),
105
+ `finishReason`, `usage`, and optional response and provider metadata. `text` is
106
+ the concatenation of text parts and can be an empty string when a result
107
+ contains no text parts.
108
+ Failed, cancelled, and expired items contain the request `id`, their terminal
109
+ status, and optional error details.
@@ -53,6 +53,21 @@ AI SDK Core contains the following main functions:
53
53
  'Generate videos based on a given prompt using a video model.',
54
54
  href: '/docs/reference/ai-sdk-core/generate-video',
55
55
  },
56
+ {
57
+ title: 'experimental_startBatch()',
58
+ description: 'Start an asynchronous text-generation batch.',
59
+ href: '/docs/reference/ai-sdk-core/start-batch',
60
+ },
61
+ {
62
+ title: 'experimental_getBatchStatus()',
63
+ description: 'Retrieve the status of an asynchronous batch.',
64
+ href: '/docs/reference/ai-sdk-core/get-batch-status',
65
+ },
66
+ {
67
+ title: 'experimental_getBatchResults()',
68
+ description: 'Retrieve terminal results from an asynchronous batch.',
69
+ href: '/docs/reference/ai-sdk-core/get-batch-results',
70
+ },
56
71
  {
57
72
  title: 'transcribe()',
58
73
  description: 'Generate a transcript from an audio file.',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "7.0.93",
3
+ "version": "7.0.95",
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.75",
46
- "@ai-sdk/provider": "4.0.10",
47
- "@ai-sdk/provider-utils": "5.0.36"
45
+ "@ai-sdk/gateway": "4.0.76",
46
+ "@ai-sdk/provider": "4.0.11",
47
+ "@ai-sdk/provider-utils": "5.0.37"
48
48
  },
49
49
  "devDependencies": {
50
- "@ai-sdk/amazon-bedrock": "5.0.75",
51
- "@ai-sdk/deepseek": "3.0.39",
52
- "@ai-sdk/google": "4.0.64",
53
- "@ai-sdk/groq": "4.0.37",
54
- "@ai-sdk/huggingface": "2.0.44",
55
- "@ai-sdk/moonshotai": "3.0.45",
56
- "@ai-sdk/openai": "4.0.59",
50
+ "@ai-sdk/amazon-bedrock": "5.0.79",
51
+ "@ai-sdk/deepseek": "3.0.40",
52
+ "@ai-sdk/google": "4.0.65",
53
+ "@ai-sdk/groq": "4.0.38",
54
+ "@ai-sdk/huggingface": "2.0.45",
55
+ "@ai-sdk/moonshotai": "3.0.46",
56
+ "@ai-sdk/openai": "4.0.63",
57
57
  "@ai-sdk/test-server": "2.0.1",
58
- "@ai-sdk/xai": "4.0.54",
58
+ "@ai-sdk/xai": "4.0.55",
59
59
  "@edge-runtime/vm": "^5.0.0",
60
60
  "@smithy/eventstream-codec": "^4.3.3",
61
61
  "@smithy/util-utf8": "^4.3.3",
@@ -1,8 +1,10 @@
1
1
  import type {
2
+ Experimental_BatchV4 as BatchV4,
2
3
  Experimental_BatchV4Error as BatchV4Error,
4
+ Experimental_BatchV4ModelIds as BatchV4ModelIds,
3
5
  Experimental_BatchV4StartResult as BatchV4StartResult,
4
6
  Experimental_BatchV4Status as BatchV4Status,
5
- Experimental_BatchLanguageModelV4 as BatchLanguageModelV4,
7
+ ProviderV4,
6
8
  } from '@ai-sdk/provider';
7
9
  import type {
8
10
  InferToolSetContext,
@@ -13,40 +15,31 @@ import type { ContentPart } from '../generate-text/content-part';
13
15
  import type { ToolOrder } from '../generate-text/tool-order';
14
16
  import type { LanguageModelCallOptions } from '../prompt/language-model-call-options';
15
17
  import type { Prompt } from '../prompt/prompt';
16
- import type {
17
- FinishReason,
18
- GlobalProviderModelId,
19
- ToolChoice,
20
- } from '../types/language-model';
18
+ import type { FinishReason, ToolChoice } from '../types/language-model';
21
19
  import type { ProviderMetadata } from '../types/provider-metadata';
22
20
  import type { LanguageModelUsage } from '../types/usage';
23
21
 
24
22
  /**
25
- * Language model input that can be used for durable batch processing.
26
- *
27
- * String model IDs are resolved through the global provider and checked for
28
- * batch support at runtime.
23
+ * Provider or lower-level batch interface used for batch processing.
29
24
  */
30
- export type BatchLanguageModel = GlobalProviderModelId | BatchLanguageModelV4;
25
+ export type BatchProvider = ProviderV4 | BatchV4;
26
+
27
+ type InferBatchModelIds<PROVIDER extends BatchProvider> =
28
+ PROVIDER extends BatchV4<infer MODEL_IDS>
29
+ ? MODEL_IDS
30
+ : PROVIDER extends { experimental_batch(): BatchV4<infer MODEL_IDS> }
31
+ ? MODEL_IDS
32
+ : BatchV4ModelIds;
31
33
 
32
34
  /**
33
- * The persisted reference for a text batch.
35
+ * The persisted reference for a batch.
34
36
  */
35
- export type TextBatchReference = {
36
- readonly version: 1;
37
- readonly type: 'text';
37
+ export type BatchReference = {
38
+ readonly version: 2;
38
39
  readonly id: string;
39
40
  readonly provider: string;
40
- readonly modelId: string;
41
41
  };
42
42
 
43
- /**
44
- * Persisted reference for any supported batch type.
45
- *
46
- * Additional modality-specific references can be added to this union.
47
- */
48
- export type BatchReference = TextBatchReference;
49
-
50
43
  /**
51
44
  * Serializable error information for a batch or batch item.
52
45
  */
@@ -58,55 +51,55 @@ export type BatchError = BatchV4Error;
58
51
  export type BatchStatus = BatchV4Status;
59
52
 
60
53
  /**
61
- * A text batch and its latest normalized lifecycle status.
54
+ * A batch and its latest normalized lifecycle status.
62
55
  */
63
- export type TextBatch = TextBatchReference & BatchStatus;
56
+ export type Batch = BatchReference & BatchStatus;
64
57
 
65
58
  /**
66
59
  * One text generation request within a batch.
67
60
  */
68
- export type TextBatchRequest = Prompt &
61
+ export type TextBatchRequest<
62
+ ModelId extends string = string,
63
+ TOOLS extends ToolSet = ToolSet,
64
+ > = Prompt &
69
65
  LanguageModelCallOptions & {
70
66
  id: string;
67
+ type: 'text';
68
+ model: ModelId;
69
+ tools?: TOOLS;
70
+ toolChoice?: ToolChoice<NoInfer<TOOLS>>;
71
+ toolOrder?: ToolOrder<TOOLS>;
72
+ toolsContext?: InferToolSetContext<TOOLS>;
71
73
  providerOptions?: ProviderOptions;
72
74
  };
73
75
 
74
- type BatchRequestOptions = {
76
+ /**
77
+ * One request within a batch, discriminated by modality.
78
+ */
79
+ export type BatchRequest<
80
+ ModelIds extends BatchV4ModelIds = BatchV4ModelIds,
81
+ TOOLS extends ToolSet = ToolSet,
82
+ > = TextBatchRequest<ModelIds['text'], TOOLS>;
83
+
84
+ type BatchCallOptions = {
75
85
  abortSignal?: AbortSignal;
76
86
  headers?: Record<string, string | undefined>;
77
87
  timeout?: number | { totalMs?: number };
78
88
  };
79
89
 
80
90
  /**
81
- * Options for starting a text batch.
91
+ * Options for starting a batch.
82
92
  */
83
- export type StartTextBatchOptions<TOOLS extends ToolSet = ToolSet> = {
84
- model: BatchLanguageModel;
85
- requests: ReadonlyArray<TextBatchRequest>;
86
-
87
- /**
88
- * Tools that the model can call for every request in the batch.
89
- *
90
- * Tool definitions are sent to the provider, but their `execute` functions
91
- * are never invoked by batch processing.
92
- */
93
- tools?: TOOLS;
94
-
95
- /**
96
- * The tool choice strategy. Default: 'auto'.
97
- */
98
- toolChoice?: ToolChoice<NoInfer<TOOLS>>;
99
-
93
+ export type StartBatchOptions<
94
+ TOOLS extends ToolSet = ToolSet,
95
+ PROVIDER extends BatchProvider = BatchProvider,
96
+ > = {
100
97
  /**
101
- * Controls the order in which tools are sent to the provider. Tools not
102
- * listed are appended alphabetically.
98
+ * Provider used to process the batch. Defaults to the global provider, or
99
+ * the Vercel AI Gateway when no global provider is configured.
103
100
  */
104
- toolOrder?: ToolOrder<TOOLS>;
105
-
106
- /**
107
- * Context used when resolving dynamic tool descriptions.
108
- */
109
- toolsContext?: InferToolSetContext<TOOLS>;
101
+ provider?: PROVIDER;
102
+ requests: ReadonlyArray<BatchRequest<InferBatchModelIds<PROVIDER>, TOOLS>>;
110
103
 
111
104
  providerOptions?: ProviderOptions;
112
105
 
@@ -116,33 +109,42 @@ export type StartTextBatchOptions<TOOLS extends ToolSet = ToolSet> = {
116
109
  * unsupported warning.
117
110
  */
118
111
  webhookUrl?: string;
119
- } & BatchRequestOptions;
112
+ } & BatchCallOptions;
120
113
 
121
114
  /**
122
- * The acknowledged text batch and warnings produced while starting it.
115
+ * The acknowledged batch and warnings produced while starting it.
123
116
  */
124
- export type StartTextBatchResult = TextBatch & {
117
+ export type StartBatchResult = Batch & {
125
118
  readonly warnings: BatchV4StartResult['warnings'];
126
119
  };
127
120
 
128
121
  /**
129
- * Options shared by batch status and result retrieval operations.
122
+ * Options for retrieving batch status.
130
123
  */
131
- export type BatchOperationOptions<TOOLS extends ToolSet = ToolSet> = {
132
- model: BatchLanguageModel;
133
- batch: BatchReference;
134
-
124
+ export type GetBatchStatusOptions = {
135
125
  /**
136
- * Definitions for client tools that were provided to `startTextBatch`.
137
- *
138
- * The definitions are used only to validate and normalize returned tool
139
- * calls. Their `execute` functions are never invoked.
126
+ * Provider used to access the batch. Defaults to the global provider, or
127
+ * the Vercel AI Gateway when no global provider is configured.
140
128
  */
141
- tools?: TOOLS;
142
-
129
+ provider?: BatchProvider;
130
+ batch: BatchReference;
143
131
  providerOptions?: ProviderOptions;
144
132
  maxRetries?: number;
145
- } & BatchRequestOptions;
133
+ } & BatchCallOptions;
134
+
135
+ /**
136
+ * Options for retrieving batch results.
137
+ */
138
+ export type GetBatchResultsOptions<TOOLS extends ToolSet = ToolSet> =
139
+ GetBatchStatusOptions & {
140
+ /**
141
+ * Definitions for client tools that were provided to `startBatch` requests.
142
+ *
143
+ * The definitions are used only to validate and normalize returned tool
144
+ * calls. Their `execute` functions are never invoked.
145
+ */
146
+ tools?: TOOLS;
147
+ };
146
148
 
147
149
  /**
148
150
  * A normalized result for a successful text batch item.
@@ -182,3 +184,9 @@ export type TextBatchItemResult<TOOLS extends ToolSet = ToolSet> =
182
184
  readonly error?: BatchError;
183
185
  readonly providerMetadata?: ProviderMetadata;
184
186
  };
187
+
188
+ /**
189
+ * A complete terminal result for one request in a batch.
190
+ */
191
+ export type BatchItemResult<TOOLS extends ToolSet = ToolSet> =
192
+ TextBatchItemResult<TOOLS>;