@ai-sdk/amazon-bedrock 4.0.176 → 4.0.178

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.178" : "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.178" : "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.178",
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.114",
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,12 +37,17 @@ 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';
45
- import { BedrockErrorSchema } from './bedrock-error';
47
+ import {
48
+ bedrockFailedResponseHandler,
49
+ BedrockErrorSchema,
50
+ } from './bedrock-error';
46
51
  import { createBedrockEventStreamResponseHandler } from './bedrock-event-stream-response-handler';
47
52
  import { prepareTools } from './bedrock-prepare-tools';
48
53
  import {
@@ -59,6 +64,7 @@ type BedrockChatConfig = {
59
64
  headers: Resolvable<Record<string, string | undefined>>;
60
65
  fetch?: FetchFunction;
61
66
  generateId: () => string;
67
+ modelFamily?: AmazonBedrockChatModelSettings['modelFamily'];
62
68
  };
63
69
 
64
70
  function isJsonResponseToolName(name: string): boolean {
@@ -165,12 +171,11 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
165
171
  });
166
172
  }
167
173
 
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);
174
+ const isAnthropicModel = detectAnthropicModel({
175
+ modelId: this.modelId,
176
+ modelFamily: this.config.modelFamily,
177
+ reasoningBudgetTokens: bedrockOptions.reasoningConfig?.budgetTokens,
178
+ });
174
179
  const openAIModelId = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)?.[1];
175
180
  const isOpenAIModel = openAIModelId != null;
176
181
  const isOpenAIGptOssModel =
@@ -215,7 +220,9 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
215
220
 
216
221
  const modelSupportsNativeStructuredOutput =
217
222
  supportsNativeStructuredOutput(this.modelId) &&
218
- (modelSupportsStructuredOutput || isThinkingEnabled);
223
+ (modelSupportsStructuredOutput ||
224
+ isThinkingEnabled ||
225
+ this.config.modelFamily === 'anthropic');
219
226
 
220
227
  const useNativeStructuredOutput =
221
228
  isAnthropicModel &&
@@ -254,6 +261,8 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
254
261
  toolChoice:
255
262
  jsonResponseTool != null ? { type: 'required' } : toolChoice,
256
263
  modelId: this.modelId,
264
+ modelFamily: this.config.modelFamily,
265
+ reasoningBudgetTokens: bedrockOptions.reasoningConfig?.budgetTokens,
257
266
  disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
258
267
  });
259
268
 
@@ -726,10 +735,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
726
735
  url,
727
736
  headers: await this.getHeaders({ headers: options.headers }),
728
737
  body: args,
729
- failedResponseHandler: createJsonErrorResponseHandler({
730
- errorSchema: BedrockErrorSchema,
731
- errorToMessage: error => `${error.type}: ${error.message}`,
732
- }),
738
+ failedResponseHandler: bedrockFailedResponseHandler,
733
739
  successfulResponseHandler:
734
740
  createBedrockEventStreamResponseHandler(BedrockStreamSchema),
735
741
  abortSignal: options.abortSignal,
@@ -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).
@@ -4,7 +4,6 @@ import {
4
4
  } from '@ai-sdk/provider';
