@ai-sdk/amazon-bedrock 5.0.84 → 5.0.86

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 ? "5.0.84" : "0.0.0-test";
38
+ var VERSION = true ? "5.0.86" : "0.0.0-test";
39
39
 
40
40
  // src/amazon-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 ? "5.0.84" : "0.0.0-test";
26
+ var VERSION = true ? "5.0.86" : "0.0.0-test";
27
27
 
28
28
  // src/amazon-bedrock-sigv4-fetch.ts
29
29
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -278,6 +278,42 @@ Anthropic provider, `providerOptions.anthropic.structuredOutputMode` is also
278
278
  honored for Anthropic models on Bedrock. When both are provided, the
279
279
  `amazonBedrock` or legacy `bedrock` value takes precedence.
280
280
 
281
+ For an Anthropic application inference profile, prefer the Bedrock Anthropic
282
+ provider. It uses Bedrock's native InvokeModel API, which accepts application
283
+ inference profile ARNs, and identifies the model as Anthropic automatically:
284
+
285
+ ```ts
286
+ import { amazonBedrockAnthropic } from '@ai-sdk/amazon-bedrock/anthropic';
287
+
288
+ const profileArn =
289
+ 'arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/qibm5eutlkcy';
290
+
291
+ const model = amazonBedrockAnthropic(profileArn);
292
+ ```
293
+
294
+ Use `modelFamily: 'anthropic'` only when you need to use the generic
295
+ `@ai-sdk/amazon-bedrock` provider, which uses Bedrock's Converse API (for
296
+ example, when IAM permits Converse but not InvokeModel). Application inference
297
+ profile ARNs do not identify their underlying model, so declaring the family
298
+ allows Anthropic-specific features, including native structured output:
299
+
300
+ ```ts
301
+ import {
302
+ amazonBedrock,
303
+ type AmazonBedrockChatModelSettings,
304
+ } from '@ai-sdk/amazon-bedrock';
305
+
306
+ const profileArn =
307
+ 'arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/qibm5eutlkcy';
308
+
309
+ const model = amazonBedrock(profileArn, {
310
+ modelFamily: 'anthropic',
311
+ } satisfies AmazonBedrockChatModelSettings);
312
+ ```
313
+
314
+ For an underlying model that does not reliably support native structured
315
+ output, set `structuredOutputMode` to `"jsonTool"`.
316
+
281
317
  ### File Inputs
282
318
 
283
319
  <Note type="warning">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "5.0.84",
3
+ "version": "5.0.86",
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.54",
45
- "@ai-sdk/openai": "4.0.67",
46
- "@ai-sdk/provider": "4.0.15",
47
- "@ai-sdk/provider-utils": "5.0.41",
44
+ "@ai-sdk/anthropic": "4.0.56",
45
+ "@ai-sdk/openai": "4.0.69",
46
+ "@ai-sdk/provider": "4.0.17",
47
+ "@ai-sdk/provider-utils": "5.0.43",
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,22 @@
1
+ import type { AmazonBedrockChatModelSettings } from './amazon-bedrock-chat-language-model-options';
2
+
3
+ export function isAnthropicModel({
4
+ modelId,
5
+ modelFamily,
6
+ reasoningBudgetTokens,
7
+ }: {
8
+ modelId: string;
9
+ modelFamily?: AmazonBedrockChatModelSettings['modelFamily'];
10
+ reasoningBudgetTokens?: number;
11
+ }): boolean {
12
+ return (
13
+ modelFamily === 'anthropic' ||
14
+ modelId.includes('anthropic') ||
15
+ (modelId.includes(':application-inference-profile/') &&
16
+ reasoningBudgetTokens != null)
17
+ );
18
+ }
19
+
1
20
  export function supportsStrictTools(modelId: string): boolean {
2
21
  return !matchesModel(modelId, MODELS_WITHOUT_STRICT_TOOL_SUPPORT);
3
22
  }
@@ -86,6 +86,16 @@ export type AmazonBedrockChatModelId =
86
86
  | 'us.meta.llama4-maverick-17b-instruct-v1:0'
87
87
  | (string & {});
88
88
 
