@ai-sdk/amazon-bedrock 5.0.120 → 5.0.121

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.
@@ -4,7 +4,7 @@ let _ai_sdk_provider = require("@ai-sdk/provider");
4
4
  let _ai_sdk_provider_utils = require("@ai-sdk/provider-utils");
5
5
  let aws4fetch = require("aws4fetch");
6
6
  //#region src/version.ts
7
- const VERSION = "5.0.120";
7
+ const VERSION = "5.0.121";
8
8
  //#endregion
9
9
  //#region src/amazon-bedrock-sigv4-fetch.ts
10
10
  /**
@@ -3,7 +3,7 @@ import { InvalidArgumentError, NoSuchModelError } from "@ai-sdk/provider";
3
3
  import { combineHeaders, getRuntimeEnvironmentUserAgent, isValidHostnamePart, loadOptionalSetting, loadSetting, normalizeHeaders, withUserAgentSuffix, withoutTrailingSlash } from "@ai-sdk/provider-utils";
4
4
  import { AwsV4Signer } from "aws4fetch";
5
5
  //#region src/version.ts
6
- const VERSION = "5.0.120";
6
+ const VERSION = "5.0.121";
7
7
  //#endregion
8
8
  //#region src/amazon-bedrock-sigv4-fetch.ts
9
9
  /**
@@ -1,17 +1,65 @@
1
1
  ---
2
2
  title: Amazon Bedrock
3
- description: Learn how to use the Amazon Bedrock provider.
3
+ description: Learn how to use Amazon Bedrock with AI Gateway and the direct provider.
4
4
  ---
5
5
 
6
6
  # Amazon Bedrock Provider
7
7
 
8
8
  The Amazon Bedrock provider for the [AI SDK](/docs) contains language model support for the [Amazon Bedrock](https://aws.amazon.com/bedrock) APIs.
9
+ Start with [AI Gateway](/providers/ai-sdk-providers/ai-gateway) for models in its catalog (recommended), or use `@ai-sdk/amazon-bedrock` to connect directly to Amazon Bedrock.
9
10
 
10
- ## Setup
11
+ ```ts provider="amazon" model="amazon/nova-pro"
12
+ import { generateText } from 'ai';
13
+ __PROVIDER_IMPORT__;
14
+
15
+ const { text } = await generateText({
16
+ model: __MODEL__,
17
+ prompt: 'Write a vegetarian lasagna recipe for 4 people.',
18
+ __GATEWAY_OPTIONS__,
19
+ });
20
+
21
+ console.log(text);
22
+ ```
23
+
24
+ ## Using AI Gateway
25
+
26
+ The AI SDK uses AI Gateway by default for model strings. Gateway provides access to models across providers through a single API key, with usage and cost tracking. Install `ai`:
27
+
28
+ <InstallPackages packages="ai" />
29
+
30
+ Set an [AI Gateway API key](https://vercel.com/docs/ai-gateway/getting-started) in your environment:
31
+
32
+ ```bash
33
+ export AI_GATEWAY_API_KEY=your_api_key_here
34
+ ```
35
+
36
+ Vercel deployments can also use [OIDC authentication](/providers/ai-sdk-providers/ai-gateway#oidc-authentication-vercel-deployments).
37
+ See the [AI Gateway provider documentation](/providers/ai-sdk-providers/ai-gateway) for configuration and the [model catalog](https://vercel.com/ai-gateway/models) for available models.
38
+
39
+ The example sets `providerOptions.gateway.order` to `['bedrock']`. This sends the request to Amazon Bedrock first, then falls back to other available providers of the same model if Amazon Bedrock is unavailable or the request fails. `order` sets a preference; it does not restrict fallback to Amazon Bedrock. See [provider ordering](https://vercel.com/docs/ai-gateway/models-and-providers/provider-filtering-and-ordering).
40
+
41
+ The dropdown lists models served by Amazon Bedrock through Gateway with a corresponding direct-provider example. Provider availability depends on the model and your team's [Provider Allowlist](https://vercel.com/docs/ai-gateway/models-and-providers/provider-filtering-and-ordering).
42
+
43
+ ## Using `@ai-sdk/amazon-bedrock`
44
+
45
+ For direct access to Amazon Bedrock, install `ai` and `@ai-sdk/amazon-bedrock`:
46
+
47
+ <InstallPackages packages="ai @ai-sdk/amazon-bedrock" />
11
48
 
12
- The Bedrock provider is available in the `@ai-sdk/amazon-bedrock` module. You can install it with
49
+ Set your Amazon Bedrock API credential in the `AWS_BEARER_TOKEN_BEDROCK` environment variable:
13
50
 
14
- <InstallPackages packages="@ai-sdk/amazon-bedrock" />
51
+ ```bash
52
+ export AWS_BEARER_TOKEN_BEDROCK=your_api_key_here
53
+ export AWS_REGION=us-east-1
54
+ ```
55
+
56
+ Use the direct provider for AWS authentication, account-specific inference profiles, or Bedrock-specific APIs. Gateway and Bedrock use different model IDs.
57
+
58
+ <Note>
59
+ The following sections document the direct `@ai-sdk/amazon-bedrock` provider,
60
+ including its model factories and settings. Gateway model and feature
61
+ availability can differ.
62
+ </Note>
15
63
 
16
64
  ### Prerequisites
17
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "5.0.120",
3
+ "version": "5.0.121",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -41,10 +41,10 @@
41
41
  }
42
42
  },
43
43
  "dependencies": {
44
- "@ai-sdk/anthropic": "4.0.84",
45
- "@ai-sdk/openai": "4.0.98",
44
+ "@ai-sdk/anthropic": "4.0.85",
45
+ "@ai-sdk/openai": "4.0.99",
46
46
  "@ai-sdk/provider": "4.0.31",
47
- "@ai-sdk/provider-utils": "5.0.64",
47
+ "@ai-sdk/provider-utils": "5.0.65",
48
48
  "@smithy/eventstream-codec": "^4.3.3",
49
49
  "@smithy/util-utf8": "^4.3.3",
50
50
  "aws4fetch": "^1.0.20"
@@ -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
@@ -108,22 +113,26 @@ export type AmazonBedrockChatModelSettings = {
108
113
  * Bedrock file part provider options for document-specific features.
109
114
  * These options apply to individual file parts (documents).
110
115
  */
