@ai-sdk/amazon-bedrock 4.0.200 → 4.0.202

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.
@@ -35,7 +35,7 @@ var import_provider_utils = require("@ai-sdk/provider-utils");
35
35
  var import_aws4fetch = require("aws4fetch");
36
36
 
37
37
  // src/version.ts
38
- var VERSION = true ? "4.0.200" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.202" : "0.0.0-test";
39
39
 
40
40
  // src/bedrock-sigv4-fetch.ts
41
41
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -23,7 +23,7 @@ import {
23
23
  import { AwsV4Signer } from "aws4fetch";
24
24
 
25
25
  // src/version.ts
26
- var VERSION = true ? "4.0.200" : "0.0.0-test";
26
+ var VERSION = true ? "4.0.202" : "0.0.0-test";
27
27
 
28
28
  // src/bedrock-sigv4-fetch.ts
29
29
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.200",
3
+ "version": "4.0.202",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -44,10 +44,10 @@
44
44
  "@smithy/eventstream-codec": "^4.0.1",
45
45
  "@smithy/util-utf8": "^4.0.0",
46
46
  "aws4fetch": "^1.0.20",
47
- "@ai-sdk/anthropic": "3.0.134",
48
- "@ai-sdk/openai": "3.0.130",
47
+ "@ai-sdk/anthropic": "3.0.135",
48
+ "@ai-sdk/openai": "3.0.132",
49
49
  "@ai-sdk/provider": "3.0.19",
50
- "@ai-sdk/provider-utils": "4.0.61"
50
+ "@ai-sdk/provider-utils": "4.0.62"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "20.17.24",
@@ -1,4 +1,6 @@
1
1
  import {
2
+ lazySchema,
3
+ zodSchema,
2
4
  convertBase64ToUint8Array,
3
5
  safeParseJSON,
4
6
  type FetchFunction,
@@ -6,9 +8,13 @@ import {
6
8
  import { z } from 'zod/v4';
7
9
  import { createBedrockEventStreamDecoder } from '../bedrock-event-stream-decoder';
8
10
 
9
- const bedrockErrorSchema = z.looseObject({
10
- message: z.string().optional(),
11
- });
11
+ const bedrockErrorSchema = lazySchema(() =>
12
+ zodSchema(
13
+ z.looseObject({
14
+ message: z.string().optional(),
15
+ }),
16
+ ),
17
+ );
12
18
 
13
19
  export function createBedrockAnthropicFetch(
14
20
  baseFetch: FetchFunction,
@@ -13,6 +13,8 @@ import type {
13
13
  SharedV3Warning,
14
14
  } from '@ai-sdk/provider';
15
15
  import {
16
+ lazySchema,
17
+ zodSchema,
16
18
  combineHeaders,
17
19
  createJsonErrorResponseHandler,
18
20
  createJsonResponseHandler,
@@ -71,10 +73,16 @@ function isJsonResponseToolName(name: string): boolean {
71
73
  return name === 'json' || name === 'json<|channel|>commentary';
72
74
  }
73
75
 
74
- const anthropicProviderOptions = z.object({
75
- disableParallelToolUse: z.boolean().optional(),
76
- structuredOutputMode: z.enum(['outputFormat', 'jsonTool', 'auto']).optional(),
77
- });
76
+ const anthropicProviderOptions = lazySchema(() =>
77
+ zodSchema(
78
+ z.object({
79
+ disableParallelToolUse: z.boolean().optional(),
80
+ structuredOutputMode: z
81
+ .enum(['outputFormat', 'jsonTool', 'auto'])
82
+ .optional(),
83
+ }),
84
+ ),
85
+ );
78
86
 
79
87
  export class BedrockChatLanguageModel implements LanguageModelV3 {
80
88
  readonly specificationVersion = 'v3';
@@ -1268,14 +1276,16 @@ const BedrockToolUseSchema = z.object({
1268
1276
  input: z.unknown().optional(),
1269
1277
  });
1270
1278
 
1271
- const BedrockReasoningTextSchema = z.object({
1272
- signature: z.string().nullish(),
1273
- text: z.string(),
1274
- });
1279
+ const BedrockReasoningTextSchema = () =>
1280
+ z.object({
1281
+ signature: z.string().nullish(),
1282
+ text: z.string(),
1283
+ });
1275
1284
 
1276
- const BedrockRedactedReasoningSchema = z.object({
1277
- data: z.string(),
1278
- });
1285
+ const BedrockRedactedReasoningSchema = () =>
1286
+ z.object({
1287
+ data: z.string(),
1288
+ });
1279
1289
 
1280
1290
  const AmazonBedrockCacheDetailSchema = z
1281
1291
  .object({
@@ -1286,68 +1296,72 @@ const AmazonBedrockCacheDetailSchema = z
1286
1296
 
1287
1297
  // limited version of the schema, focused on what is needed for the implementation
1288
1298
  // this approach limits breakages when the API changes and increases efficiency
1289
- const BedrockResponseSchema = z.object({
1290
- metrics: z
1291
- .object({
1292
- latencyMs: z.number(),
1293
- })
1294
- .nullish(),
1295
- output: z.object({
1296
- message: z.object({
1297
- content: z.array(
1298
- z.object({
1299
- text: z.string().nullish(),
1300
- citationsContent: z
1301
- .object({
1302
- content: z
1303
- .array(
1299
+ const BedrockResponseSchema = lazySchema(() =>
1300
+ zodSchema(
1301
+ z.object({
1302
+ metrics: z
1303
+ .object({
1304
+ latencyMs: z.number(),
1305
+ })
1306
+ .nullish(),
1307
+ output: z.object({
1308
+ message: z.object({
1309
+ content: z.array(
1310
+ z.object({
1311
+ text: z.string().nullish(),
1312
+ citationsContent: z
1313
+ .object({
1314
+ content: z
1315
+ .array(
1316
+ z.object({
1317
+ text: z.string().nullish(),
1318
+ }),
1319
+ )
1320
+ .nullish(),
1321
+ })
1322
+ .nullish(),
1323
+ toolUse: BedrockToolUseSchema.nullish(),
1324
+ reasoningContent: z
1325
+ .union([
1326
+ z.object({
1327
+ reasoningText: BedrockReasoningTextSchema(),
1328
+ }),
1329
+ z.object({
1330
+ redactedReasoning: BedrockRedactedReasoningSchema(),
1331
+ }),
1332
+ // `redactedContent` is a member of the documented
1333
+ // ReasoningContentBlock union. OpenAI models on Bedrock
1334
+ // (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
1335
+ // reasoning in this shape.
1304
1336
  z.object({
1305
- text: z.string().nullish(),
1337
+ redactedContent: z.string(),
1306
1338
  }),
1307
- )
1339
+ ])
1308
1340
  .nullish(),
1309
- })
1310
- .nullish(),
1311
- toolUse: BedrockToolUseSchema.nullish(),
1312
- reasoningContent: z
1313
- .union([
1314
- z.object({
1315
- reasoningText: BedrockReasoningTextSchema,
1316
- }),
1317
- z.object({
1318
- redactedReasoning: BedrockRedactedReasoningSchema,
1319
- }),
1320
- // `redactedContent` is a member of the documented
1321
- // ReasoningContentBlock union. OpenAI models on Bedrock
1322
- // (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
1323
- // reasoning in this shape.
1324
- z.object({
1325
- redactedContent: z.string(),
1326
- }),
1327
- ])
1328
- .nullish(),
1341
+ }),
1342
+ ),
1343
+ role: z.string(),
1329
1344
  }),
1330
- ),
1331
- role: z.string(),
1345
+ }),
1346
+ stopReason: BedrockStopReasonSchema,
1347
+ additionalModelResponseFields:
1348
+ BedrockAdditionalModelResponseFieldsSchema.nullish(),
1349
+ trace: z.unknown().nullish(),
1350
+ performanceConfig: z.object({ latency: z.string() }).nullish(),
1351
+ serviceTier: z.object({ type: z.string() }).nullish(),
1352
+ usage: z
1353
+ .object({
1354
+ inputTokens: z.number(),
1355
+ outputTokens: z.number(),
1356
+ totalTokens: z.number(),
1357
+ cacheReadInputTokens: z.number().nullish(),
1358
+ cacheWriteInputTokens: z.number().nullish(),
1359
+ cacheDetails: z.array(AmazonBedrockCacheDetailSchema).nullish(),
1360
+ })
1361
+ .catchall(z.json()),
1332
1362
  }),
1333
- }),
1334
- stopReason: BedrockStopReasonSchema,
1335
- additionalModelResponseFields:
1336
- BedrockAdditionalModelResponseFieldsSchema.nullish(),
1337
- trace: z.unknown().nullish(),
1338
- performanceConfig: z.object({ latency: z.string() }).nullish(),
1339
- serviceTier: z.object({ type: z.string() }).nullish(),
1340
- usage: z
1341
- .object({
1342
- inputTokens: z.number(),
1343
- outputTokens: z.number(),
1344
- totalTokens: z.number(),
1345
- cacheReadInputTokens: z.number().nullish(),
1346
- cacheWriteInputTokens: z.number().nullish(),
1347
- cacheDetails: z.array(AmazonBedrockCacheDetailSchema).nullish(),
1348
- })
1349
- .catchall(z.json()),
1350
- });
1363
+ ),
1364
+ );
1351
1365
 
1352
1366
  // limited version of the schema, focussed on what is needed for the implementation
1353
1367
  // this approach limits breakages when the API changes and increases efficiency
@@ -1,3 +1,8 @@
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
1
6
  import { z } from 'zod/v4';
2
7
 
3
8
  // https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html
@@ -105,22 +110,26 @@ export type AmazonBedrockChatModelSettings = {
105
110
  * Bedrock file part provider options for document-specific features.
106
111
  * These options apply to individual file parts (documents).
107
112
  */
108
- export const bedrockFilePartProviderOptions = z.object({
109
- /**
110
- * Citation configuration for this document.
111
- * When enabled, this document will generate citations in the response.
112
- */
113
- citations: z
114
- .object({
113
+ export const bedrockFilePartProviderOptions = lazySchema(() =>
114
+ zodSchema(
115
+ z.object({
115
116
  /**
116
- * Enable citations for this document
117
+ * Citation configuration for this document.
118
+ * When enabled, this document will generate citations in the response.
117
119
  */
118
- enabled: z.boolean(),
119
- })
120
- .optional(),
121
- });
120
+ citations: z
121
+ .object({
122
+ /**
123
+ * Enable citations for this document
124
+ */
125
+ enabled: z.boolean(),
126
+ })
127
+ .optional(),
128
+ }),
129
+ ),
130
+ );
122
131
 
123
- export type BedrockFilePartProviderOptions = z.infer<
132
+ export type BedrockFilePartProviderOptions = InferSchema<
124
133
  typeof bedrockFilePartProviderOptions
125
134
  >;
126
135
 
@@ -3,6 +3,8 @@ import {
3
3
  type EmbeddingModelV3,
4
4
  } from '@ai-sdk/provider';
5
5
  import {
6
+ lazySchema,
7
+ zodSchema,
6
8
  combineHeaders,
7
9
  createJsonResponseHandler,
8
10
  parseProviderOptions,
@@ -187,30 +189,34 @@ function detectEmbeddingModelFamily(
187
189
  : 'titan';
188
190
  }
189
191
 
190
- const BedrockEmbeddingResponseSchema = z.union([
191
- // Titan-style response
192
- z.object({
193
- embedding: z.array(z.number()),
194
- inputTextTokenCount: z.number(),
195
- }),
196
- // Nova-style response
197
- z.object({
198
- embeddings: z.array(
192
+ const BedrockEmbeddingResponseSchema = lazySchema(() =>
193
+ zodSchema(
194
+ z.union([
195
+ // Titan-style response
199
196
  z.object({
200
- embeddingType: z.string(),
201
197
  embedding: z.array(z.number()),
198
+ inputTextTokenCount: z.number(),
202
199
  }),
203
- ),
204
- inputTokenCount: z.number().optional(),
205
- }),
206
- // Cohere v3-style response
207
- z.object({
208
- embeddings: z.array(z.array(z.number())),
209
- }),
210
- // Cohere v4-style response
211
- z.object({
212
- embeddings: z.object({
213
- float: z.array(z.array(z.number())),
214
- }),
215
- }),
216
- ]);
200
+ // Nova-style response
201
+ z.object({
202
+ embeddings: z.array(
203
+ z.object({
204
+ embeddingType: z.string(),
205
+ embedding: z.array(z.number()),
206
+ }),
207
+ ),
208
+ inputTokenCount: z.number().optional(),
209
+ }),
210
+ // Cohere v3-style response
211
+ z.object({
212
+ embeddings: z.array(z.array(z.number())),
213
+ }),
214
+ // Cohere v4-style response
215
+ z.object({
216
+ embeddings: z.object({
217
+ float: z.array(z.array(z.number())),
218
+ }),
219
+ }),
220
+ ]),
221
+ ),
222
+ );
@@ -1,3 +1,8 @@
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
1
6
  import { z } from 'zod/v4';
2
7
 
3
8
  export type BedrockEmbeddingModelId =
@@ -17,72 +22,91 @@ export type AmazonBedrockEmbeddingModelSettings = {
17
22
  modelFamily?: 'titan' | 'cohere' | 'nova';
18
23
  };
19
24
 
20
- export const amazonBedrockEmbeddingModelOptionsSchema = z.object({
21
- /**
22
- * The number of dimensions the resulting output embeddings should have (defaults to 1024).
23
- * Only supported in amazon.titan-embed-text-v2:0.
24
- */
25
- dimensions: z
26
- .union([z.literal(1024), z.literal(512), z.literal(256)])
27
- .optional(),
25
+ export const amazonBedrockEmbeddingModelOptionsSchema = lazySchema(() =>
26
+ zodSchema(
27
+ z.object({
28
+ /**
29
+ * The number of dimensions the resulting output embeddings should have (defaults to 1024).
30
+ * Only supported in amazon.titan-embed-text-v2:0.
31
+ */
32
+ dimensions: z
33
+ .union([z.literal(1024), z.literal(512), z.literal(256)])
34
+ .optional(),
28
35
 
29
- /**
30
- * Flag indicating whether or not to normalize the output embeddings. Defaults to true.
31
- * Only supported in amazon.titan-embed-text-v2:0.
32
- */
33
- normalize: z.boolean().optional(),
36
+ /**
37
+ * Flag indicating whether or not to normalize the output embeddings. Defaults to true.
38
+ * Only supported in amazon.titan-embed-text-v2:0.
39
+ */
40
+ normalize: z.boolean().optional(),
34
41
 
35
- /**
36
- * The number of dimensions for Nova embedding models (defaults to 1024).
37
- * Supported values: 256, 384, 1024, 3072.
38
- * Only supported in amazon.nova-* embedding models.
39
- */
40
- embeddingDimension: z
41
- .union([z.literal(256), z.literal(384), z.literal(1024), z.literal(3072)])
42
- .optional(),
42
+ /**
43
+ * The number of dimensions for Nova embedding models (defaults to 1024).
44
+ * Supported values: 256, 384, 1024, 3072.
45
+ * Only supported in amazon.nova-* embedding models.
46
+ */
47
+ embeddingDimension: z
48
+ .union([
49
+ z.literal(256),
50
+ z.literal(384),
51
+ z.literal(1024),
52
+ z.literal(3072),
53
+ ])
54
+ .optional(),
43
55
 
44
- /**
45
- * The purpose of the embedding. Defaults to 'GENERIC_INDEX'.
46
- * Only supported in amazon.nova-* embedding models.
47
- */
48
- embeddingPurpose: z
49
- .enum([
50
- 'GENERIC_INDEX',
51
- 'TEXT_RETRIEVAL',
52
- 'IMAGE_RETRIEVAL',
53
- 'VIDEO_RETRIEVAL',
54
- 'DOCUMENT_RETRIEVAL',
55
- 'AUDIO_RETRIEVAL',
56
- 'GENERIC_RETRIEVAL',
57
- 'CLASSIFICATION',
58
- 'CLUSTERING',
59
- ])
60
- .optional(),
56
+ /**
57
+ * The purpose of the embedding. Defaults to 'GENERIC_INDEX'.
58
+ * Only supported in amazon.nova-* embedding models.
59
+ */
60
+ embeddingPurpose: z
61
+ .enum([
62
+ 'GENERIC_INDEX',
63
+ 'TEXT_RETRIEVAL',
64
+ 'IMAGE_RETRIEVAL',
65
+ 'VIDEO_RETRIEVAL',
66
+ 'DOCUMENT_RETRIEVAL',
67
+ 'AUDIO_RETRIEVAL',
68
+ 'GENERIC_RETRIEVAL',
69
+ 'CLASSIFICATION',
70
+ 'CLUSTERING',
71
+ ])
72
+ .optional(),
61
73
 
62
- /**
63
- * Input type for Cohere embedding models on Bedrock.
64
- * Common values: `search_document`, `search_query`, `classification`, `clustering`.
65
- * If not set, the provider defaults to `search_query`.
66
- */
67
- inputType: z
68
- .enum(['search_document', 'search_query', 'classification', 'clustering'])
69
- .optional(),
74
+ /**
75
+ * Input type for Cohere embedding models on Bedrock.
76
+ * Common values: `search_document`, `search_query`, `classification`, `clustering`.
77
+ * If not set, the provider defaults to `search_query`.
78
+ */
79
+ inputType: z
80
+ .enum([
81
+ 'search_document',
82
+ 'search_query',
83
+ 'classification',
84
+ 'clustering',
85
+ ])
86
+ .optional(),
70
87
 
71
- /**
72
- * Truncation behavior when input exceeds the model's context length.
73
- * Supported in Cohere and Nova embedding models. Defaults to 'END' for Nova models.
74
- */
75
- truncate: z.enum(['NONE', 'START', 'END']).optional(),
88
+ /**
89
+ * Truncation behavior when input exceeds the model's context length.
90
+ * Supported in Cohere and Nova embedding models. Defaults to 'END' for Nova models.
91
+ */
92
+ truncate: z.enum(['NONE', 'START', 'END']).optional(),
76
93
 
77
- /**
78
- * The number of dimensions the resulting output embeddings should have (defaults to 1536).
79
- * Only supported in cohere.embed-v4:0 and newer Cohere embedding models.
80
- */
81
- outputDimension: z
82
- .union([z.literal(256), z.literal(512), z.literal(1024), z.literal(1536)])
83
- .optional(),
84
- });
94
+ /**
95
+ * The number of dimensions the resulting output embeddings should have (defaults to 1536).
96
+ * Only supported in cohere.embed-v4:0 and newer Cohere embedding models.
97
+ */
98
+ outputDimension: z
99
+ .union([
100
+ z.literal(256),
101
+ z.literal(512),
102
+ z.literal(1024),
103
+ z.literal(1536),
104
+ ])
105
+ .optional(),
106
+ }),
107
+ ),
108
+ );
85
109
 
86
- export type AmazonBedrockEmbeddingModelOptions = z.infer<
110
+ export type AmazonBedrockEmbeddingModelOptions = InferSchema<
87
111
  typeof amazonBedrockEmbeddingModelOptionsSchema
88
112
  >;
@@ -1,10 +1,18 @@
1
- import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ createJsonErrorResponseHandler,
5
+ } from '@ai-sdk/provider-utils';
2
6
  import { z } from 'zod/v4';
3
7
 
4
- export const BedrockErrorSchema = z.object({
5
- message: z.string(),
6
- type: z.string().nullish(),
7
- });
8
+ export const BedrockErrorSchema = lazySchema(() =>
9
+ zodSchema(
10
+ z.object({
11
+ message: z.string(),
12
+ type: z.string().nullish(),
13
+ }),
14
+ ),
15
+ );
8
16
 
9
17
  export const bedrockFailedResponseHandler = createJsonErrorResponseHandler({
10
18
  errorSchema: BedrockErrorSchema,
@@ -4,6 +4,8 @@ import type {
4
4
  SharedV3Warning,
5
5
  } from '@ai-sdk/provider';
6
6
  import {
7
+ lazySchema,
8
+ zodSchema,
7
9
  combineHeaders,
8
10
  convertUint8ArrayToBase64,
9
11
  createJsonResponseHandler,
@@ -279,15 +281,19 @@ function getBase64Data(file: ImageModelV3File): string {
279
281
 
280
282
  // minimal version of the schema, focussed on what is needed for the implementation
281
283
  // this approach limits breakages when the API changes and increases efficiency
282
- const bedrockImageResponseSchema = z.object({
283
- // Normal successful response
284
- images: z.array(z.string()).optional(),
285
-
286
- // Moderation response fields
287
- id: z.string().optional(),
288
- status: z.string().optional(),
289
- result: z.unknown().optional(),
290
- progress: z.unknown().optional(),
291
- details: z.record(z.string(), z.unknown()).optional(),
292
- preview: z.unknown().optional(),
293
- });
284
+ const bedrockImageResponseSchema = lazySchema(() =>
285
+ zodSchema(
286
+ z.object({
287
+ // Normal successful response
288
+ images: z.array(z.string()).optional(),
289
+
290
+ // Moderation response fields
291
+ id: z.string().optional(),
292
+ status: z.string().optional(),
293
+ result: z.unknown().optional(),
294
+ progress: z.unknown().optional(),
295
+ details: z.record(z.string(), z.unknown()).optional(),
296
+ preview: z.unknown().optional(),
297
+ }),
298
+ ),
299
+ );
@@ -1,11 +1,20 @@
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
1
6
  import { z } from 'zod/v4';
2
7
 
3
- export const bedrockReasoningMetadataSchema = z.object({
4
- signature: z.string().optional(),
5
- redactedData: z.string().optional(),
6
- redactedContent: z.string().optional(),
7
- });
8
+ export const bedrockReasoningMetadataSchema = lazySchema(() =>
9
+ zodSchema(
10
+ z.object({
11
+ signature: z.string().optional(),
12
+ redactedData: z.string().optional(),
13
+ redactedContent: z.string().optional(),
14
+ }),
15
+ ),
16
+ );
8
17
 
9
- export type BedrockReasoningMetadata = z.infer<
18
+ export type BedrockReasoningMetadata = InferSchema<
10
19
  typeof bedrockReasoningMetadataSchema
11
20
  >;