@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.
package/dist/index.js CHANGED
@@ -28,10 +28,10 @@ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/bedrock-provider.ts
30
30
  var import_internal3 = require("@ai-sdk/anthropic/internal");
31
- var import_provider_utils12 = require("@ai-sdk/provider-utils");
31
+ var import_provider_utils13 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/bedrock-chat-language-model.ts
34
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
34
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
35
35
  var import_internal2 = require("@ai-sdk/anthropic/internal");
36
36
  var import_v44 = require("zod/v4");
37
37
 
@@ -122,6 +122,13 @@ var amazonBedrockLanguageModelOptions = import_v4.z.object({
122
122
  });
123
123
 
124
124
  // src/bedrock-anthropic-model-support.ts
125
+ function isAnthropicModel({
126
+ modelId,
127
+ modelFamily,
128
+ reasoningBudgetTokens
129
+ }) {
130
+ return modelFamily === "anthropic" || modelId.includes("anthropic") || modelId.includes(":application-inference-profile/") && reasoningBudgetTokens != null;
131
+ }
125
132
  function supportsStrictTools(modelId) {
126
133
  return !matchesModel(modelId, MODELS_WITHOUT_STRICT_TOOL_SUPPORT);
127
134
  }
@@ -148,15 +155,20 @@ function matchesModel(modelId, models) {
148
155
  }
149
156
 
150
157
  // src/bedrock-error.ts
158
+ var import_provider_utils = require("@ai-sdk/provider-utils");
151
159
  var import_v42 = require("zod/v4");
152
160
  var BedrockErrorSchema = import_v42.z.object({
153
161
  message: import_v42.z.string(),
154
162
  type: import_v42.z.string().nullish()
155
163
  });
164
+ var bedrockFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
165
+ errorSchema: BedrockErrorSchema,
166
+ errorToMessage: (error) => error.type == null ? error.message : `${error.type}: ${error.message}`
167
+ });
156
168
 
157
169
  // src/bedrock-event-stream-response-handler.ts
158
170
  var import_provider = require("@ai-sdk/provider");
159
- var import_provider_utils = require("@ai-sdk/provider-utils");
171
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
160
172
 
161
173
  // src/bedrock-event-stream-decoder.ts
162
174
  var import_eventstream_codec = require("@smithy/eventstream-codec");