111
- export const amazonBedrockFilePartProviderOptions = z.object({
112
- /**
113
- * Citation configuration for this document.
114
- * When enabled, this document will generate citations in the response.
115
- */
116
- citations: z
117
- .object({
116
+ export const amazonBedrockFilePartProviderOptions = lazySchema(() =>
117
+ zodSchema(
118
+ z.object({
118
119
  /**
119
- * Enable citations for this document
120
+ * Citation configuration for this document.
121
+ * When enabled, this document will generate citations in the response.
120
122
  */
121
- enabled: z.boolean(),
122
- })
123
- .optional(),
124
- });
123
+ citations: z
124
+ .object({
125
+ /**
126
+ * Enable citations for this document
127
+ */
128
+ enabled: z.boolean(),
129
+ })
130
+ .optional(),
131
+ }),
132
+ ),
133
+ );
125
134
 
126
- export type AmazonBedrockFilePartProviderOptions = z.infer<
135
+ export type AmazonBedrockFilePartProviderOptions = InferSchema<
127
136
  typeof amazonBedrockFilePartProviderOptions
128
137
  >;
129
138
 
@@ -131,14 +140,18 @@ export type AmazonBedrockFilePartProviderOptions = z.infer<
131
140
  * Amazon Bedrock text part provider options for guardrail content.
132
141
  * These options apply to individual text parts.
133
142
  */
