@ai-sdk/amazon-bedrock 4.0.175 → 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.175" : "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.175" : "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") {
@@ -203,6 +203,10 @@ You can use the following optional settings to customize the Amazon Bedrock prov
203
203
 
204
204
  Optional. Base URL for the Bedrock API calls.
205
205
  Useful for custom endpoints or proxy configurations.
206
+ When omitted, the provider also supports the service-specific
207
+ `AWS_ENDPOINT_URL_BEDROCK_RUNTIME` and
208
+ `AWS_ENDPOINT_URL_BEDROCK_AGENT_RUNTIME` environment variables, which take
209
+ precedence over the global `AWS_ENDPOINT_URL` environment variable.
206
210
 
207
211
  - **headers** _Record<string, string>_
208
212
 
@@ -301,6 +305,42 @@ For parity with the Anthropic provider,
301
305
  `providerOptions.anthropic.structuredOutputMode` is also honored for Anthropic
302
306
  models on Bedrock. When both are provided, the `bedrock` value takes precedence.
303
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
+
304
344
  ### File Inputs
305
345
 
306
346
  <Note type="warning">
@@ -1473,6 +1513,9 @@ You can use the following optional settings to customize the Bedrock Anthropic p
1473
1513
 
1474
1514
  Base URL for the Bedrock API calls.
1475
1515
  Useful for custom endpoints or proxy configurations.
1516
+ When omitted, the provider also supports the service-specific
1517
+ `AWS_ENDPOINT_URL_BEDROCK_RUNTIME` environment variable, which takes
1518
+ precedence over the global `AWS_ENDPOINT_URL` environment variable.
1476
1519
 
1477
1520
  - **headers** _Resolvable&lt;Record&lt;string, string | undefined&gt;&gt;_
1478
1521
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.175",
3
+ "version": "4.0.177",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -44,8 +44,8 @@
44
44
  "@smithy/eventstream-codec": "^4.0.1",
45
45
  "@smithy/util-utf8": "^4.0.0",
46
46
  "aws4fetch": "^1.0.20",
47
- "@ai-sdk/anthropic": "3.0.117",
48
- "@ai-sdk/openai": "3.0.112",
47
+ "@ai-sdk/anthropic": "3.0.118",
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
  },
@@ -7,7 +7,6 @@ import {
7
7
  loadOptionalSetting,
8
8
  loadSetting,
9
9
  resolve,
10
- withoutTrailingSlash,
11
10
  withUserAgentSuffix,
12
11
  type FetchFunction,
13
12
  type Resolvable,
@@ -25,6 +24,7 @@ import {
25
24
  supportsNativeStructuredOutput,
26
25
  supportsStrictTools,
27
26
  } from '../bedrock-anthropic-model-support';
27
+ import { resolveBedrockBaseURL } from '../resolve-bedrock-base-url';
28
28
  import { createBedrockAnthropicFetch } from './bedrock-anthropic-fetch';
29
29
  import type { BedrockAnthropicModelId } from './bedrock-anthropic-options';
30
30
  import { VERSION } from '../version';
@@ -112,7 +112,9 @@ export interface BedrockAnthropicProviderSettings {
112
112
  sessionToken?: string;
113
113
 
114
114
  /**
115
- * Base URL for the Bedrock API calls.
115
+ * Base URL for the Bedrock API calls. When omitted, the provider uses
116
+ * `AWS_ENDPOINT_URL_BEDROCK_RUNTIME`, then `AWS_ENDPOINT_URL`, before
117
+ * generating an endpoint from the AWS region.
116
118
  */
117
119
  baseURL?: string;
118
120
 
@@ -237,15 +239,19 @@ export function createBedrockAnthropic(
237
239
  const fetchFunction = createBedrockAnthropicFetch(baseFetchFunction);
238
240
 
239
241
  const getBaseURL = (): string =>
240
- withoutTrailingSlash(
241
- options.baseURL ??
242
- `https://bedrock-runtime.${loadSetting({
242
+ resolveBedrockBaseURL({
243
+ baseURL: options.baseURL,
244
+ getRegion: () =>
245
+ loadSetting({
243
246
  settingValue: options.region,
244
247
  settingName: 'region',
245
248
  environmentVariableName: 'AWS_REGION',
246
249
  description: 'AWS region',
247
- })}.amazonaws.com`,
248
- ) ?? 'https://bedrock-runtime.us-east-1.amazonaws.com';
250
+ }),
251
+ service: 'bedrock-runtime',
252
+ serviceEndpointUrlEnvironmentVariableName:
253
+ 'AWS_ENDPOINT_URL_BEDROCK_RUNTIME',
254
+ });
249
255
 
