ai 7.0.94 → 7.0.96

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.
@@ -0,0 +1,96 @@
1
+ ---
2
+ title: experimental_cancelBatch
3
+ description: API Reference for experimental_cancelBatch.
4
+ ---
5
+
6
+ # `experimental_cancelBatch()`
7
+
8
+ <Note type="warning">
9
+ Batch support is experimental and the API may change in patch releases.
10
+ </Note>
11
+
12
+ Requests cancellation of an asynchronous batch. A successful call means that
13
+ the provider accepted the cancellation request, not that cancellation has
14
+ finished. For a complete guide to the batch lifecycle, see
15
+ [Batch](/docs/ai-sdk-core/batch).
16
+
17
+ ```ts
18
+ import { experimental_cancelBatch as cancelBatch } from 'ai';
19
+
20
+ const result = await cancelBatch({
21
+ provider,
22
+ batch,
23
+ });
24
+
25
+ console.log(result.providerMetadata);
26
+ ```
27
+
28
+ ## Import
29
+
30
+ <Snippet
31
+ text={`import { experimental_cancelBatch } from "ai"`}
32
+ prompt={false}
33
+ />
34
+
35
+ ## API Signature
36
+
37
+ ### Parameters
38
+
39
+ <PropertiesTable
40
+ content={[
41
+ {
42
+ name: 'provider',
43
+ type: 'Experimental_BatchProvider',
44
+ isOptional: true,
45
+ description:
46
+ 'The provider used to access the batch. Defaults to the global provider, or the AI Gateway when no global provider is configured.',
47
+ },
48
+ {
49
+ name: 'batch',
50
+ type: 'Experimental_BatchReference',
51
+ description:
52
+ 'The serializable reference returned by experimental_startBatch.',
53
+ },
54
+ {
55
+ name: 'providerOptions',
56
+ type: 'ProviderOptions',
57
+ isOptional: true,
58
+ description:
59
+ 'Additional provider-specific options for the cancellation request.',
60
+ },
61
+ {
62
+ name: 'abortSignal',
63
+ type: 'AbortSignal',
64
+ isOptional: true,
65
+ description: 'An optional abort signal to cancel the API request.',
66
+ },
67
+ {
68
+ name: 'timeout',
69
+ type: 'number | { totalMs?: number }',
70
+ isOptional: true,
71
+ description: 'Maximum time allowed for the cancellation request.',
72
+ },
73
+ {
74
+ name: 'headers',
75
+ type: 'Record<string, string | undefined>',
76
+ isOptional: true,
77
+ description: 'Additional HTTP headers for the request.',
78
+ },
79
+ ]}
80
+ />
81
+
82
+ ### Returns
83
+
84
+ <PropertiesTable
85
+ content={[
86
+ {
87
+ name: 'providerMetadata',
88
+ type: 'ProviderMetadata',
89
+ isOptional: true,
90
+ description: 'Provider-specific metadata from the cancellation response.',
91
+ },
92
+ ]}
93
+ />
94
+
95
+ Calling this function with a provider that does not support batch cancellation
96
+ throws an `UnsupportedFunctionalityError`.
@@ -0,0 +1,121 @@
1
+ ---
2
+ title: experimental_listBatches
3
+ description: API Reference for experimental_listBatches.
4
+ ---
5
+
6
+ # `experimental_listBatches()`
7
+
8
+ <Note type="warning">
9
+ Batch support is experimental and the API may change in patch releases.
10
+ </Note>
11
+
12
+ Lists a page of asynchronous batches and their latest normalized statuses. For
13
+ a complete guide to the batch lifecycle, see [Batch](/docs/ai-sdk-core/batch).
14
+
15
+ ```ts
16
+ import { experimental_listBatches as listBatches } from 'ai';
17
+
18
+ const page = await listBatches({
19
+ provider,
20
+ limit: 20,
21
+ cursor,
22
+ });
23
+
24
+ console.log(page.batches, page.nextCursor);
25
+ ```
26
+
27
+ ## Import
28
+
29
+ <Snippet
30
+ text={`import { experimental_listBatches } 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 whose batches should be listed. Defaults to the global provider, or the AI Gateway when no global provider is configured.',
46
+ },
47
+ {
48
+ name: 'limit',
49
+ type: 'number',
50
+ isOptional: true,
51
+ description: 'Maximum number of batches to return in this page.',
52
+ },
53
+ {
54
+ name: 'cursor',
55
+ type: 'string',
56
+ isOptional: true,
57
+ description:
58
+ 'Opaque cursor returned as nextCursor by the previous list operation.',
59
+ },
60
+ {
61
+ name: 'providerOptions',
62
+ type: 'ProviderOptions',
63
+ isOptional: true,
64
+ description: 'Additional provider-specific options for listing batches.',
65
+ },
66
+ {
67
+ name: 'maxRetries',
68
+ type: 'number',
69
+ isOptional: true,
70
+ description:
71
+ 'Maximum number of retries for listing batches. Set to 0 to disable retries. Default: 2.',
72
+ },
73
+ {
74
+ name: 'abortSignal',
75
+ type: 'AbortSignal',
76
+ isOptional: true,
77
+ description: 'An optional abort signal to cancel the request.',
78
+ },
79
+ {
80
+ name: 'timeout',
81
+ type: 'number | { totalMs?: number }',
82
+ isOptional: true,
83
+ description: 'Maximum time allowed for the list request.',
84
+ },
85
+ {
86
+ name: 'headers',
87
+ type: 'Record<string, string | undefined>',
88
+ isOptional: true,
89
+ description: 'Additional HTTP headers for the request.',
90
+ },
91
+ ]}
92
+ />
93
+
94
+ ### Returns
95
+
96
+ <PropertiesTable
97
+ content={[
98
+ {
99
+ name: 'batches',
100
+ type: 'Array<Experimental_Batch>',
101
+ description:
102
+ 'The batches in this page. Each item contains a serializable batch reference and its latest normalized status.',
103
+ },
104
+ {
105
+ name: 'nextCursor',
106
+ type: 'string',
107
+ isOptional: true,
108
+ description:
109
+ 'Opaque cursor to pass as cursor to retrieve the next page. Omitted when there are no more batches.',
110
+ },
111
+ {
112
+ name: 'providerMetadata',
113
+ type: 'ProviderMetadata',
114
+ isOptional: true,
115
+ description: 'Provider-specific metadata for the list operation.',
116
+ },
117
+ ]}
118
+ />
119
+
120
+ Calling this function with a provider that does not support listing batches
121
+ throws an `UnsupportedFunctionalityError`.
@@ -53,6 +53,31 @@ 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
+ },
71
+ {
72
+ title: 'experimental_cancelBatch()',
73
+ description: 'Request cancellation of an asynchronous batch.',
74
+ href: '/docs/reference/ai-sdk-core/cancel-batch',
75
+ },
76
+ {
77
+ title: 'experimental_listBatches()',
78
+ description: 'List asynchronous batches and their latest statuses.',
79
+ href: '/docs/reference/ai-sdk-core/list-batches',
80
+ },
56
81
  {
57
82
  title: 'transcribe()',
58
83
  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.94",
3
+ "version": "7.0.96",
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.76",
46
- "@ai-sdk/provider": "4.0.11",
47
- "@ai-sdk/provider-utils": "5.0.37"
45
+ "@ai-sdk/gateway": "4.0.77",
46
+ "@ai-sdk/provider": "4.0.12",
47
+ "@ai-sdk/provider-utils": "5.0.38"
48
48
  },
49
49
  "devDependencies": {
50
- "@ai-sdk/amazon-bedrock": "5.0.77",
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.61",
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",
57
57
  "@ai-sdk/test-server": "2.0.1",
58
- "@ai-sdk/xai": "4.0.55",
58
+ "@ai-sdk/xai": "4.0.56",
59
59
  "@edge-runtime/vm": "^5.0.0",
60
60
  "@smithy/eventstream-codec": "^4.3.3",
61
61
  "@smithy/util-utf8": "^4.3.3",
@@ -118,6 +118,42 @@ export type StartBatchResult = Batch & {
118
118
  readonly warnings: BatchV4StartResult['warnings'];
119
119
  };
120
120
 
121
+ /**
122
+ * Options for requesting cancellation of a batch.
123
+ */
124
+ export type CancelBatchOptions = {
125
+ provider?: BatchProvider;
126
+ batch: BatchReference;
127
+ providerOptions?: ProviderOptions;
128
+ } & BatchCallOptions;
129
+
130
+ /**
131
+ * Result of requesting cancellation of a batch.
132
+ */
133
+ export type CancelBatchResult = {
134
+ readonly providerMetadata?: ProviderMetadata;
135
+ };
136
+
137
+ /**
138
+ * Options for listing batches.
139
+ */
140
+ export type ListBatchesOptions = {
141
+ provider?: BatchProvider;
142
+ providerOptions?: ProviderOptions;
143
+ limit?: number;
144
+ cursor?: string;
145
+ maxRetries?: number;
146
+ } & BatchCallOptions;
147
+
148
+ /**
149
+ * One page of listed batches.
150
+ */
151
+ export type ListBatchesResult = {
152
+ readonly batches: Array<Batch>;
153
+ readonly nextCursor?: string;
154
+ readonly providerMetadata?: ProviderMetadata;
155
+ };
156
+
121
157
  /**
122
158
  * Options for retrieving batch status.
123
159
  */
@@ -31,14 +31,114 @@ import type {
31
31
  BatchProvider,
32
32
  BatchReference,
33
33
  BatchStatus,
34
+ CancelBatchOptions,
35
+ CancelBatchResult,
34
36
  GetBatchResultsOptions,
35
37
  GetBatchStatusOptions,
38
+ ListBatchesOptions,
39
+ ListBatchesResult,
36
40
  StartBatchOptions,
37
41
  StartBatchResult,
38
42
  TextBatchGenerationResult,
39
43
  TextBatchItemResult,
40
44
  } from './batch-types';
41
45
 
46
+ /**
47
+ * Requests cancellation of a batch.
48
+ */
49
+ export async function cancelBatch({
50
+ provider,
51
+ batch,
52
+ providerOptions,
53
+ abortSignal,
54
+ headers,
55
+ timeout,
56
+ }: CancelBatchOptions): Promise<CancelBatchResult> {
57
+ const batchApi = resolveBatchApi(provider);
58
+ validateBatchReference({ batchApi, batch });
59
+
60
+ if (batchApi.doCancelBatch == null) {
61
+ throw new UnsupportedFunctionalityError({
62
+ functionality: 'batch cancellation',
63
+ message: 'The provider does not support batch cancellation.',
64
+ });
65
+ }
66
+
67
+ const operationAbortSignal = mergeAbortSignals(
68
+ abortSignal,
69
+ getTotalTimeoutMs(timeout),
70
+ );
71
+
72
+ try {
73
+ return await batchApi.doCancelBatch({
74
+ batchId: batch.id,
75
+ providerOptions,
76
+ abortSignal: operationAbortSignal,
77
+ headers: withUserAgentSuffix(headers ?? {}, `ai/${VERSION}`),
78
+ });
79
+ } catch (error) {
80
+ throw wrapGatewayError(error);
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Lists a page of batches.
86
+ */
87
+ export async function listBatches({
88
+ provider,
89
+ providerOptions,
90
+ limit,
91
+ cursor,
92
+ maxRetries,
93
+ abortSignal,
94
+ headers,
95
+ timeout,
96
+ }: ListBatchesOptions = {}): Promise<ListBatchesResult> {
97
+ const batchApi = resolveBatchApi(provider);
98
+
99
+ const doListBatches = batchApi.doListBatches?.bind(batchApi);
100
+ if (doListBatches == null) {
101
+ throw new UnsupportedFunctionalityError({
102
+ functionality: 'batch listing',
103
+ message: 'The provider does not support listing batches.',
104
+ });
105
+ }
106
+
107
+ const operationAbortSignal = mergeAbortSignals(
108
+ abortSignal,
109
+ getTotalTimeoutMs(timeout),
110
+ );
111
+ const { retry } = prepareRetries({
112
+ maxRetries,
113
+ abortSignal: operationAbortSignal,
114
+ });
115
+
116
+ try {
117
+ const { batches, nextCursor, providerMetadata } = await retry(() =>
118
+ doListBatches({
119
+ providerOptions,
120
+ abortSignal: operationAbortSignal,
121
+ headers: withUserAgentSuffix(headers ?? {}, `ai/${VERSION}`),
122
+ ...(limit != null && { limit }),
123
+ ...(cursor != null && { cursor }),
124
+ }),
125
+ );
126
+
127
+ return {
128
+ batches: batches.map(({ batchId, ...status }) => ({
129
+ version: 2,
130
+ id: batchId,
131
+ provider: batchApi.provider,
132
+ ...status,
133
+ })),
134
+ ...(nextCursor != null && { nextCursor }),
135
+ ...(providerMetadata != null && { providerMetadata }),
136
+ };
137
+ } catch (error) {
138
+ throw wrapGatewayError(error);
139
+ }
140
+ }
141
+
42
142
  /**
43
143
  * Starts a batch.
44
144
  */