@@ -208,7 +220,7 @@ function createBedrockEventStreamDecoder(body, processEvent) {
208
220
 
209
221
  // src/bedrock-event-stream-response-handler.ts
210
222
  var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response }) => {
211
- const responseHeaders = (0, import_provider_utils.extractResponseHeaders)(response);
223
+ const responseHeaders = (0, import_provider_utils2.extractResponseHeaders)(response);
212
224
  if (response.body == null) {
213
225
  throw new import_provider.EmptyResponseBodyError({});
214
226
  }
@@ -221,7 +233,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
221
233
  if (payloadType == null) {
222
234
  return;
223
235
  }
224
- const parsedDataResult = await (0, import_provider_utils.safeParseJSON)({ text: event.data });
236
+ const parsedDataResult = await (0, import_provider_utils2.safeParseJSON)({ text: event.data });
225
237
  if (!parsedDataResult.success) {
226
238
  controller.enqueue(parsedDataResult);
227
239
  return;
@@ -230,7 +242,7 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
230
242
  const wrappedData = {
231
243
  [payloadType]: parsedDataResult.value
232
244
  };
233
- const validatedWrappedData = await (0, import_provider_utils.safeValidateTypes)({
245
+ const validatedWrappedData = await (0, import_provider_utils2.safeValidateTypes)({
234
246
  value: wrappedData,
235
247
  schema: chunkSchema
236
248
  });
@@ -250,12 +262,14 @@ var createBedrockEventStreamResponseHandler = (chunkSchema) => async ({ response
250
262
 
251
263
  // src/bedrock-prepare-tools.ts
252
264
  var import_provider2 = require("@ai-sdk/provider");
253
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
265
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
254
266
  var import_internal = require("@ai-sdk/anthropic/internal");
255
267
  async function prepareTools({
256
268
  tools,
257
269
  toolChoice,
258
270
  modelId,
271
+ modelFamily,
272
+ reasoningBudgetTokens,
259
273
  disableParallelToolUse
260
274
  }) {
261
275
  var _a;
@@ -288,12 +302,16 @@ async function prepareTools({
288
302
  toolWarnings
289
303
  };
290
304
  }
291
- const isAnthropicModel = modelId.includes("anthropic.");
305
+ const isAnthropicModel2 = isAnthropicModel({
306
+ modelId,
307
+ modelFamily,
308
+ reasoningBudgetTokens
309
+ });
292
310
  const ProviderTools = supportedTools.filter((t) => t.type === "provider");
293
311
  const functionTools = supportedTools.filter((t) => t.type === "function");
294
312
  let additionalTools = void 0;
295
313
  const bedrockTools = [];
296
- const usingAnthropicTools = isAnthropicModel && ProviderTools.length > 0;
314
+ const usingAnthropicTools = isAnthropicModel2 && ProviderTools.length > 0;
297
315
  if (usingAnthropicTools) {
298
316
  const {
299
317
  toolChoice: preparedAnthropicToolChoice,
@@ -324,7 +342,7 @@ async function prepareTools({
324
342
  toolSpec: {
325
343
  name: tool.name,
326
344
  inputSchema: {
327
- json: await (0, import_provider_utils2.asSchema)(fullToolDefinition.inputSchema).jsonSchema
345
+ json: await (0, import_provider_utils3.asSchema)(fullToolDefinition.inputSchema).jsonSchema
328
346
  }
329
347
  }
330
348
  });
@@ -358,7 +376,7 @@ async function prepareTools({
358
376
  }
359
377
  });
360
378
  }
361
- if (isAnthropicModel && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
379
+ if (isAnthropicModel2 && !usingAnthropicTools && disableParallelToolUse && bedrockTools.length > 0 && (toolChoice == null ? void 0 : toolChoice.type) !== "none") {
362
380
  additionalTools = {
363
381
  tool_choice: (toolChoice == null ? void 0 : toolChoice.type) === "required" ? { type: "any", disable_parallel_tool_use: true } : (toolChoice == null ? void 0 : toolChoice.type) === "tool" ? {
364
382
  type: "tool",
@@ -442,7 +460,7 @@ function convertBedrockUsage(usage) {
442
460
 
443
461
  // src/convert-to-bedrock-chat-messages.ts
444
462
  var import_provider3 = require("@ai-sdk/provider");
445
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
463
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
446
464
 
447
465
  // src/bedrock-reasoning-metadata.ts
448
466
  var import_v43 = require("zod/v4");
@@ -496,7 +514,7 @@ function getBedrockImageSource({
496
514
  }
497
515
  };
498
516
  }
499
- return { bytes: (0, import_provider_utils3.convertToBase64)(data) };
517
+ return { bytes: (0, import_provider_utils4.convertToBase64)(data) };
500
518
  }
501
519
  function getBedrockImageFormatFromUrl(url) {
502
520
  var _a;
@@ -507,7 +525,7 @@ function getBedrockImageFormatFromUrl(url) {
507
525
  }
508
526
  async function shouldEnableCitations(providerMetadata) {
509
527
  var _a, _b;
510
- const bedrockOptions = await (0, import_provider_utils3.parseProviderOptions)({
528
+ const bedrockOptions = await (0, import_provider_utils4.parseProviderOptions)({
511
529
  provider: "bedrock",
512
530
  providerOptions: providerMetadata,
513
531
  schema: bedrockFilePartProviderOptions
@@ -585,8 +603,8 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
585
603
  bedrockContent.push({
586
604
  document: {
587
605
  format: getBedrockDocumentFormat(part.mediaType),
588
- name: part.filename ? (0, import_provider_utils3.stripFileExtension)(part.filename) : generateDocumentName(),
589
- source: { bytes: (0, import_provider_utils3.convertToBase64)(part.data) },
606
+ name: part.filename ? (0, import_provider_utils4.stripFileExtension)(part.filename) : generateDocumentName(),
607
+ source: { bytes: (0, import_provider_utils4.convertToBase64)(part.data) },
590
608
  ...enableCitations && {
591
609
  citations: { enabled: true }
592
610
  }
@@ -621,7 +639,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
621
639
  contentPart.mediaType
622
640
  ),
623
641
  source: {
624
- bytes: (0, import_provider_utils3.convertToBase64)(contentPart.data)
642
+ bytes: (0, import_provider_utils4.convertToBase64)(contentPart.data)
625
643
  }
626
644
  }
627
645
  };
@@ -648,9 +666,9 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
648
666
  format: getBedrockDocumentFormat(
649
667
  contentPart.mediaType
650
668
  ),
651
- name: "filename" in contentPart && contentPart.filename ? (0, import_provider_utils3.stripFileExtension)(contentPart.filename) : generateDocumentName(),
669
+ name: "filename" in contentPart && contentPart.filename ? (0, import_provider_utils4.stripFileExtension)(contentPart.filename) : generateDocumentName(),
652
670
  source: {
653
- bytes: (0, import_provider_utils3.convertToBase64)(contentPart.data)
671
+ bytes: (0, import_provider_utils4.convertToBase64)(contentPart.data)
654
672
  },
655
673
  ...enableCitations && {
656
674
  citations: { enabled: true }
@@ -664,7 +682,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
664
682
  contentPart.mediaType
665
683
  ),
666
684
  source: {
667
- bytes: (0, import_provider_utils3.convertToBase64)(contentPart.data)
685
+ bytes: (0, import_provider_utils4.convertToBase64)(contentPart.data)
668
686
  }
669
687
  }
670
688
  };
@@ -732,7 +750,7 @@ async function convertToBedrockChatMessages(prompt, isMistral = false) {
732
750
  if (part.type !== "reasoning") {
733
751
  return void 0;
734
752
  }
735
- const metadata = await (0, import_provider_utils3.parseProviderOptions)({
753
+ const metadata = await (0, import_provider_utils4.parseProviderOptions)({
736
754
  provider: "bedrock",
737
755
  providerOptions: part.providerOptions,
738
756
  schema: bedrockReasoningMetadataSchema
@@ -959,13 +977,13 @@ var BedrockChatLanguageModel = class {
959
977
  toolChoice,
960
978
  providerOptions
961
979
  }) {
962
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
963
- const bedrockOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
980
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
981
+ const bedrockOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
964
982
  provider: "bedrock",
965
983
  providerOptions,
966
984
  schema: amazonBedrockLanguageModelOptions
967
985
  })) != null ? _a : {};
968
- const anthropicOptions = await (0, import_provider_utils4.parseProviderOptions)({
986
+ const anthropicOptions = await (0, import_provider_utils5.parseProviderOptions)({
969
987
  provider: "anthropic",
970
988
  providerOptions,
971
989
  schema: anthropicProviderOptions
@@ -1011,7 +1029,11 @@ var BedrockChatLanguageModel = class {
1011
1029
  details: "Only text and json response formats are supported."
1012
1030
  });
1013
1031
  }
1014
- const isAnthropicModel = this.modelId.includes("anthropic") || this.modelId.includes(":application-inference-profile/") && ((_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.budgetTokens) != null;
1032
+ const isAnthropicModel2 = isAnthropicModel({
1033
+ modelId: this.modelId,
1034
+ modelFamily: this.config.modelFamily,
1035
+ reasoningBudgetTokens: (_b = bedrockOptions.reasoningConfig) == null ? void 0 : _b.budgetTokens
1036
+ });
1015
1037
  const openAIModelId = (_c = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)) == null ? void 0 : _c[1];
1016
1038
  const isOpenAIModel = openAIModelId != null;
1017
1039
  const isOpenAIGptOssModel = (_d = openAIModelId == null ? void 0 : openAIModelId.startsWith("openai.gpt-oss-")) != null ? _d : false;
@@ -1034,9 +1056,9 @@ var BedrockChatLanguageModel = class {
1034
1056
  bedrockOptions.additionalModelRequestFields = additionalModelRequestFields;
1035
1057
  }
1036
1058
  }
1037
- const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled);
1038
- const useNativeStructuredOutput = isAnthropicModel && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
1039
- const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && structuredOutputMode !== "jsonTool" && isAnthropicModel && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
1059
+ const modelSupportsNativeStructuredOutput = supportsNativeStructuredOutput(this.modelId) && (modelSupportsStructuredOutput || isThinkingEnabled || this.config.modelFamily === "anthropic");
1060
+ const useNativeStructuredOutput = isAnthropicModel2 && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && (structuredOutputMode === "outputFormat" || structuredOutputMode === "auto" && modelSupportsNativeStructuredOutput);
1061
+ const useJsonInstructionForStructuredOutput = !useNativeStructuredOutput && structuredOutputMode !== "jsonTool" && isAnthropicModel2 && !supportsStrictTools(this.modelId) && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && tools != null && tools.length > 0;
1040
1062
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useNativeStructuredOutput && !useJsonInstructionForStructuredOutput ? {
1041
1063
  type: "function",
1042
1064
  name: "json",
@@ -1047,6 +1069,8 @@ var BedrockChatLanguageModel = class {
1047
1069
  tools: jsonResponseTool ? [...tools != null ? tools : [], jsonResponseTool] : tools,
1048
1070
  toolChoice: jsonResponseTool != null ? { type: "required" } : toolChoice,
1049
1071
  modelId: this.modelId,
1072
+ modelFamily: this.config.modelFamily,
1073
+ reasoningBudgetTokens: (_i = bedrockOptions.reasoningConfig) == null ? void 0 : _i.budgetTokens,
1050
1074
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
1051
1075
  });
1052
1076
  warnings.push(...toolWarnings);
@@ -1057,17 +1081,17 @@ var BedrockChatLanguageModel = class {
1057
1081
  };
1058
1082
  }
1059
1083
  if (betas.size > 0 || bedrockOptions.anthropicBeta) {
1060
- const existingBetas = (_i = bedrockOptions.anthropicBeta) != null ? _i : [];
1084
+ const existingBetas = (_j = bedrockOptions.anthropicBeta) != null ? _j : [];
1061
1085
  const mergedBetas = betas.size > 0 ? [...existingBetas, ...Array.from(betas)] : existingBetas;
1062
1086
  bedrockOptions.additionalModelRequestFields = {
1063
1087
  ...bedrockOptions.additionalModelRequestFields,
1064
1088
  anthropic_beta: mergedBetas
1065
1089
  };
1066
1090
  }
1067
- const thinkingType = (_j = bedrockOptions.reasoningConfig) == null ? void 0 : _j.type;
1068
- const thinkingBudget = thinkingType === "enabled" ? (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.budgetTokens : void 0;
1069
- const thinkingDisplay = thinkingType === "adaptive" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.display : void 0;
1070
- const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
1091
+ const thinkingType = (_k = bedrockOptions.reasoningConfig) == null ? void 0 : _k.type;
1092
+ const thinkingBudget = thinkingType === "enabled" ? (_l = bedrockOptions.reasoningConfig) == null ? void 0 : _l.budgetTokens : void 0;
1093
+ const thinkingDisplay = thinkingType === "adaptive" ? (_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.display : void 0;
1094
+ const isAnthropicThinkingEnabled = isAnthropicModel2 && isThinkingEnabled;
1071
1095
  const inferenceConfig = {
1072
1096
  ...maxOutputTokens != null && { maxTokens: maxOutputTokens },
1073
1097
  ...temperature != null && { temperature },
@@ -1098,8 +1122,8 @@ var BedrockChatLanguageModel = class {
1098
1122
  }
1099
1123
  };
1100
1124
  }
1101
- } else if (!isAnthropicModel) {
1102
- if (((_m = bedrockOptions.reasoningConfig) == null ? void 0 : _m.budgetTokens) != null) {
1125
+ } else if (!isAnthropicModel2) {
1126
+ if (((_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.budgetTokens) != null) {
1103
1127
  warnings.push({
1104
1128
  type: "unsupported",
1105
1129
  feature: "budgetTokens",
@@ -1114,13 +1138,13 @@ var BedrockChatLanguageModel = class {
1114
1138
  });
1115
1139
  }
1116
1140
  }
1117
- const maxReasoningEffort = (_n = bedrockOptions.reasoningConfig) == null ? void 0 : _n.maxReasoningEffort;
1141
+ const maxReasoningEffort = (_o = bedrockOptions.reasoningConfig) == null ? void 0 : _o.maxReasoningEffort;
1118
1142
  if (maxReasoningEffort != null) {
1119
- if (isAnthropicModel) {
1143
+ if (isAnthropicModel2) {
1120
1144
  bedrockOptions.additionalModelRequestFields = {
1121
1145
  ...bedrockOptions.additionalModelRequestFields,
1122
1146
  output_config: {
1123
- ...(_o = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _o.output_config,
1147
+ ...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.output_config,
1124
1148
  effort: maxReasoningEffort
1125
1149
  }
1126
1150
  };
@@ -1131,7 +1155,7 @@ var BedrockChatLanguageModel = class {
1131
1155
  } : {
1132
1156
  ...bedrockOptions.additionalModelRequestFields,
1133
1157
  reasoning: {
1134
- ...(_p = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _p.reasoning,
1158
+ ...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.reasoning,
1135
1159
  effort: maxReasoningEffort
1136
1160
  }
1137
1161
  };
@@ -1150,7 +1174,7 @@ var BedrockChatLanguageModel = class {
1150
1174
  bedrockOptions.additionalModelRequestFields = {
1151
1175
  ...bedrockOptions.additionalModelRequestFields,
1152
1176
  output_config: {
1153
- ...(_q = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _q.output_config,
1177
+ ...(_r = bedrockOptions.additionalModelRequestFields) == null ? void 0 : _r.output_config,
1154
1178
  format: {
1155
1179
  type: "json_schema",
1156
1180
  schema: (0, import_internal2.sanitizeJsonSchema)(responseFormat.schema)
@@ -1182,7 +1206,7 @@ var BedrockChatLanguageModel = class {
1182
1206
  details: "topK is not supported when thinking is enabled"
1183
1207
  });
1184
1208
  }
1185
- const hasAnyTools = ((_s = (_r = toolConfig.tools) == null ? void 0 : _r.length) != null ? _s : 0) > 0 || additionalTools;
1209
+ const hasAnyTools = ((_t = (_s = toolConfig.tools) == null ? void 0 : _s.length) != null ? _t : 0) > 0 || additionalTools;
1186
1210
  let filteredPrompt = prompt;
1187
1211
  if (!hasAnyTools) {
1188
1212
  const hasToolContent = prompt.some(
@@ -1209,7 +1233,7 @@ var BedrockChatLanguageModel = class {
1209
1233
  }
1210
1234
  }
1211
1235
  if (useJsonInstructionForStructuredOutput) {
1212
- filteredPrompt = (0, import_provider_utils4.injectJsonInstructionIntoMessages)({
1236
+ filteredPrompt = (0, import_provider_utils5.injectJsonInstructionIntoMessages)({
1213
1237
  messages: filteredPrompt,
1214
1238
  schema: responseFormat.schema,
1215
1239
  schemaSuffix: "You MUST answer with only a JSON object that matches the JSON schema above. Do not wrap it in markdown fences or include any other text."
@@ -1227,7 +1251,7 @@ var BedrockChatLanguageModel = class {
1227
1251
  structuredOutputMode: ____,
1228
1252
  ...filteredBedrockOptions
1229
1253
  } = (providerOptions == null ? void 0 : providerOptions.bedrock) || {};
1230
- const additionalModelResponseFieldPaths = isAnthropicModel ? ["/delta/stop_sequence"] : void 0;
1254
+ const additionalModelResponseFieldPaths = isAnthropicModel2 ? ["/delta/stop_sequence"] : void 0;
1231
1255
  return {
1232
1256
  command: {
1233
1257
  system,
@@ -1256,7 +1280,7 @@ var BedrockChatLanguageModel = class {
1256
1280
  async getHeaders({
1257
1281
  headers
1258
1282
  }) {
1259
- return (0, import_provider_utils4.combineHeaders)(await (0, import_provider_utils4.resolve)(this.config.headers), headers);
1283
+ return (0, import_provider_utils5.combineHeaders)(await (0, import_provider_utils5.resolve)(this.config.headers), headers);
1260
1284
  }
1261
1285
  async doGenerate(options) {
1262
1286
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
@@ -1267,18 +1291,18 @@ var BedrockChatLanguageModel = class {
1267
1291
  usesJsonResponseTool
1268
1292
  } = await this.getArgs(options);
1269
1293
  const url = `${this.getUrl(this.modelId)}/converse`;
1270
- const { value: response, responseHeaders } = await (0, import_provider_utils4.postJsonToApi)({
1294
+ const { value: response, responseHeaders } = await (0, import_provider_utils5.postJsonToApi)({
1271
1295
  url,
1272
1296
  headers: await this.getHeaders({ headers: options.headers }),
1273
1297
  body: args,
1274
- failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
1298
+ failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)({
1275
1299
  errorSchema: BedrockErrorSchema,
1276
1300
  errorToMessage: (error) => {
1277
1301
  var _a2;
1278
1302
  return `${(_a2 = error.message) != null ? _a2 : "Unknown error"}`;
1279
1303
  }
1280
1304
  }),
1281
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
1305
+ successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
1282
1306
  BedrockResponseSchema
1283
1307
  ),
1284
1308
  abortSignal: options.abortSignal,
@@ -1407,14 +1431,11 @@ var BedrockChatLanguageModel = class {
1407
1431
  const modelId = this.modelId;
1408
1432
  const isMistral = isMistralModel(modelId);
1409
1433
  const url = `${this.getUrl(modelId)}/converse-stream`;
1410
- const { value: response, responseHeaders } = await (0, import_provider_utils4.postJsonToApi)({
1434
+ const { value: response, responseHeaders } = await (0, import_provider_utils5.postJsonToApi)({
1411
1435
  url,
1412
1436
  headers: await this.getHeaders({ headers: options.headers }),
1413
1437
  body: args,
1414
- failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
1415
- errorSchema: BedrockErrorSchema,
1416
- errorToMessage: (error) => `${error.type}: ${error.message}`
1417
- }),
1438
+ failedResponseHandler: bedrockFailedResponseHandler,
1418
1439
  successfulResponseHandler: createBedrockEventStreamResponseHandler(BedrockStreamSchema),
1419
1440
  abortSignal: options.abortSignal,
1420
1441
  fetch: this.config.fetch
@@ -1933,7 +1954,7 @@ var BedrockStreamSchema = import_v44.z.object({
1933
1954
 
1934
1955
  // src/bedrock-embedding-model.ts
1935
1956
  var import_provider4 = require("@ai-sdk/provider");
1936
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1957
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
1937
1958
 
1938
1959
  // src/bedrock-embedding-options.ts
1939
1960
  var import_v45 = require("zod/v4");
@@ -2023,7 +2044,7 @@ var BedrockEmbeddingModel = class {
2023
2044
  values
2024
2045
  });
2025
2046
  }
2026
- const bedrockOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
2047
+ const bedrockOptions = (_a = await (0, import_provider_utils6.parseProviderOptions)({
2027
2048
  provider: "bedrock",
2028
2049
  providerOptions,
2029
2050
  schema: amazonBedrockEmbeddingModelOptionsSchema
@@ -2052,17 +2073,14 @@ var BedrockEmbeddingModel = class {
2052
2073
  normalize: bedrockOptions.normalize
2053
2074
  };
2054
2075
  const url = this.getUrl(this.modelId);
2055
- const { value: response, responseHeaders } = await (0, import_provider_utils5.postJsonToApi)({
2076
+ const { value: response, responseHeaders } = await (0, import_provider_utils6.postJsonToApi)({
2056
2077
  url,
2057
- headers: await (0, import_provider_utils5.resolve)(
2058
- (0, import_provider_utils5.combineHeaders)(await (0, import_provider_utils5.resolve)(this.config.headers), headers)
2078
+ headers: await (0, import_provider_utils6.resolve)(
2079
+ (0, import_provider_utils6.combineHeaders)(await (0, import_provider_utils6.resolve)(this.config.headers), headers)
2059
2080
  ),
2060
2081
  body: args,
2061
- failedResponseHandler: (0, import_provider_utils5.createJsonErrorResponseHandler)({
2062
- errorSchema: BedrockErrorSchema,
2063
- errorToMessage: (error) => `${error.type}: ${error.message}`
2064
- }),
2065
- successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
2082
+ failedResponseHandler: bedrockFailedResponseHandler,
2083
+ successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
2066
2084
  BedrockEmbeddingResponseSchema
2067
2085
  ),
2068
2086
  fetch: this.config.fetch,
@@ -2130,7 +2148,7 @@ var BedrockEmbeddingResponseSchema = import_v46.z.union([
2130
2148
  ]);
2131
2149
 
2132
2150
  // src/bedrock-image-model.ts
2133
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
2151
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
2134
2152
 
2135
2153
  // src/bedrock-image-settings.ts
2136
2154
  var modelMaxImagesPerCall = {
@@ -2274,17 +2292,14 @@ var BedrockImageModel = class {
2274
2292
  });
2275
2293
  }
2276
2294
  const currentDate = (_o = (_n = (_m = this.config._internal) == null ? void 0 : _m.currentDate) == null ? void 0 : _n.call(_m)) != null ? _o : /* @__PURE__ */ new Date();
2277
- const { value: response, responseHeaders } = await (0, import_provider_utils6.postJsonToApi)({
2295
+ const { value: response, responseHeaders } = await (0, import_provider_utils7.postJsonToApi)({
2278
2296
  url: this.getUrl(this.modelId),
2279
- headers: await (0, import_provider_utils6.resolve)(
2280
- (0, import_provider_utils6.combineHeaders)(await (0, import_provider_utils6.resolve)(this.config.headers), headers)
2297
+ headers: await (0, import_provider_utils7.resolve)(
2298
+ (0, import_provider_utils7.combineHeaders)(await (0, import_provider_utils7.resolve)(this.config.headers), headers)
2281
2299
  ),
2282
2300
  body: args,
2283
- failedResponseHandler: (0, import_provider_utils6.createJsonErrorResponseHandler)({
2284
- errorSchema: BedrockErrorSchema,
2285
- errorToMessage: (error) => `${error.type}: ${error.message}`
2286
- }),
2287
- successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
2301
+ failedResponseHandler: bedrockFailedResponseHandler,
2302
+ successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
2288
2303
  bedrockImageResponseSchema
2289
2304
  ),
2290
2305
  abortSignal,
@@ -2320,7 +2335,7 @@ function getBase64Data(file) {
2320
2335
  );
2321
2336
  }
2322
2337
  if (file.data instanceof Uint8Array) {
2323
- return (0, import_provider_utils6.convertUint8ArrayToBase64)(file.data);
2338
+ return (0, import_provider_utils7.convertUint8ArrayToBase64)(file.data);
2324
2339
  }
2325
2340
  return file.data;
2326
2341
  }
@@ -2337,11 +2352,11 @@ var bedrockImageResponseSchema = import_v47.z.object({
2337
2352
  });
2338
2353
 
2339
2354
  // src/bedrock-sigv4-fetch.ts
2340
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
2355
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
2341
2356
  var import_aws4fetch = require("aws4fetch");
2342
2357
 
2343
2358
  // src/version.ts
2344
- var VERSION = true ? "4.0.176" : "0.0.0-test";
2359
+ var VERSION = true ? "4.0.178" : "0.0.0-test";
2345
2360
 
2346
2361
  // src/bedrock-sigv4-fetch.ts
2347
2362
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
@@ -2349,14 +2364,14 @@ function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
2349
2364
  var _a, _b;
2350
2365
  const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
2351
2366
  const request = input instanceof Request ? input : void 0;
2352
- const originalHeaders = (0, import_provider_utils7.combineHeaders)(
2353
- (0, import_provider_utils7.normalizeHeaders)(request == null ? void 0 : request.headers),
2354
- (0, import_provider_utils7.normalizeHeaders)(init == null ? void 0 : init.headers)
2367
+ const originalHeaders = (0, import_provider_utils8.combineHeaders)(
2368
+ (0, import_provider_utils8.normalizeHeaders)(request == null ? void 0 : request.headers),
2369
+ (0, import_provider_utils8.normalizeHeaders)(init == null ? void 0 : init.headers)
2355
2370
  );
2356
- const headersWithUserAgent = (0, import_provider_utils7.withUserAgentSuffix)(
2371
+ const headersWithUserAgent = (0, import_provider_utils8.withUserAgentSuffix)(
2357
2372
  originalHeaders,
2358
2373
  `ai-sdk/amazon-bedrock/${VERSION}`,
2359
- (0, import_provider_utils7.getRuntimeEnvironmentUserAgent)()
2374
+ (0, import_provider_utils8.getRuntimeEnvironmentUserAgent)()
2360
2375
  );
2361
2376
  let effectiveBody = (_a = init == null ? void 0 : init.body) != null ? _a : void 0;
2362
2377
  if (effectiveBody === void 0 && request && request.body !== null) {
@@ -2387,8 +2402,8 @@ function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
2387
2402
  service
2388
2403
  });
2389
2404
  const signingResult = await signer.sign();
2390
- const signedHeaders = (0, import_provider_utils7.normalizeHeaders)(signingResult.headers);
2391
- const combinedHeaders = (0, import_provider_utils7.combineHeaders)(headersWithUserAgent, signedHeaders);
2405
+ const signedHeaders = (0, import_provider_utils8.normalizeHeaders)(signingResult.headers);
2406
+ const combinedHeaders = (0, import_provider_utils8.combineHeaders)(headersWithUserAgent, signedHeaders);
2392
2407
  return effectiveFetch(input, {
2393
2408
  ...init,
2394
2409
  body,
@@ -2410,13 +2425,13 @@ function prepareBodyString(body) {
2410
2425
  function createApiKeyFetchFunction(apiKey, fetch) {
2411
2426
  return async (input, init) => {
2412
2427
  const effectiveFetch = fetch != null ? fetch : globalThis.fetch;
2413
- const originalHeaders = (0, import_provider_utils7.normalizeHeaders)(init == null ? void 0 : init.headers);
2414
- const headersWithUserAgent = (0, import_provider_utils7.withUserAgentSuffix)(
2428
+ const originalHeaders = (0, import_provider_utils8.normalizeHeaders)(init == null ? void 0 : init.headers);
2429
+ const headersWithUserAgent = (0, import_provider_utils8.withUserAgentSuffix)(
2415
2430
  originalHeaders,
2416
2431
  `ai-sdk/amazon-bedrock/${VERSION}`,
2417
- (0, import_provider_utils7.getRuntimeEnvironmentUserAgent)()
2432
+ (0, import_provider_utils8.getRuntimeEnvironmentUserAgent)()
2418
2433
  );
2419
- const finalHeaders = (0, import_provider_utils7.combineHeaders)(headersWithUserAgent, {
2434
+ const finalHeaders = (0, import_provider_utils8.combineHeaders)(headersWithUserAgent, {
2420
2435
  Authorization: `Bearer ${apiKey}`
2421
2436
  });
2422
2437
  return effectiveFetch(input, {
@@ -2427,13 +2442,13 @@ function createApiKeyFetchFunction(apiKey, fetch) {
2427
2442
  }
2428
2443
 
2429
2444
  // src/reranking/bedrock-reranking-model.ts
2430
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
2445
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
2431
2446
 
2432
2447
  // src/reranking/bedrock-reranking-api.ts
2433
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
2448
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
2434
2449
  var import_v48 = require("zod/v4");
2435
- var bedrockRerankingResponseSchema = (0, import_provider_utils8.lazySchema)(
2436
- () => (0, import_provider_utils8.zodSchema)(
2450
+ var bedrockRerankingResponseSchema = (0, import_provider_utils9.lazySchema)(
2451
+ () => (0, import_provider_utils9.zodSchema)(
2437
2452
  import_v48.z.object({
2438
2453
  results: import_v48.z.array(
2439
2454
  import_v48.z.object({
@@ -2447,10 +2462,10 @@ var bedrockRerankingResponseSchema = (0, import_provider_utils8.lazySchema)(
2447
2462
  );
2448
2463
 
2449
2464
  // src/reranking/bedrock-reranking-options.ts
2450
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
2465
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
2451
2466
  var import_v49 = require("zod/v4");
2452
- var amazonBedrockRerankingModelOptionsSchema = (0, import_provider_utils9.lazySchema)(
2453
- () => (0, import_provider_utils9.zodSchema)(
2467
+ var amazonBedrockRerankingModelOptionsSchema = (0, import_provider_utils10.lazySchema)(
2468
+ () => (0, import_provider_utils10.zodSchema)(
2454
2469
  import_v49.z.object({
2455
2470
  /**
2456
2471
  * If the total number of results was greater than could fit in a response, a token is returned in the nextToken field. You can enter that token in this field to return the next batch of results.
@@ -2480,7 +2495,7 @@ var BedrockRerankingModel = class {
2480
2495
  abortSignal,
2481
2496
  providerOptions
2482
2497
  }) {
2483
- const bedrockOptions = await (0, import_provider_utils10.parseProviderOptions)({
2498
+ const bedrockOptions = await (0, import_provider_utils11.parseProviderOptions)({
2484
2499
  provider: "bedrock",
2485
2500
  providerOptions,
2486
2501
  schema: amazonBedrockRerankingModelOptionsSchema
@@ -2489,10 +2504,10 @@ var BedrockRerankingModel = class {
2489
2504
  value: response,
2490
2505
  responseHeaders,
2491
2506
  rawValue
2492
- } = await (0, import_provider_utils10.postJsonToApi)({
2507
+ } = await (0, import_provider_utils11.postJsonToApi)({
2493
2508
  url: `${this.config.baseUrl()}/rerank`,
2494
- headers: await (0, import_provider_utils10.resolve)(
2495
- (0, import_provider_utils10.combineHeaders)(await (0, import_provider_utils10.resolve)(this.config.headers), headers)
2509
+ headers: await (0, import_provider_utils11.resolve)(
2510
+ (0, import_provider_utils11.combineHeaders)(await (0, import_provider_utils11.resolve)(this.config.headers), headers)
2496
2511
  ),
2497
2512
  body: {
2498
2513
  nextToken: bedrockOptions == null ? void 0 : bedrockOptions.nextToken,
@@ -2523,11 +2538,8 @@ var BedrockRerankingModel = class {
2523
2538
  }
2524
2539
  }))
2525
2540
  },
2526
- failedResponseHandler: (0, import_provider_utils10.createJsonErrorResponseHandler)({
2527
- errorSchema: BedrockErrorSchema,
2528
- errorToMessage: (error) => `${error.type}: ${error.message}`
2529
- }),
2530
- successfulResponseHandler: (0, import_provider_utils10.createJsonResponseHandler)(
2541
+ failedResponseHandler: bedrockFailedResponseHandler,
2542
+ successfulResponseHandler: (0, import_provider_utils11.createJsonResponseHandler)(
2531
2543
  bedrockRerankingResponseSchema
2532
2544
  ),
2533
2545
  fetch: this.config.fetch,
@@ -2544,7 +2556,7 @@ var BedrockRerankingModel = class {
2544
2556
  };
2545
2557
 
2546
2558
  // src/resolve-bedrock-base-url.ts
2547
- var import_provider_utils11 = require("@ai-sdk/provider-utils");
2559
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
2548
2560
  var AWS_PARTITION_DNS_SUFFIXES = [
2549
2561
  { regionPrefix: "cn-", dnsSuffix: "amazonaws.com.cn" },
2550
2562
  { regionPrefix: "us-iso-", dnsSuffix: "c2s.ic.gov" },
@@ -2560,33 +2572,33 @@ function resolveBedrockBaseURL({
2560
2572
  serviceEndpointUrlEnvironmentVariableName
2561
2573
  }) {
2562
2574
  var _a, _b, _c, _d, _e;
2563
- const resolvedBaseURL = (_a = baseURL != null ? baseURL : (0, import_provider_utils11.loadOptionalSetting)({
2575
+ const resolvedBaseURL = (_a = baseURL != null ? baseURL : (0, import_provider_utils12.loadOptionalSetting)({
2564
2576
  settingValue: void 0,
2565
2577
  environmentVariableName: serviceEndpointUrlEnvironmentVariableName
2566
- })) != null ? _a : (0, import_provider_utils11.loadOptionalSetting)({
2578
+ })) != null ? _a : (0, import_provider_utils12.loadOptionalSetting)({
2567
2579
  settingValue: void 0,
2568
2580
  environmentVariableName: "AWS_ENDPOINT_URL"
2569
2581
  });
2570
2582
  if (resolvedBaseURL != null) {
2571
- return (_b = (0, import_provider_utils11.withoutTrailingSlash)(resolvedBaseURL)) != null ? _b : resolvedBaseURL;
2583
+ return (_b = (0, import_provider_utils12.withoutTrailingSlash)(resolvedBaseURL)) != null ? _b : resolvedBaseURL;
2572
2584
  }
2573
2585
  const region = getRegion();
2574
2586
  const dnsSuffix = (_d = (_c = AWS_PARTITION_DNS_SUFFIXES.find(
2575
2587
  ({ regionPrefix }) => region.startsWith(regionPrefix)
2576
2588
  )) == null ? void 0 : _c.dnsSuffix) != null ? _d : "amazonaws.com";
2577
2589
  const generatedBaseURL = `https://${service}.${region}.${dnsSuffix}`;
2578
- return (_e = (0, import_provider_utils11.withoutTrailingSlash)(generatedBaseURL)) != null ? _e : generatedBaseURL;
2590
+ return (_e = (0, import_provider_utils12.withoutTrailingSlash)(generatedBaseURL)) != null ? _e : generatedBaseURL;
2579
2591
  }
2580
2592
 
2581
2593
  // src/bedrock-provider.ts
2582
2594
  function createAmazonBedrock(options = {}) {
2583
- const rawApiKey = (0, import_provider_utils12.loadOptionalSetting)({
2595
+ const rawApiKey = (0, import_provider_utils13.loadOptionalSetting)({
2584
2596
  settingValue: options.apiKey,
2585
2597
  environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
2586
2598
  });
2587
2599
  const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
2588
2600
  const fetchFunction = apiKey ? createApiKeyFetchFunction(apiKey, options.fetch) : createSigV4FetchFunction(async () => {
2589
- const region = (0, import_provider_utils12.loadSetting)({
2601
+ const region = (0, import_provider_utils13.loadSetting)({
2590
2602
  settingValue: options.region,
2591
2603
  settingName: "region",
2592
2604
  environmentVariableName: "AWS_REGION",
@@ -2608,19 +2620,19 @@ function createAmazonBedrock(options = {}) {
2608
2620
  try {
2609
2621
  return {
2610
2622
  region,
2611
- accessKeyId: (0, import_provider_utils12.loadSetting)({
2623
+ accessKeyId: (0, import_provider_utils13.loadSetting)({
2612
2624
  settingValue: options.accessKeyId,
2613
2625
  settingName: "accessKeyId",
2614
2626
  environmentVariableName: "AWS_ACCESS_KEY_ID",
2615
2627
  description: "AWS access key ID"
2616
2628
  }),
2617
- secretAccessKey: (0, import_provider_utils12.loadSetting)({
2629
+ secretAccessKey: (0, import_provider_utils13.loadSetting)({
2618
2630
  settingValue: options.secretAccessKey,
2619
2631
  settingName: "secretAccessKey",
2620
2632
  environmentVariableName: "AWS_SECRET_ACCESS_KEY",
2621
2633
  description: "AWS secret access key"
2622
2634
  }),
2623
- sessionToken: options.accessKeyId != null && options.secretAccessKey != null ? options.sessionToken : (0, import_provider_utils12.loadOptionalSetting)({
2635
+ sessionToken: options.accessKeyId != null && options.secretAccessKey != null ? options.sessionToken : (0, import_provider_utils13.loadOptionalSetting)({
2624
2636
  settingValue: options.sessionToken,
2625
2637
  environmentVariableName: "AWS_SESSION_TOKEN"
2626
2638
  })
@@ -2649,11 +2661,11 @@ Original error: ${errorMessage}`
2649
2661
  const getHeaders = () => {
2650
2662
  var _a;
2651
2663
  const baseHeaders = (_a = options.headers) != null ? _a : {};
2652
- return (0, import_provider_utils12.withUserAgentSuffix)(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
2664
+ return (0, import_provider_utils13.withUserAgentSuffix)(baseHeaders, `ai-sdk/amazon-bedrock/${VERSION}`);
2653
2665
  };
2654
2666
  const getBedrockRuntimeBaseUrl = () => resolveBedrockBaseURL({
2655
2667
  baseURL: options.baseURL,
2656
- getRegion: () => (0, import_provider_utils12.loadSetting)({
2668
+ getRegion: () => (0, import_provider_utils13.loadSetting)({
2657
2669
  settingValue: options.region,
2658
2670
  settingName: "region",
2659
2671
  environmentVariableName: "AWS_REGION",
@@ -2664,7 +2676,7 @@ Original error: ${errorMessage}`
2664
2676
  });
2665
2677
  const getBedrockAgentRuntimeBaseUrl = () => resolveBedrockBaseURL({
2666
2678
  baseURL: options.baseURL,
2667
- getRegion: () => (0, import_provider_utils12.loadSetting)({
2679
+ getRegion: () => (0, import_provider_utils13.loadSetting)({
2668
2680
  settingValue: options.region,
2669
2681
  settingName: "region",
2670
2682
  environmentVariableName: "AWS_REGION",
@@ -2673,19 +2685,20 @@ Original error: ${errorMessage}`
2673
2685
  service: "bedrock-agent-runtime",
2674
2686
  serviceEndpointUrlEnvironmentVariableName: "AWS_ENDPOINT_URL_BEDROCK_AGENT_RUNTIME"
2675
2687
  });
2676
- const createChatModel = (modelId) => new BedrockChatLanguageModel(modelId, {
2688
+ const createChatModel = (modelId, settings = {}) => new BedrockChatLanguageModel(modelId, {
2677
2689
  baseUrl: getBedrockRuntimeBaseUrl,
2678
2690
  headers: getHeaders,
2679
2691
  fetch: fetchFunction,
2680
- generateId: import_provider_utils12.generateId
2692
+ generateId: import_provider_utils13.generateId,
2693
+ modelFamily: settings.modelFamily
2681
2694
  });
2682
- const provider = function(modelId) {
2695
+ const provider = function(modelId, settings) {
2683
2696
  if (new.target) {
2684
2697
  throw new Error(
2685
2698
  "The Amazon Bedrock model function cannot be called with the new keyword."
2686
2699
  );
2687
2700
  }
2688
- return createChatModel(modelId);
2701
+ return createChatModel(modelId, settings);
2689
2702
  };
2690
2703
  const createEmbeddingModel = (modelId, settings = {}) => new BedrockEmbeddingModel(modelId, {
2691
2704
  baseUrl: getBedrockRuntimeBaseUrl,
@@ -2700,7 +2713,7 @@ Original error: ${errorMessage}`
2700
2713
  });
2701
2714
  const createRerankingModel = (modelId) => new BedrockRerankingModel(modelId, {
2702
2715
  baseUrl: getBedrockAgentRuntimeBaseUrl,
2703
- region: (0, import_provider_utils12.loadSetting)({
2716
+ region: (0, import_provider_utils13.loadSetting)({
2704
2717
  settingValue: options.region,
2705
2718
  settingName: "region",
2706
2719
  environmentVariableName: "AWS_REGION",