@ai-sdk/amazon-bedrock 5.0.70 → 5.0.72
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 +23 -0
- package/dist/anthropic/index.js +14 -8
- package/dist/anthropic/index.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +60 -23
- 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 +46 -0
- package/package.json +5 -5
- package/src/amazon-bedrock-anthropic-model-support.ts +17 -7
- package/src/amazon-bedrock-chat-language-model-options.ts +8 -0
- package/src/amazon-bedrock-chat-language-model.ts +45 -3
package/dist/mantle/index.cjs
CHANGED
|
@@ -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 ? "5.0.
|
|
38
|
+
var VERSION = true ? "5.0.72" : "0.0.0-test";
|
|
39
39
|
|
|
40
40
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
41
41
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
package/dist/mantle/index.js
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import { AwsV4Signer } from "aws4fetch";
|
|
24
24
|
|
|
25
25
|
// src/version.ts
|
|
26
|
-
var VERSION = true ? "5.0.
|
|
26
|
+
var VERSION = true ? "5.0.72" : "0.0.0-test";
|
|
27
27
|
|
|
28
28
|
// src/amazon-bedrock-sigv4-fetch.ts
|
|
29
29
|
function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
|
|
@@ -228,6 +228,52 @@ const { text } = await generateText({
|
|
|
228
228
|
Amazon Bedrock language models can also be used in the `streamText` function
|
|
229
229
|
(see [AI SDK Core](/docs/ai-sdk-core)).
|
|
230
230
|
|
|
231
|
+
### Structured Outputs
|
|
232
|
+
|
|
233
|
+
For Anthropic models, you can use the `structuredOutputMode` provider option to
|
|
234
|
+
choose how Amazon Bedrock generates structured outputs:
|
|
235
|
+
|
|
236
|
+
- `"outputFormat"`: Use Bedrock's native `output_config.format` parameter.
|
|
237
|
+
- `"jsonTool"`: Use a special `json` tool with required tool choice.
|
|
238
|
+
- `"auto"`: Use native structured output when supported and otherwise fall
|
|
239
|
+
back to the JSON tool. This is the default.
|
|
240
|
+
|
|
241
|
+
In `"auto"` mode, Claude Sonnet 4.6 and Claude Haiku 4.5 use the JSON tool
|
|
242
|
+
fallback because native structured output can be unreliable across workloads
|
|
243
|
+
and Bedrock accounts. You can set `"outputFormat"` to opt into native structured
|
|
244
|
+
output when it works for your account and workload, or use `"jsonTool"` to force
|
|
245
|
+
the fallback for any model:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import {
|
|
249
|
+
amazonBedrock,
|
|
250
|
+
type AmazonBedrockLanguageModelChatOptions,
|
|
251
|
+
} from '@ai-sdk/amazon-bedrock';
|
|
252
|
+
import { generateText, Output } from 'ai';
|
|
253
|
+
import { z } from 'zod';
|
|
254
|
+
|
|
255
|
+
const { output } = await generateText({
|
|
256
|
+
model: amazonBedrock('eu.anthropic.claude-sonnet-4-6'),
|
|
257
|
+
output: Output.object({
|
|
258
|
+
schema: z.object({
|
|
259
|
+
summary: z.string(),
|
|
260
|
+
findings: z.array(z.string()),
|
|
261
|
+
}),
|
|
262
|
+
}),
|
|
263
|
+
prompt: 'Summarize the inspection report.',
|
|
264
|
+
providerOptions: {
|
|
265
|
+
amazonBedrock: {
|
|
266
|
+
structuredOutputMode: 'jsonTool',
|
|
267
|
+
} satisfies AmazonBedrockLanguageModelChatOptions,
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
The legacy `providerOptions.bedrock` key remains supported. For parity with the
|
|
273
|
+
Anthropic provider, `providerOptions.anthropic.structuredOutputMode` is also
|
|
274
|
+
honored for Anthropic models on Bedrock. When both are provided, the
|
|
275
|
+
`amazonBedrock` or legacy `bedrock` value takes precedence.
|
|
276
|
+
|
|
231
277
|
### File Inputs
|
|
232
278
|
|
|
233
279
|
<Note type="warning">
|
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.72",
|
|
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.48",
|
|
45
|
+
"@ai-sdk/openai": "4.0.56",
|
|
46
|
+
"@ai-sdk/provider": "4.0.10",
|
|
47
|
+
"@ai-sdk/provider-utils": "5.0.36",
|
|
48
48
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
49
49
|
"@smithy/util-utf8": "^4.3.3",
|
|
50
50
|
"aws4fetch": "^1.0.20"
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export function supportsStrictTools(modelId: string): boolean {
|
|
2
|
-
return !
|
|
2
|
+
return !matchesModel(modelId, MODELS_WITHOUT_STRICT_TOOL_SUPPORT);
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export function supportsNativeStructuredOutput(modelId: string): boolean {
|
|
6
|
-
return !
|
|
6
|
+
return !matchesModel(
|
|
7
|
+
modelId,
|
|
8
|
+
MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT,
|
|
9
|
+
);
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
// Bedrock validates against its own copy of the Messages schema, which rejects
|
|
10
13
|
// `output_config.format` and tool `strict` for the newest Claude models
|
|
11
|
-
const
|
|
14
|
+
const MODELS_WITHOUT_STRICT_TOOL_SUPPORT = [
|
|
12
15
|
'claude-opus-4-7',
|
|
13
16
|
'claude-opus-4-8',
|
|
14
17
|
'claude-opus-5',
|
|
@@ -16,8 +19,15 @@ const MODELS_REJECTING_NEWER_SCHEMA_FIELDS = [
|
|
|
16
19
|
'claude-sonnet-5',
|
|
17
20
|
];
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
// Native structured output is unreliable for additional models even though
|
|
23
|
+
// their strict tool support remains available. Sonnet 4.6 can fail to adhere
|
|
24
|
+
// to complex schemas, while Haiku 4.5 support varies between Bedrock accounts.
|
|
25
|
+
const MODELS_WITHOUT_RELIABLE_NATIVE_STRUCTURED_OUTPUT = [
|
|
26
|
+
...MODELS_WITHOUT_STRICT_TOOL_SUPPORT,
|
|
27
|
+
'claude-sonnet-4-6',
|
|
28
|
+
'claude-haiku-4-5',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
function matchesModel(modelId: string, models: string[]): boolean {
|
|
32
|
+
return models.some(model => modelId.includes(model));
|
|
23
33
|
}
|
|
@@ -134,6 +134,14 @@ export type AmazonBedrockImagePartProviderOptions = z.infer<
|
|
|
134
134
|
>;
|
|
135
135
|
|
|
136
136
|
export const amazonBedrockLanguageModelChatOptions = z.object({
|
|
137
|
+
/**
|
|
138
|
+
* Determines how structured outputs are generated for Anthropic models.
|
|
139
|
+
*
|
|
140
|
+
* - `outputFormat`: Use the native `output_config.format` parameter.
|
|
141
|
+
* - `jsonTool`: Use a special 'json' tool to specify the structured output format.
|
|
142
|
+
* - `auto`: Use `outputFormat` when supported, otherwise use `jsonTool` (default).
|
|
143
|
+
*/
|
|
144
|
+
structuredOutputMode: z.enum(['outputFormat', 'jsonTool', 'auto']).optional(),
|
|
137
145
|
/**
|
|
138
146
|
* Additional inference parameters that the model supports,
|
|
139
147
|
* beyond the base set of inference parameters that Converse
|
|
@@ -75,6 +75,7 @@ type AmazonBedrockChatConfig = {
|
|
|
75
75
|
|
|
76
76
|
const anthropicProviderOptions = z.object({
|
|
77
77
|
disableParallelToolUse: z.boolean().optional(),
|
|
78
|
+
structuredOutputMode: z.enum(['outputFormat', 'jsonTool', 'auto']).optional(),
|
|
78
79
|
});
|
|
79
80
|
|
|
80
81
|
function createAmazonBedrockStreamError({
|
|
@@ -242,14 +243,54 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
|
|
|
242
243
|
const { supportsStructuredOutput: modelSupportsStructuredOutput } =
|
|
243
244
|
getModelCapabilities(this.modelId);
|
|
244
245
|
|
|
246
|
+
const structuredOutputMode =
|
|
247
|
+
amazonBedrockOptions.structuredOutputMode ??
|
|
248
|
+
anthropicOptions?.structuredOutputMode ??
|
|
249
|
+
'auto';
|
|
250
|
+
|
|
251
|
+
if (structuredOutputMode === 'jsonTool') {
|
|
252
|
+
const additionalModelRequestFields = {
|
|
253
|
+
...amazonBedrockOptions.additionalModelRequestFields,
|
|
254
|
+
};
|
|
255
|
+
const outputConfig = additionalModelRequestFields.output_config;
|
|
256
|
+
|
|
257
|
+
if (
|
|
258
|
+
outputConfig != null &&
|
|
259
|
+
typeof outputConfig === 'object' &&
|
|
260
|
+
!Array.isArray(outputConfig)
|
|
261
|
+
) {
|
|
262
|
+
const outputConfigWithoutFormat = { ...outputConfig };
|
|
263
|
+
delete outputConfigWithoutFormat.format;
|
|
264
|
+
|
|
265
|
+
if (Object.keys(outputConfigWithoutFormat).length > 0) {
|
|
266
|
+
additionalModelRequestFields.output_config =
|
|
267
|
+
outputConfigWithoutFormat;
|
|
268
|
+
} else {
|
|
269
|
+
delete additionalModelRequestFields.output_config;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
amazonBedrockOptions = {
|
|
273
|
+
...amazonBedrockOptions,
|
|
274
|
+
additionalModelRequestFields,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const modelSupportsNativeStructuredOutput =
|
|
280
|
+
supportsNativeStructuredOutput(this.modelId) &&
|
|
281
|
+
(modelSupportsStructuredOutput || isThinkingEnabled);
|
|
282
|
+
|
|
245
283
|
const useNativeStructuredOutput =
|
|
246
284
|
isAnthropicModel &&
|
|
247
|
-
supportsNativeStructuredOutput(this.modelId) &&
|
|
248
|
-
(modelSupportsStructuredOutput || isThinkingEnabled) &&
|
|
249
285
|
responseFormat?.type === 'json' &&
|
|
250
|
-
responseFormat.schema != null
|
|
286
|
+
responseFormat.schema != null &&
|
|
287
|
+
(structuredOutputMode === 'outputFormat' ||
|
|
288
|
+
(structuredOutputMode === 'auto' &&
|
|
289
|
+
modelSupportsNativeStructuredOutput));
|
|
251
290
|
|
|
252
291
|
const useJsonInstructionForStructuredOutput =
|
|
292
|
+
!useNativeStructuredOutput &&
|
|
293
|
+
structuredOutputMode !== 'jsonTool' &&
|
|
253
294
|
isAnthropicModel &&
|
|
254
295
|
!supportsStrictTools(this.modelId) &&
|
|
255
296
|
responseFormat?.type === 'json' &&
|
|
@@ -503,6 +544,7 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
|
|
|
503
544
|
reasoningConfig: _,
|
|
504
545
|
additionalModelRequestFields: __,
|
|
505
546
|
serviceTier: ___,
|
|
547
|
+
structuredOutputMode: ____,
|
|
506
548
|
...filteredAmazonBedrockOptions
|
|
507
549
|
} = providerOptions?.amazonBedrock ?? providerOptions?.bedrock ?? {};
|
|
508
550
|
|