@ai-sdk/amazon-bedrock 4.0.176 → 4.0.177

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.176" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.177" : "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.176" : "0.0.0-test";
26
+ var VERSION = true ? "4.0.177" : "0.0.0-test";
27
27
 
28
28
  // src/bedrock-sigv4-fetch.ts
29
29
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -305,6 +305,42 @@ For parity with the Anthropic provider,
305
305
  `providerOptions.anthropic.structuredOutputMode` is also honored for Anthropic
306
306
  models on Bedrock. When both are provided, the `bedrock` value takes precedence.
307
307
 
308
+ For an Anthropic application inference profile, prefer the Bedrock Anthropic
309
+ provider. It uses Bedrock's native InvokeModel API, which accepts application
310
+ inference profile ARNs, and identifies the model as Anthropic automatically:
311
+
312
+ ```ts
313
+ import { bedrockAnthropic } from '@ai-sdk/amazon-bedrock/anthropic';
314
+
315
+ const profileArn =
316
+ 'arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/qibm5eutlkcy';
317
+
318
+ const model = bedrockAnthropic(profileArn);
319
+ ```
320
+
321
+ Use `modelFamily: 'anthropic'` only when you need to use the generic
322
+ `@ai-sdk/amazon-bedrock` provider, which uses Bedrock's Converse API (for
323
+ example, when IAM permits Converse but not InvokeModel). Application inference
324
+ profile ARNs do not identify their underlying model, so declaring the family
325
+ allows Anthropic-specific features, including native structured output:
326
+
327
+ ```ts
328
+ import {
329
+ bedrock,
330
+ type AmazonBedrockChatModelSettings,
331
+ } from '@ai-sdk/amazon-bedrock';
332
+
333
+ const profileArn =
334
+ 'arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/qibm5eutlkcy';
335
+
336
+ const model = bedrock(profileArn, {
337
+ modelFamily: 'anthropic',
338
+ } satisfies AmazonBedrockChatModelSettings);
339
+ ```
340
+
341
+ For an underlying model that does not reliably support native structured
342
+ output, set `structuredOutputMode` to `"jsonTool"`.
343
+
308
344
  ### File Inputs
309
345
 
310
346
  <Note type="warning">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.176",
3
+ "version": "4.0.177",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -45,7 +45,7 @@
45
45
  "@smithy/util-utf8": "^4.0.0",
46
46
  "aws4fetch": "^1.0.20",
47
47
  "@ai-sdk/anthropic": "3.0.118",
48
- "@ai-sdk/openai": "3.0.112",
48
+ "@ai-sdk/openai": "3.0.113",
49
49
  "@ai-sdk/provider": "3.0.16",
50
50
  "@ai-sdk/provider-utils": "4.0.51"
51
51
  },
@@ -1,3 +1,22 @@
1
+ import type { AmazonBedrockChatModelSettings } from './bedrock-chat-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
  }
@@ -37,8 +37,10 @@ import {
37
37
  import {
38
38
  amazonBedrockLanguageModelOptions,
39
39
  type BedrockChatModelId,
40
+ type AmazonBedrockChatModelSettings,
40
41
  } from './bedrock-chat-options';
41
42
  import {
43
+ isAnthropicModel as detectAnthropicModel,
42
44
  supportsNativeStructuredOutput,
43
45
  supportsStrictTools,
44
46
  } from './bedrock-anthropic-model-support';
@@ -59,6 +61,7 @@ type BedrockChatConfig = {
59
61
  headers: Resolvable<Record<string, string | undefined>>;
60
62
  fetch?: FetchFunction;
61
63
  generateId: () => string;
64
+ modelFamily?: AmazonBedrockChatModelSettings['modelFamily'];
62
65
  };
63
66
 
64
67
  function isJsonResponseToolName(name: string): boolean {
@@ -165,12 +168,11 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
165
168
  });
166
169
  }
167
170
 
168
- // Application inference profile ARNs do not expose their underlying model.
169
- // The Anthropic-only reasoning budget provides the model-family signal.
170
- const isAnthropicModel =
171
- this.modelId.includes('anthropic') ||
172
- (this.modelId.includes(':application-inference-profile/') &&
173
- bedrockOptions.reasoningConfig?.budgetTokens != null);
171
+ const isAnthropicModel = detectAnthropicModel({
172
+ modelId: this.modelId,
173
+ modelFamily: this.config.modelFamily,
174
+ reasoningBudgetTokens: bedrockOptions.reasoningConfig?.budgetTokens,
175
+ });
174
176
  const openAIModelId = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)?.[1];
175
177
  const isOpenAIModel = openAIModelId != null;
176
178
  const isOpenAIGptOssModel =
@@ -215,7 +217,9 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
215
217
 
216
218
  const modelSupportsNativeStructuredOutput =
217
219
  supportsNativeStructuredOutput(this.modelId) &&
218
- (modelSupportsStructuredOutput || isThinkingEnabled);
220
+ (modelSupportsStructuredOutput ||
221
+ isThinkingEnabled ||
222
+ this.config.modelFamily === 'anthropic');
219
223
 
220
224
  const useNativeStructuredOutput =
221
225
  isAnthropicModel &&