89
+ export type AmazonBedrockChatModelSettings = {
90
+ /**
91
+ * The chat model family.
92
+ *
93
+ * Specify this when the model ID does not identify the underlying model,
94
+ * such as an application inference profile ARN.
95
+ */
96
+ modelFamily?: 'anthropic';
97
+ };
98
+
89
99
  /**
90
100
  * Bedrock file part provider options for document-specific features.
91
101
  * These options apply to individual file parts (documents).
@@ -45,8 +45,10 @@ import {
45
45
  amazonBedrockLanguageModelChatOptions,
46
46
  type AmazonBedrockLanguageModelChatOptions,
47
47
  type AmazonBedrockChatModelId,
48
+ type AmazonBedrockChatModelSettings,
48
49
  } from './amazon-bedrock-chat-language-model-options';
49
50
  import {
51
+ isAnthropicModel as detectAnthropicModel,
50
52
  supportsNativeStructuredOutput,
51
53
  supportsStrictTools,
52
54
  } from './amazon-bedrock-anthropic-model-support';
@@ -71,6 +73,7 @@ type AmazonBedrockChatConfig = {
71
73
  headers?: Resolvable<Record<string, string | undefined>>;
72
74
  fetch?: FetchFunction;
73
75
  generateId: () => string;
76
+ modelFamily?: AmazonBedrockChatModelSettings['modelFamily'];
74
77
  };
75
78
 
76
79
  const anthropicProviderOptions = z.object({
@@ -217,12 +220,11 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
217
220
  });
218
221
  }
219
222
 
220
- // Application inference profile ARNs do not expose their underlying model.
221
- // The Anthropic-only reasoning budget provides the model-family signal.
222
- const isAnthropicModel =
223
- this.modelId.includes('anthropic') ||
224
- (this.modelId.includes(':application-inference-profile/') &&
225
- amazonBedrockOptions.reasoningConfig?.budgetTokens != null);
223
+ const isAnthropicModel = detectAnthropicModel({
224
+ modelId: this.modelId,
225
+ modelFamily: this.config.modelFamily,
226
+ reasoningBudgetTokens: amazonBedrockOptions.reasoningConfig?.budgetTokens,
227
+ });
226
228
  const openAIModelId = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)?.[1];
227
229
  const isOpenAIModel = openAIModelId != null;
228
230
  const isOpenAIGptOssModel =
@@ -278,7 +280,9 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
278
280
 
279
281
  const modelSupportsNativeStructuredOutput =
280
282
  supportsNativeStructuredOutput(this.modelId) &&
281
- (modelSupportsStructuredOutput || isThinkingEnabled);
283
+ (modelSupportsStructuredOutput ||
284
+ isThinkingEnabled ||
285
+ this.config.modelFamily === 'anthropic');
282
286
 
283
287
  const useNativeStructuredOutput =
284
288
  isAnthropicModel &&
@@ -317,6 +321,9 @@ export class AmazonBedrockChatLanguageModel implements LanguageModelV4 {
317
321
  toolChoice:
318
322
  jsonResponseTool != null ? { type: 'required' } : toolChoice,
319
323
  modelId: this.modelId,
324
+ modelFamily: this.config.modelFamily,
325
+ reasoningBudgetTokens:
326
+ amazonBedrockOptions.reasoningConfig?.budgetTokens,
320
327
  disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
321
328
  });
322
329
 
@@ -9,21 +9,29 @@ import {
9
9
  anthropicTools,
10
10
  prepareTools as prepareAnthropicTools,
11
11
  } from '@ai-sdk/anthropic/internal';
12
- import { supportsStrictTools } from './amazon-bedrock-anthropic-model-support';
12
+ import {
13
+ isAnthropicModel as detectAnthropicModel,
14
+ supportsStrictTools,
15
+ } from './amazon-bedrock-anthropic-model-support';
13
16
  import type {
14
17
  AmazonBedrockTool,
15
18
  AmazonBedrockToolConfiguration,
16
19
  } from './amazon-bedrock-api-types';
20
+ import type { AmazonBedrockChatModelSettings } from './amazon-bedrock-chat-language-model-options';
17
21
 
18
22
  export async function prepareTools({
19
23
  tools,
20
24
  toolChoice,
21
25
  modelId,
26
+ modelFamily,
27
+ reasoningBudgetTokens,
22
28
  disableParallelToolUse,
23
29
  }: {
24
30
  tools: LanguageModelV4CallOptions['tools'];
25
31
  toolChoice?: LanguageModelV4CallOptions['toolChoice'];
26
32
  modelId: string;
33
+ modelFamily?: AmazonBedrockChatModelSettings['modelFamily'];
34
+ reasoningBudgetTokens?: number;
27
35
  disableParallelToolUse?: boolean;
28
36
  }): Promise<{
29
37
  toolConfig: AmazonBedrockToolConfiguration;
@@ -43,17 +51,18 @@ export async function prepareTools({
43
51
  };
44
52
  }
45
53
 
46
- // Filter out unsupported web_search tool and add a warning
54
+ // Filter out Anthropic web tools that Amazon Bedrock does not support.
47
55
  const supportedTools = tools.filter(tool => {
48
56
  if (
49
57
  tool.type === 'provider' &&
50
- tool.id === 'anthropic.web_search_20250305'
58
+ (tool.id === 'anthropic.web_search_20250305' ||
59
+ tool.id === 'anthropic.web_search_20260318' ||
60
+ tool.id === 'anthropic.web_fetch_20260318')
51
61
  ) {
52
62
  toolWarnings.push({
53
63
  type: 'unsupported',
54
- feature: 'web_search_20250305 tool',
55
- details:
56
- 'The web_search_20250305 tool is not supported on Amazon Bedrock.',
64
+ feature: `${tool.id.slice('anthropic.'.length)} tool`,
65
+ details: `The ${tool.id.slice('anthropic.'.length)} tool is not supported on Amazon Bedrock.`,
57
66
  });
58
67
  return false; // Exclude this tool
59
68
  }
@@ -69,7 +78,11 @@ export async function prepareTools({
69
78
  };
70
79
  }
71
80
 
72
- const isAnthropicModel = modelId.includes('anthropic.');
81
+ const isAnthropicModel = detectAnthropicModel({
82
+ modelId,
83
+ modelFamily,
84
+ reasoningBudgetTokens,
85
+ });
73
86
  const ProviderTools = supportedTools.filter(t => t.type === 'provider');
74
87
  const functionTools = supportedTools.filter(t => t.type === 'function');
75
88
 
@@ -14,7 +14,10 @@ import {
14
14
  type FetchFunction,
15
15
  } from '@ai-sdk/provider-utils';
16
16
  import { AmazonBedrockChatLanguageModel } from './amazon-bedrock-chat-language-model';
17
- import type { AmazonBedrockChatModelId } from './amazon-bedrock-chat-language-model-options';
17
+ import type {
18
+ AmazonBedrockChatModelId,
19
+ AmazonBedrockChatModelSettings,
20
+ } from './amazon-bedrock-chat-language-model-options';
18
21
  import { AmazonBedrockEmbeddingModel } from './amazon-bedrock-embedding-model';
19
22
  import type {
20
23
  AmazonBedrockEmbeddingModelId,
@@ -115,9 +118,15 @@ export interface AmazonBedrockProviderSettings {
115
118
  }
116
119
 
117
120
  export interface AmazonBedrockProvider extends ProviderV4 {
118
- (modelId: AmazonBedrockChatModelId): LanguageModelV4;
121
+ (
122
+ modelId: AmazonBedrockChatModelId,
123
+ settings?: AmazonBedrockChatModelSettings,
124
+ ): LanguageModelV4;
119
125
 
120
- languageModel(modelId: AmazonBedrockChatModelId): LanguageModelV4;
126
+ languageModel(
127
+ modelId: AmazonBedrockChatModelId,
128
+ settings?: AmazonBedrockChatModelSettings,
129
+ ): LanguageModelV4;
121
130
 
122
131
  /**
123
132
  * Creates a model for text embeddings.
@@ -315,22 +324,29 @@ export function createAmazonBedrock(
315
324
  'AWS_ENDPOINT_URL_BEDROCK_AGENT_RUNTIME',
316
325
  });
317
326
 
318
- const createChatModel = (modelId: AmazonBedrockChatModelId) =>
327
+ const createChatModel = (
328
+ modelId: AmazonBedrockChatModelId,
329
+ settings: AmazonBedrockChatModelSettings = {},
330
+ ) =>
319
331
  new AmazonBedrockChatLanguageModel(modelId, {
320
332
  baseUrl: getAmazonBedrockRuntimeBaseUrl,
321
333
  headers: getHeaders,
322
334
  fetch: fetchFunction,
323
335
  generateId,
336
+ modelFamily: settings.modelFamily,
324
337
  });
325
338
 
326
- const provider = function (modelId: AmazonBedrockChatModelId) {
339
+ const provider = function (
340
+ modelId: AmazonBedrockChatModelId,
341
+ settings?: AmazonBedrockChatModelSettings,
342
+ ) {
327
343
  if (new.target) {
328
344
  throw new Error(
329
345
  'The Amazon Bedrock model function cannot be called with the new keyword.',
330
346
  );
331
347
  }
332
348
 
333
- return createChatModel(modelId);
349
+ return createChatModel(modelId, settings);
334
350
  };
335
351
 
336
352
  const createEmbeddingModel = (
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export type {
6
6
  } from './amazon-bedrock-embedding-model-options';
7
7
  export type { AmazonBedrockImageModelOptions } from './amazon-bedrock-image-model-options';
8
8
  export type {
9
+ AmazonBedrockChatModelSettings,
9
10
  AmazonBedrockLanguageModelChatOptions,
10
11
  /** @deprecated Use `AmazonBedrockLanguageModelChatOptions` instead. */
11
12
  AmazonBedrockLanguageModelChatOptions as AmazonBedrockLanguageModelOptions,