@ai-sdk/amazon-bedrock 5.0.101 → 5.0.103

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.
@@ -3,11 +3,13 @@ import {
3
3
  OpenAIResponsesLanguageModel,
4
4
  } from '@ai-sdk/openai/internal';
5
5
  import {
6
+ InvalidArgumentError,
6
7
  NoSuchModelError,
7
8
  type LanguageModelV4,
8
9
  type ProviderV4,
9
10
  } from '@ai-sdk/provider';
10
11
  import {
12
+ isValidHostnamePart,
11
13
  loadOptionalSetting,
12
14
  loadSetting,
13
15
  withoutTrailingSlash,
@@ -215,21 +217,33 @@ export function createBedrockMantle(
215
217
  'bedrock-mantle',
216
218
  );
217
219
 
218
- const getBaseURL = (modelId: string): string =>
219
- withoutTrailingSlash(
220
- options.baseURL ??
221
- `https://bedrock-mantle.${loadSetting({
222
- settingValue: options.region,
223
- settingName: 'region',
224
- environmentVariableName: 'AWS_REGION',
225
- description: 'AWS region',
226
- })}.api.aws/${
227
- // Mantle serves these models under its separate OpenAI route.
228
- /^(?:openai\.gpt-(?!oss-)|google\.gemma-4|xai\.)/.test(modelId)
229
- ? 'openai/v1'
230
- : 'v1'
231
- }`,
232
- ) ?? 'https://bedrock-mantle.us-east-1.api.aws/v1';
220
+ const getBaseURL = (modelId: string): string => {
221
+ const baseURL = withoutTrailingSlash(options.baseURL);
222
+ if (baseURL != null) {
223
+ return baseURL;
224
+ }
225
+
226
+ const region = loadSetting({
227
+ settingValue: options.region,
228
+ settingName: 'region',
229
+ environmentVariableName: 'AWS_REGION',
230
+ description: 'AWS region',
231
+ });
232
+ if (!isValidHostnamePart(region)) {
233
+ throw new InvalidArgumentError({
234
+ argument: 'region',
235
+ message:
236
+ 'Invalid AWS region. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints.',
237
+ });
238
+ }
239
+
240
+ return `https://bedrock-mantle.${region}.api.aws/${
241
+ // Mantle serves these models under its separate OpenAI route.
242
+ /^(?:openai\.gpt-(?!oss-)|google\.gemma-4|xai\.)/.test(modelId)
243
+ ? 'openai/v1'
244
+ : 'v1'
245
+ }`;
246
+ };
233
247
 
234
248
  const getHeaders = (): Record<string, string | undefined> =>
235
249
  withUserAgentSuffix(
@@ -1,4 +1,6 @@
1
+ import { InvalidArgumentError } from '@ai-sdk/provider';
1
2
  import {
3
+ isValidHostnamePart,
2
4
  loadOptionalSetting,
3
5
  withoutTrailingSlash,
4
6
  } from '@ai-sdk/provider-utils';
@@ -41,6 +43,13 @@ export function resolveAmazonBedrockBaseURL({
41
43
  }
42
44
 
43
45
  const region = getRegion();
46
+ if (!isValidHostnamePart(region)) {
47
+ throw new InvalidArgumentError({
48
+ argument: 'region',
49
+ message:
50
+ 'Invalid AWS region. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints.',
51
+ });
52
+ }
44
53
  const dnsSuffix =
45
54
  AWS_PARTITION_DNS_SUFFIXES.find(({ regionPrefix }) =>
46
55
  region.startsWith(regionPrefix),