@ai-sdk/amazon-bedrock 4.0.174 → 4.0.176

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.174" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.176" : "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.174" : "0.0.0-test";
26
+ var VERSION = true ? "4.0.176" : "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
 
@@ -1473,6 +1477,9 @@ You can use the following optional settings to customize the Bedrock Anthropic p
1473
1477
 
1474
1478
  Base URL for the Bedrock API calls.
1475
1479
  Useful for custom endpoints or proxy configurations.
1480
+ When omitted, the provider also supports the service-specific
1481
+ `AWS_ENDPOINT_URL_BEDROCK_RUNTIME` environment variable, which takes
1482
+ precedence over the global `AWS_ENDPOINT_URL` environment variable.
1476
1483
 
1477
1484
  - **headers** _Resolvable<Record<string, string | undefined>>_
1478
1485
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.174",
3
+ "version": "4.0.176",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -44,10 +44,10 @@
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.116",
48
- "@ai-sdk/openai": "3.0.111",
49
- "@ai-sdk/provider": "3.0.15",
50
- "@ai-sdk/provider-utils": "4.0.50"
47
+ "@ai-sdk/anthropic": "3.0.118",
48
+ "@ai-sdk/openai": "3.0.112",
49
+ "@ai-sdk/provider": "3.0.16",
50
+ "@ai-sdk/provider-utils": "4.0.51"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "20.17.24",
@@ -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)) ?? {};
@@ -10,7 +10,6 @@ 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';
@@ -30,6 +29,7 @@ import {
30
29
  } from './bedrock-sigv4-fetch';
31
30
  import { BedrockRerankingModel } from './reranking/bedrock-reranking-model';
32
31
  import type { BedrockRerankingModelId } from './reranking/bedrock-reranking-options';
32
+ import { resolveBedrockBaseURL } from './resolve-bedrock-base-url';
33
33
  import { VERSION } from './version';
34
34
 
35
35
  export interface AmazonBedrockProviderSettings {
@@ -85,7 +85,9 @@ export interface AmazonBedrockProviderSettings {
85
85
  sessionToken?: string;
86
86
 
87
87
  /**
88
- * Base URL for the Bedrock API calls.
88
+ * Base URL for the Bedrock API calls. When omitted, the provider uses
89
+ * service-specific AWS endpoint environment variables, then `AWS_ENDPOINT_URL`,
90
+ * before generating an endpoint from the AWS region.
89
91
  */
90
92
  baseURL?: string;
91
93
 
@@ -284,26 +286,34 @@ export function createAmazonBedrock(
284
286
  };
285
287
 
286
288
  const getBedrockRuntimeBaseUrl = (): string =>
287
- withoutTrailingSlash(
288
- options.baseURL ??
289
- `https://bedrock-runtime.${loadSetting({
289
+ resolveBedrockBaseURL({
290
+ baseURL: options.baseURL,
291
+ getRegion: () =>
292
+ loadSetting({
290
293
  settingValue: options.region,
291
294
  settingName: 'region',
292
295
  environmentVariableName: 'AWS_REGION',
293
296
  description: 'AWS region',
294
- })}.amazonaws.com`,
295
- ) ?? `https://bedrock-runtime.us-east-1.amazonaws.com`;
297
+ }),
298
+ service: 'bedrock-runtime',
299
+ serviceEndpointUrlEnvironmentVariableName:
300
+ 'AWS_ENDPOINT_URL_BEDROCK_RUNTIME',
301
+ });
296
302
 
297
303
  const getBedrockAgentRuntimeBaseUrl = (): string =>
298
- withoutTrailingSlash(
299
- options.baseURL ??
300
- `https://bedrock-agent-runtime.${loadSetting({
304
+ resolveBedrockBaseURL({
305
+ baseURL: options.baseURL,
306
+ getRegion: () =>
307
+ loadSetting({
301
308
  settingValue: options.region,
302
309
  settingName: 'region',
303
310
  environmentVariableName: 'AWS_REGION',
304
311
  description: 'AWS region',
305
- })}.amazonaws.com`,
306
- ) ?? `https://bedrock-agent-runtime.us-west-2.amazonaws.com`;
312
+ }),
313
+ service: 'bedrock-agent-runtime',
314
+ serviceEndpointUrlEnvironmentVariableName:
315
+ 'AWS_ENDPOINT_URL_BEDROCK_AGENT_RUNTIME',
316
+ });
307
317
 
308
318
  const createChatModel = (modelId: BedrockChatModelId) =>
309
319
  new BedrockChatLanguageModel(modelId, {
@@ -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
+ }