5
5
  import {
6
6
  combineHeaders,
7
- createJsonErrorResponseHandler,
8
7
  createJsonResponseHandler,
9
8
  parseProviderOptions,
10
9
  postJsonToApi,
@@ -17,7 +16,7 @@ import {
17
16
  type BedrockEmbeddingModelId,
18
17
  type AmazonBedrockEmbeddingModelSettings,
19
18
  } from './bedrock-embedding-options';
20
- import { BedrockErrorSchema } from './bedrock-error';
19
+ import { bedrockFailedResponseHandler } from './bedrock-error';
21
20
  import { z } from 'zod/v4';
22
21
 
23
22
  type BedrockEmbeddingConfig = {
@@ -118,10 +117,7 @@ export class BedrockEmbeddingModel implements EmbeddingModelV3 {
118
117
  combineHeaders(await resolve(this.config.headers), headers),
119
118
  ),
120
119
  body: args,
121
- failedResponseHandler: createJsonErrorResponseHandler({
122
- errorSchema: BedrockErrorSchema,
123
- errorToMessage: error => `${error.type}: ${error.message}`,
124
- }),
120
+ failedResponseHandler: bedrockFailedResponseHandler,
125
121
  successfulResponseHandler: createJsonResponseHandler(
126
122
  BedrockEmbeddingResponseSchema,
127
123
  ),
@@ -1,6 +1,13 @@
1
+ import { createJsonErrorResponseHandler } from '@ai-sdk/provider-utils';
1
2
  import { z } from 'zod/v4';
2
3
 
3
4
  export const BedrockErrorSchema = z.object({
4
5
  message: z.string(),
5
6
  type: z.string().nullish(),
6
7
  });
8
+
9
+ export const bedrockFailedResponseHandler = createJsonErrorResponseHandler({
10
+ errorSchema: BedrockErrorSchema,
11
+ errorToMessage: error =>
12
+ error.type == null ? error.message : `${error.type}: ${error.message}`,
13
+ });
@@ -6,7 +6,6 @@ import type {
6
6
  import {
7
7
  combineHeaders,
8
8
  convertUint8ArrayToBase64,
9
- createJsonErrorResponseHandler,
10
9
  createJsonResponseHandler,
11
10
  postJsonToApi,
12
11
  resolve,
@@ -17,7 +16,7 @@ import {
17
16
  modelMaxImagesPerCall,
18
17
  type BedrockImageModelId,
19
18
  } from './bedrock-image-settings';
20
- import { BedrockErrorSchema } from './bedrock-error';
19
+ import { bedrockFailedResponseHandler } from './bedrock-error';
21
20
  import { z } from 'zod/v4';
22
21
 
23
22
  type BedrockImageModelConfig = {
@@ -223,10 +222,7 @@ export class BedrockImageModel implements ImageModelV3 {
223
222
  combineHeaders(await resolve(this.config.headers), headers),
224
223
  ),
225
224
  body: args,
226
- failedResponseHandler: createJsonErrorResponseHandler({
227
- errorSchema: BedrockErrorSchema,
228
- errorToMessage: error => `${error.type}: ${error.message}`,
229
- }),
225
+ failedResponseHandler: bedrockFailedResponseHandler,
230
226
  successfulResponseHandler: createJsonResponseHandler(
231
227
  bedrockImageResponseSchema,
232
228
  ),
@@ -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,
@@ -1,7 +1,6 @@
1
1
  import type { RerankingModelV3 } from '@ai-sdk/provider';
2
2
  import {
3
3
  combineHeaders,
4
- createJsonErrorResponseHandler,
5
4
  createJsonResponseHandler,
6
5
  parseProviderOptions,
7
6
  postJsonToApi,
@@ -9,7 +8,7 @@ import {
9
8
  type FetchFunction,
10
9
  type Resolvable,
11
10
  } from '@ai-sdk/provider-utils';
12
- import { BedrockErrorSchema } from '../bedrock-error';
11
+ import { bedrockFailedResponseHandler } from '../bedrock-error';
13
12
  import {
14
13
  bedrockRerankingResponseSchema,
15
14
  type BedrockRerankingInput,
@@ -93,10 +92,7 @@ export class BedrockRerankingModel implements RerankingModelV3 {
93
92
  },
94
93
  })),
95
94
  } satisfies BedrockRerankingInput,
96
- failedResponseHandler: createJsonErrorResponseHandler({
97
- errorSchema: BedrockErrorSchema,
98
- errorToMessage: error => `${error.type}: ${error.message}`,
99
- }),
95
+ failedResponseHandler: bedrockFailedResponseHandler,
100
96
  successfulResponseHandler: createJsonResponseHandler(
101
97
  bedrockRerankingResponseSchema,
102
98
  ),