134
- export const amazonBedrockTextPartProviderOptions = z.object({
135
- guardContent: z.boolean().optional(),
136
- guardContentQualifiers: z
137
- .array(z.enum(['grounding_source', 'query', 'guard_content']))
138
- .optional(),
139
- });
143
+ export const amazonBedrockTextPartProviderOptions = lazySchema(() =>
144
+ zodSchema(
145
+ z.object({
146
+ guardContent: z.boolean().optional(),
147
+ guardContentQualifiers: z
148
+ .array(z.enum(['grounding_source', 'query', 'guard_content']))
149
+ .optional(),
150
+ }),
151
+ ),
152
+ );
140
153
 
141
- export type AmazonBedrockTextPartProviderOptions = z.infer<
154
+ export type AmazonBedrockTextPartProviderOptions = InferSchema<
142
155
  typeof amazonBedrockTextPartProviderOptions
143
156
  >;
144
157
 
@@ -146,11 +159,15 @@ export type AmazonBedrockTextPartProviderOptions = z.infer<
146
159
  * Amazon Bedrock image part provider options for guardrail content.
147
160
  * These options apply to individual image parts.
148
161
  */
149
- export const amazonBedrockImagePartProviderOptions = z.object({
150
- guardContent: z.boolean().optional(),
151
- });
162
+ export const amazonBedrockImagePartProviderOptions = lazySchema(() =>
163
+ zodSchema(
164
+ z.object({
165
+ guardContent: z.boolean().optional(),
166
+ }),
167
+ ),
168
+ );
152
169
 
153
- export type AmazonBedrockImagePartProviderOptions = z.infer<
170
+ export type AmazonBedrockImagePartProviderOptions = InferSchema<
154
171
  typeof amazonBedrockImagePartProviderOptions
155
172
  >;
156
173
 
@@ -13,6 +13,8 @@ import type {
13
13
  SharedV4Warning,
14
14
  } from '@ai-sdk/provider';