@@ -254,6 +258,8 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
254
258
  toolChoice:
255
259
  jsonResponseTool != null ? { type: 'required' } : toolChoice,
256
260
  modelId: this.modelId,
261
+ modelFamily: this.config.modelFamily,
262
+ reasoningBudgetTokens: bedrockOptions.reasoningConfig?.budgetTokens,
257
263
  disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
258
264
  });
259
265
 
@@ -83,6 +83,16 @@ export type BedrockChatModelId =
83
83
  | 'us.meta.llama4-maverick-17b-instruct-v1:0'
84
84
  | (string & {});
85
85
 
86
+ export type AmazonBedrockChatModelSettings = {
87
+ /**
88
+ * The chat model family.
89
+ *
90
+ * Specify this when the model ID does not identify the underlying model,
91
+ * such as an application inference profile ARN.
92
+ */
93
+ modelFamily?: 'anthropic';
94
+ };
95
+
86
96
  /**
87
97
  * Bedrock file part provider options for document-specific features.
88
98
  * These options apply to individual file parts (documents).
@@ -9,21 +9,29 @@ import {
9
9
  anthropicTools,
10
10
  prepareTools as prepareAnthropicTools,
11
11
  } from '@ai-sdk/anthropic/internal';
12
- import { supportsStrictTools } from './bedrock-anthropic-model-support';
12
+ import {
13
+ isAnthropicModel as detectAnthropicModel,
14
+ supportsStrictTools,
15
+ } from './bedrock-anthropic-model-support';
13
16
  import type {
14
17
  BedrockTool,
15
18
  BedrockToolConfiguration,
16
19
  } from './bedrock-api-types';
20
+ import type { AmazonBedrockChatModelSettings } from './bedrock-chat-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: LanguageModelV3CallOptions['tools'];
25
31
  toolChoice?: LanguageModelV3CallOptions['toolChoice'];
26
32
  modelId: string;
33
+ modelFamily?: AmazonBedrockChatModelSettings['modelFamily'];
34
+ reasoningBudgetTokens?: number;
27
35
  disableParallelToolUse?: boolean;
28
36
  }): Promise<{
29
37
  toolConfig: BedrockToolConfiguration;
@@ -69,7 +77,11 @@ export async function prepareTools({
69
77
  };
70
78
  }
71
79
 
72
- const isAnthropicModel = modelId.includes('anthropic.');
80
+ const isAnthropicModel = detectAnthropicModel({
81
+ modelId,
82
+ modelFamily,
83
+ reasoningBudgetTokens,
84
+ });
73
85
  const ProviderTools = supportedTools.filter(t => t.type === 'provider');
74
86
  const functionTools = supportedTools.filter(t => t.type === 'function');
75
87
 
@@ -14,7 +14,10 @@ import {
14
14
  type FetchFunction,
15
15
  } from '@ai-sdk/provider-utils';
16
16
  import { BedrockChatLanguageModel } from './bedrock-chat-language-model';
17
- import type { BedrockChatModelId } from './bedrock-chat-options';
17
+ import type {
18
+ AmazonBedrockChatModelSettings,
19
+ BedrockChatModelId,
20
+ } from './bedrock-chat-options';
18
21
  import { BedrockEmbeddingModel } from './bedrock-embedding-model';
19
22
  import type {
20
23
  BedrockEmbeddingModelId,
@@ -115,9 +118,15 @@ export interface AmazonBedrockProviderSettings {
115
118
  }
116
119
 
117
120
  export interface AmazonBedrockProvider extends ProviderV3 {
118
- (modelId: BedrockChatModelId): LanguageModelV3;
121
+ (
122
+ modelId: BedrockChatModelId,
123
+ settings?: AmazonBedrockChatModelSettings,
124
+ ): LanguageModelV3;
119
125
 
120
- languageModel(modelId: BedrockChatModelId): LanguageModelV3;
126
+ languageModel(
127
+ modelId: BedrockChatModelId,
128
+ settings?: AmazonBedrockChatModelSettings,
129
+ ): LanguageModelV3;
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: BedrockChatModelId) =>
327
+ const createChatModel = (
328
+ modelId: BedrockChatModelId,
329
+ settings: AmazonBedrockChatModelSettings = {},
330
+ ) =>
319
331
  new BedrockChatLanguageModel(modelId, {
320
332
  baseUrl: getBedrockRuntimeBaseUrl,
321
333
  headers: getHeaders,
322
334
  fetch: fetchFunction,
323
335
  generateId,
336
+ modelFamily: settings.modelFamily,
324
337
  });
325
338
 
326
- const provider = function (modelId: BedrockChatModelId) {
339
+ const provider = function (
340
+ modelId: BedrockChatModelId,
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
@@ -5,6 +5,7 @@ export type {
5
5
  AmazonBedrockEmbeddingModelSettings,
6
6
  } from './bedrock-embedding-options';
7
7
  export type {
8
+ AmazonBedrockChatModelSettings,
8
9
  AmazonBedrockLanguageModelOptions,
9
10
  /** @deprecated Use `AmazonBedrockLanguageModelOptions` instead. */
10
11
  AmazonBedrockLanguageModelOptions as BedrockProviderOptions,