250
256
  const getHeaders = async () => {
251
257
  const baseHeaders = (await resolve(options.headers)) ?? {};
@@ -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
 
@@ -10,12 +10,14 @@ import {
10
10
  generateId,
11
11
  loadOptionalSetting,
12
12
  loadSetting,
13
- withoutTrailingSlash,
14
13
  withUserAgentSuffix,
15
14
  type FetchFunction,
16
15
  } from '@ai-sdk/provider-utils';
17
16
  import { BedrockChatLanguageModel } from './bedrock-chat-language-model';
18
- import type { BedrockChatModelId } from './bedrock-chat-options';
17
+ import type {
18
+ AmazonBedrockChatModelSettings,
19
+ BedrockChatModelId,
20
+ } from './bedrock-chat-options';
19
21
  import { BedrockEmbeddingModel } from './bedrock-embedding-model';
20
22
  import type {
21
23
  BedrockEmbeddingModelId,
@@ -30,6 +32,7 @@ import {
30
32
  } from './bedrock-sigv4-fetch';
31
33
  import { BedrockRerankingModel } from './reranking/bedrock-reranking-model';
32
34
  import type { BedrockRerankingModelId } from './reranking/bedrock-reranking-options';
35
+ import { resolveBedrockBaseURL } from './resolve-bedrock-base-url';
33
36
  import { VERSION } from './version';
34
37
 
35
38
  export interface AmazonBedrockProviderSettings {
@@ -85,7 +88,9 @@ export interface AmazonBedrockProviderSettings {
85
88
  sessionToken?: string;
86
89
 
87
90
  /**
88
- * Base URL for the Bedrock API calls.
91
+ * Base URL for the Bedrock API calls. When omitted, the provider uses
92
+ * service-specific AWS endpoint environment variables, then `AWS_ENDPOINT_URL`,
93
+ * before generating an endpoint from the AWS region.
89
94
  */
90
95
  baseURL?: string;
91
96
 
@@ -113,9 +118,15 @@ export interface AmazonBedrockProviderSettings {
113
118
  }
114
119
 
115
120
  export interface AmazonBedrockProvider extends ProviderV3 {
116
- (modelId: BedrockChatModelId): LanguageModelV3;
121
+ (
122
+ modelId: BedrockChatModelId,
123
+ settings?: AmazonBedrockChatModelSettings,
124
+ ): LanguageModelV3;
117
125
 
118
- languageModel(modelId: BedrockChatModelId): LanguageModelV3;
126
+ languageModel(
127
+ modelId: BedrockChatModelId,
128
+ settings?: AmazonBedrockChatModelSettings,
129
+ ): LanguageModelV3;
119
130
 
120
131
  /**
121
132
  * Creates a model for text embeddings.
@@ -284,43 +295,58 @@ export function createAmazonBedrock(
284
295
  };
285
296
 
286
297
  const getBedrockRuntimeBaseUrl = (): string =>
287
- withoutTrailingSlash(
288
- options.baseURL ??
289
- `https://bedrock-runtime.${loadSetting({
298
+ resolveBedrockBaseURL({
299
+ baseURL: options.baseURL,
300
+ getRegion: () =>
301
+ loadSetting({
290
302
  settingValue: options.region,
291
303
  settingName: 'region',
292
304
  environmentVariableName: 'AWS_REGION',
293
305
  description: 'AWS region',
294
- })}.amazonaws.com`,
295
- ) ?? `https://bedrock-runtime.us-east-1.amazonaws.com`;
306
+ }),
307
+ service: 'bedrock-runtime',
308
+ serviceEndpointUrlEnvironmentVariableName:
309
+ 'AWS_ENDPOINT_URL_BEDROCK_RUNTIME',
310
+ });
296
311
 
297
312
  const getBedrockAgentRuntimeBaseUrl = (): string =>
298
- withoutTrailingSlash(
299
- options.baseURL ??
300
- `https://bedrock-agent-runtime.${loadSetting({
313
+ resolveBedrockBaseURL({
314
+ baseURL: options.baseURL,
315
+ getRegion: () =>
316
+ loadSetting({
301
317
  settingValue: options.region,
302
318
  settingName: 'region',
303
319
  environmentVariableName: 'AWS_REGION',
304
320
  description: 'AWS region',
305
- })}.amazonaws.com`,
306
- ) ?? `https://bedrock-agent-runtime.us-west-2.amazonaws.com`;
321
+ }),
322
+ service: 'bedrock-agent-runtime',
323
+ serviceEndpointUrlEnvironmentVariableName:
324
+ 'AWS_ENDPOINT_URL_BEDROCK_AGENT_RUNTIME',
325
+ });
307
326
 
308
- const createChatModel = (modelId: BedrockChatModelId) =>
327
+ const createChatModel = (
328
+ modelId: BedrockChatModelId,
329
+ settings: AmazonBedrockChatModelSettings = {},
330
+ ) =>
309
331
  new BedrockChatLanguageModel(modelId, {
310
332
  baseUrl: getBedrockRuntimeBaseUrl,
311
333
  headers: getHeaders,
312
334
  fetch: fetchFunction,
313
335
  generateId,
336
+ modelFamily: settings.modelFamily,
314
337
  });
315
338
 
316
- const provider = function (modelId: BedrockChatModelId) {
339
+ const provider = function (
340
+ modelId: BedrockChatModelId,
341
+ settings?: AmazonBedrockChatModelSettings,
342
+ ) {
317
343
  if (new.target) {
318
344
  throw new Error(
319
345
  'The Amazon Bedrock model function cannot be called with the new keyword.',
320
346
  );
321
347
  }
322
348
 
323
- return createChatModel(modelId);
349
+ return createChatModel(modelId, settings);
324
350
  };
325
351
 
326
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,
@@ -0,0 +1,51 @@
1
+ import {
2
+ loadOptionalSetting,
3
+ withoutTrailingSlash,
4
+ } from '@ai-sdk/provider-utils';
5
+
6
+ const AWS_PARTITION_DNS_SUFFIXES = [
7
+ { regionPrefix: 'cn-', dnsSuffix: 'amazonaws.com.cn' },
8
+ { regionPrefix: 'us-iso-', dnsSuffix: 'c2s.ic.gov' },
9
+ { regionPrefix: 'us-isob-', dnsSuffix: 'sc2s.sgov.gov' },
10
+ { regionPrefix: 'eu-isoe-', dnsSuffix: 'cloud.adc-e.uk' },
11
+ { regionPrefix: 'us-isof-', dnsSuffix: 'csp.hci.ic.gov' },
12
+ { regionPrefix: 'eusc-', dnsSuffix: 'amazonaws.eu' },
13
+ ] as const;
14
+
15
+ export function resolveBedrockBaseURL({
16
+ baseURL,
17
+ getRegion,
18
+ service,
19
+ serviceEndpointUrlEnvironmentVariableName,
20
+ }: {
21
+ baseURL: string | undefined;
22
+ getRegion: () => string;
23
+ service: 'bedrock-runtime' | 'bedrock-agent-runtime';
24
+ serviceEndpointUrlEnvironmentVariableName:
25
+ | 'AWS_ENDPOINT_URL_BEDROCK_RUNTIME'
26
+ | 'AWS_ENDPOINT_URL_BEDROCK_AGENT_RUNTIME';
27
+ }): string {
28
+ const resolvedBaseURL =
29
+ baseURL ??
30
+ loadOptionalSetting({
31
+ settingValue: undefined,
32
+ environmentVariableName: serviceEndpointUrlEnvironmentVariableName,
33
+ }) ??
34
+ loadOptionalSetting({
35
+ settingValue: undefined,
36
+ environmentVariableName: 'AWS_ENDPOINT_URL',
37
+ });
38
+
39
+ if (resolvedBaseURL != null) {
40
+ return withoutTrailingSlash(resolvedBaseURL) ?? resolvedBaseURL;
41
+ }
42
+
43
+ const region = getRegion();
44
+ const dnsSuffix =
45
+ AWS_PARTITION_DNS_SUFFIXES.find(({ regionPrefix }) =>
46
+ region.startsWith(regionPrefix),
47
+ )?.dnsSuffix ?? 'amazonaws.com';
48
+ const generatedBaseURL = `https://${service}.${region}.${dnsSuffix}`;
49
+
50
+ return withoutTrailingSlash(generatedBaseURL) ?? generatedBaseURL;
51
+ }