15
15
  import {
16
+ lazySchema,
17
+ zodSchema,
16
18
  combineHeaders,
17
19
  createProviderStreamError,
18
20
  createJsonErrorResponseHandler,
@@ -79,10 +81,16 @@ type AmazonBedrockChatConfig = {
79
81
  modelFamily?: AmazonBedrockChatModelSettings['modelFamily'];
80
82
  };
81
83
 
82
- const anthropicProviderOptions = z.object({
83
- disableParallelToolUse: z.boolean().optional(),
84
- structuredOutputMode: z.enum(['outputFormat', 'jsonTool', 'auto']).optional(),
85
- });
84
+ const anthropicProviderOptions = lazySchema(() =>
85
+ zodSchema(
86
+ z.object({
87
+ disableParallelToolUse: z.boolean().optional(),
88
+ structuredOutputMode: z
89
+ .enum(['outputFormat', 'jsonTool', 'auto'])
90
+ .optional(),
91
+ }),
92
+ ),
93
+ );
86
94
 
87
95
  function createAmazonBedrockStreamError({
88
96
  type,
@@ -1454,14 +1462,16 @@ const AmazonBedrockToolUseSchema = z.object({
1454
1462
  input: z.unknown().optional(),
1455
1463
  });
1456
1464
 
1457
- const AmazonBedrockReasoningTextSchema = z.object({
1458
- signature: z.string().nullish(),
1459
- text: z.string(),
1460
- });
1465
+ const AmazonBedrockReasoningTextSchema = () =>
1466
+ z.object({
1467
+ signature: z.string().nullish(),
1468
+ text: z.string(),
1469
+ });
1461
1470
 
1462
- const AmazonBedrockRedactedReasoningSchema = z.object({
1463
- data: z.string(),
1464
- });
1471
+ const AmazonBedrockRedactedReasoningSchema = () =>
1472
+ z.object({
1473
+ data: z.string(),
1474
+ });
1465
1475
 
1466
1476
  const AmazonBedrockCacheDetailSchema = z
1467
1477
  .object({
@@ -1472,68 +1482,72 @@ const AmazonBedrockCacheDetailSchema = z
1472
1482
 
1473
1483
  // limited version of the schema, focused on what is needed for the implementation
1474
1484
  // this approach limits breakages when the API changes and increases efficiency
1475
- const AmazonBedrockResponseSchema = z.object({
1476
- metrics: z
1477
- .object({
1478
- latencyMs: z.number(),
1479
- })
1480
- .nullish(),
1481
- output: z.object({
1482
- message: z.object({
1483
- content: z.array(
1484
- z.object({
1485
- text: z.string().nullish(),
1486
- citationsContent: z
1487
- .object({
1488
- content: z
1489
- .array(
1485
+ const AmazonBedrockResponseSchema = lazySchema(() =>
1486
+ zodSchema(
1487
+ z.object({
1488
+ metrics: z
1489
+ .object({
1490
+ latencyMs: z.number(),
1491
+ })
1492
+ .nullish(),
1493
+ output: z.object({
1494
+ message: z.object({
1495
+ content: z.array(
1496
+ z.object({
1497
+ text: z.string().nullish(),
1498
+ citationsContent: z
1499
+ .object({
1500
+ content: z
1501
+ .array(
1502
+ z.object({
1503
+ text: z.string().nullish(),
1504
+ }),
1505
+ )
1506
+ .nullish(),
1507
+ })
1508
+ .nullish(),
1509
+ toolUse: AmazonBedrockToolUseSchema.nullish(),
1510
+ reasoningContent: z
1511
+ .union([
1512
+ z.object({
1513
+ reasoningText: AmazonBedrockReasoningTextSchema(),
1514
+ }),
1490
1515
  z.object({
1491
- text: z.string().nullish(),
1516
+ redactedReasoning: AmazonBedrockRedactedReasoningSchema(),
1492
1517
  }),
1493
- )
1518
+ // `redactedContent` is a member of the documented
1519
+ // ReasoningContentBlock union. OpenAI models on Bedrock
1520
+ // (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
1521
+ // reasoning in this shape.
1522
+ z.object({
1523
+ redactedContent: z.string(),
1524
+ }),
1525
+ ])
1494
1526
  .nullish(),
1495
- })
1496
- .nullish(),
1497
- toolUse: AmazonBedrockToolUseSchema.nullish(),
1498
- reasoningContent: z
1499
- .union([
1500
- z.object({
1501
- reasoningText: AmazonBedrockReasoningTextSchema,
1502
- }),
1503
- z.object({
1504
- redactedReasoning: AmazonBedrockRedactedReasoningSchema,
1505
- }),
1506
- // `redactedContent` is a member of the documented
1507
- // ReasoningContentBlock union. OpenAI models on Bedrock
1508
- // (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
1509
- // reasoning in this shape.
1510
- z.object({
1511
- redactedContent: z.string(),
1512
- }),
1513
- ])
1514
- .nullish(),
1527
+ }),
1528
+ ),
1529
+ role: z.string(),
1515
1530
  }),
1516
- ),
1517
- role: z.string(),
1531
+ }),
1532
+ stopReason: AmazonBedrockStopReasonSchema,
1533
+ additionalModelResponseFields:
1534
+ AmazonBedrockAdditionalModelResponseFieldsSchema.nullish(),
1535
+ trace: z.unknown().nullish(),
1536
+ performanceConfig: z.object({ latency: z.string() }).nullish(),
1537
+ serviceTier: z.object({ type: z.string() }).nullish(),
1538
+ usage: z
1539
+ .object({
1540
+ inputTokens: z.number(),
1541
+ outputTokens: z.number(),
1542
+ totalTokens: z.number(),
1543
+ cacheReadInputTokens: z.number().nullish(),
1544
+ cacheWriteInputTokens: z.number().nullish(),
1545
+ cacheDetails: z.array(AmazonBedrockCacheDetailSchema).nullish(),
1546
+ })
1547
+ .catchall(z.json()),
1518
1548
  }),
1519
- }),
1520
- stopReason: AmazonBedrockStopReasonSchema,
1521
- additionalModelResponseFields:
1522
- AmazonBedrockAdditionalModelResponseFieldsSchema.nullish(),
1523
- trace: z.unknown().nullish(),
1524
- performanceConfig: z.object({ latency: z.string() }).nullish(),
1525
- serviceTier: z.object({ type: z.string() }).nullish(),
1526
- usage: z
1527
- .object({
1528
- inputTokens: z.number(),
1529
- outputTokens: z.number(),
1530
- totalTokens: z.number(),
1531
- cacheReadInputTokens: z.number().nullish(),
1532
- cacheWriteInputTokens: z.number().nullish(),
1533
- cacheDetails: z.array(AmazonBedrockCacheDetailSchema).nullish(),
1534
- })
1535
- .catchall(z.json()),
1536
- });
1549
+ ),
1550
+ );
1537
1551
 
1538
1552
  // limited version of the schema, focussed on what is needed for the implementation
1539
1553
  // 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
  export type AmazonBedrockEmbeddingModelId =
@@ -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
  >;
@@ -3,6 +3,8 @@ import {
3
3
  type EmbeddingModelV4,
4
4
  } from '@ai-sdk/provider';
5
5
  import {
6
+ lazySchema,
7
+ zodSchema,
6
8
  combineHeaders,
7
9
  createJsonResponseHandler,
8
10
  parseProviderOptions,
@@ -217,30 +219,34 @@ function detectEmbeddingModelFamily(
217
219
  : 'titan';
218
220
  }
219
221
 
220
- const AmazonBedrockEmbeddingResponseSchema = z.union([
221
- // Titan-style response
222
- z.object({
223
- embedding: z.array(z.number()),
224
- inputTextTokenCount: z.number(),
225
- }),
226
- // Nova-style response
227
- z.object({
228
- embeddings: z.array(
222
+ const AmazonBedrockEmbeddingResponseSchema = lazySchema(() =>
223
+ zodSchema(
224
+ z.union([
225
+ // Titan-style response
229
226
  z.object({
230
- embeddingType: z.string(),
231
227
  embedding: z.array(z.number()),
228
+ inputTextTokenCount: z.number(),
232
229
  }),
233
- ),
234
- inputTokenCount: z.number().optional(),
235
- }),
236
- // Cohere v3-style response
237
- z.object({
238
- embeddings: z.array(z.array(z.number())),
239
- }),
240
- // Cohere v4-style response
241
- z.object({
242
- embeddings: z.object({
243
- float: z.array(z.array(z.number())),
244
- }),
245
- }),
246
- ]);
230
+ // Nova-style response
231
+ z.object({
232
+ embeddings: z.array(
233
+ z.object({
234
+ embeddingType: z.string(),
235
+ embedding: z.array(z.number()),
236
+ }),
237
+ ),
238
+ inputTokenCount: z.number().optional(),
239
+ }),
240
+ // Cohere v3-style response
241
+ z.object({
242
+ embeddings: z.array(z.array(z.number())),
243
+ }),
244
+ // Cohere v4-style response
245
+ z.object({
246
+ embeddings: z.object({
247
+ float: z.array(z.array(z.number())),
248
+ }),
249
+ }),
250
+ ]),
251
+ ),
252
+ );
@@ -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 AmazonBedrockErrorSchema = z.object({
5
- message: z.string(),
6
- type: z.string().nullish(),
7
- });
8
+ export const AmazonBedrockErrorSchema = lazySchema(() =>
9
+ zodSchema(
10
+ z.object({
11
+ message: z.string(),
12
+ type: z.string().nullish(),
13
+ }),
14
+ ),
15
+ );
8
16
 
9
17
  export const amazonBedrockFailedResponseHandler =
10
18
  createJsonErrorResponseHandler({