@ai-sdk/amazon-bedrock 5.0.120 → 5.0.122
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.
- package/CHANGELOG.md +35 -0
- package/dist/anthropic/index.js +3 -3
- package/dist/anthropic/index.js.map +1 -1
- package/dist/index.d.ts +10 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -25
- package/dist/index.js.map +1 -1
- package/dist/mantle/index.cjs +1 -1
- package/dist/mantle/index.js +1 -1
- package/docs/08-amazon-bedrock.mdx +52 -4
- package/package.json +5 -5
- package/src/amazon-bedrock-chat-language-model-options.ts +41 -24
- package/src/amazon-bedrock-chat-language-model.ts +84 -69
- package/src/amazon-bedrock-embedding-model-options.ts +84 -60
- package/src/amazon-bedrock-embedding-model.ts +30 -24
- package/src/amazon-bedrock-error.ts +13 -5
- package/src/amazon-bedrock-image-model.ts +18 -12
- package/src/amazon-bedrock-reasoning-metadata.ts +15 -6
- package/src/anthropic/amazon-bedrock-anthropic-fetch.ts +9 -3
package/dist/mantle/index.cjs
CHANGED
|
@@ -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.
|
|
7
|
+
const VERSION = "5.0.122";
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/amazon-bedrock-sigv4-fetch.ts
|
|
10
10
|
/**
|
package/dist/mantle/index.js
CHANGED
|
@@ -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.
|
|
6
|
+
const VERSION = "5.0.122";
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
49
|
+
Set your Amazon Bedrock API credential in the `AWS_BEARER_TOKEN_BEDROCK` environment variable:
|
|
13
50
|
|
|
14
|
-
|
|
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.
|
|
3
|
+
"version": "5.0.122",
|
|
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.
|
|
45
|
-
"@ai-sdk/openai": "4.0.
|
|
46
|
-
"@ai-sdk/provider": "4.0.
|
|
47
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
44
|
+
"@ai-sdk/anthropic": "4.0.86",
|
|
45
|
+
"@ai-sdk/openai": "4.0.100",
|
|
46
|
+
"@ai-sdk/provider": "4.0.32",
|
|
47
|
+
"@ai-sdk/provider-utils": "5.0.66",
|
|
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 =
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
*
|
|
120
|
+
* Citation configuration for this document.
|
|
121
|
+
* When enabled, this document will generate citations in the response.
|
|
120
122
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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 =
|
|
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 =
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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 =
|
|
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 =
|
|
150
|
-
|
|
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 =
|
|
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 =
|
|
83
|
-
|
|
84
|
-
|
|
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,
|
|
@@ -910,8 +918,9 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
|
|
|
910
918
|
fetch: this.config.fetch,
|
|
911
919
|
});
|
|
912
920
|
|
|
921
|
+
// A clean end without the provider's completion signal is interrupted.
|
|
913
922
|
let finishReason: LanguageModelV4FinishReason = {
|
|
914
|
-
unified: '
|
|
923
|
+
unified: 'interrupted',
|
|
915
924
|
raw: undefined,
|
|
916
925
|
};
|
|
917
926
|
let usage: AmazonBedrockUsage | undefined = undefined;
|
|
@@ -1454,14 +1463,16 @@ const AmazonBedrockToolUseSchema = z.object({
|
|
|
1454
1463
|
input: z.unknown().optional(),
|
|
1455
1464
|
});
|
|
1456
1465
|
|
|
1457
|
-
const AmazonBedrockReasoningTextSchema =
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1466
|
+
const AmazonBedrockReasoningTextSchema = () =>
|
|
1467
|
+
z.object({
|
|
1468
|
+
signature: z.string().nullish(),
|
|
1469
|
+
text: z.string(),
|
|
1470
|
+
});
|
|
1461
1471
|
|
|
1462
|
-
const AmazonBedrockRedactedReasoningSchema =
|
|
1463
|
-
|
|
1464
|
-
|
|
1472
|
+
const AmazonBedrockRedactedReasoningSchema = () =>
|
|
1473
|
+
z.object({
|
|
1474
|
+
data: z.string(),
|
|
1475
|
+
});
|
|
1465
1476
|
|
|
1466
1477
|
const AmazonBedrockCacheDetailSchema = z
|
|
1467
1478
|
.object({
|
|
@@ -1472,68 +1483,72 @@ const AmazonBedrockCacheDetailSchema = z
|
|
|
1472
1483
|
|
|
1473
1484
|
// limited version of the schema, focused on what is needed for the implementation
|
|
1474
1485
|
// this approach limits breakages when the API changes and increases efficiency
|
|
1475
|
-
const AmazonBedrockResponseSchema =
|
|
1476
|
-
|
|
1477
|
-
.object({
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
z.object({
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
.
|
|
1486
|
+
const AmazonBedrockResponseSchema = lazySchema(() =>
|
|
1487
|
+
zodSchema(
|
|
1488
|
+
z.object({
|
|
1489
|
+
metrics: z
|
|
1490
|
+
.object({
|
|
1491
|
+
latencyMs: z.number(),
|
|
1492
|
+
})
|
|
1493
|
+
.nullish(),
|
|
1494
|
+
output: z.object({
|
|
1495
|
+
message: z.object({
|
|
1496
|
+
content: z.array(
|
|
1497
|
+
z.object({
|
|
1498
|
+
text: z.string().nullish(),
|
|
1499
|
+
citationsContent: z
|
|
1500
|
+
.object({
|
|
1501
|
+
content: z
|
|
1502
|
+
.array(
|
|
1503
|
+
z.object({
|
|
1504
|
+
text: z.string().nullish(),
|
|
1505
|
+
}),
|
|
1506
|
+
)
|
|
1507
|
+
.nullish(),
|
|
1508
|
+
})
|
|
1509
|
+
.nullish(),
|
|
1510
|
+
toolUse: AmazonBedrockToolUseSchema.nullish(),
|
|
1511
|
+
reasoningContent: z
|
|
1512
|
+
.union([
|
|
1513
|
+
z.object({
|
|
1514
|
+
reasoningText: AmazonBedrockReasoningTextSchema(),
|
|
1515
|
+
}),
|
|
1490
1516
|
z.object({
|
|
1491
|
-
|
|
1517
|
+
redactedReasoning: AmazonBedrockRedactedReasoningSchema(),
|
|
1492
1518
|
}),
|
|
1493
|
-
|
|
1519
|
+
// `redactedContent` is a member of the documented
|
|
1520
|
+
// ReasoningContentBlock union. OpenAI models on Bedrock
|
|
1521
|
+
// (e.g. `us.openai.gpt-5.6-luna`) return their encrypted
|
|
1522
|
+
// reasoning in this shape.
|
|
1523
|
+
z.object({
|
|
1524
|
+
redactedContent: z.string(),
|
|
1525
|
+
}),
|
|
1526
|
+
])
|
|
1494
1527
|
.nullish(),
|
|
1495
|
-
})
|
|
1496
|
-
|
|
1497
|
-
|
|
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(),
|
|
1528
|
+
}),
|
|
1529
|
+
),
|
|
1530
|
+
role: z.string(),
|
|
1515
1531
|
}),
|
|
1516
|
-
),
|
|
1517
|
-
|
|
1532
|
+
}),
|
|
1533
|
+
stopReason: AmazonBedrockStopReasonSchema,
|
|
1534
|
+
additionalModelResponseFields:
|
|
1535
|
+
AmazonBedrockAdditionalModelResponseFieldsSchema.nullish(),
|
|
1536
|
+
trace: z.unknown().nullish(),
|
|
1537
|
+
performanceConfig: z.object({ latency: z.string() }).nullish(),
|
|
1538
|
+
serviceTier: z.object({ type: z.string() }).nullish(),
|
|
1539
|
+
usage: z
|
|
1540
|
+
.object({
|
|
1541
|
+
inputTokens: z.number(),
|
|
1542
|
+
outputTokens: z.number(),
|
|
1543
|
+
totalTokens: z.number(),
|
|
1544
|
+
cacheReadInputTokens: z.number().nullish(),
|
|
1545
|
+
cacheWriteInputTokens: z.number().nullish(),
|
|
1546
|
+
cacheDetails: z.array(AmazonBedrockCacheDetailSchema).nullish(),
|
|
1547
|
+
})
|
|
1548
|
+
.catchall(z.json()),
|
|
1518
1549
|
}),
|
|
1519
|
-
|
|
1520
|
-
|
|
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
|
-
});
|
|
1550
|
+
),
|
|
1551
|
+
);
|
|
1537
1552
|
|
|
1538
1553
|
// limited version of the schema, focussed on what is needed for the implementation
|
|
1539
1554
|
// 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 =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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 =
|
|
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 =
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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 {
|
|
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 =
|
|
5
|
-
|
|
6
|
-
|
|
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({
|