@ai-sdk/amazon-bedrock 4.0.161 → 4.0.163

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.161" : "0.0.0-test";
38
+ var VERSION = true ? "4.0.163" : "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.161" : "0.0.0-test";
26
+ var VERSION = true ? "4.0.163" : "0.0.0-test";
27
27
 
28
28
  // src/bedrock-sigv4-fetch.ts
29
29
  function createSigV4FetchFunction(getCredentials, fetch, service = "bedrock") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/amazon-bedrock",
3
- "version": "4.0.161",
3
+ "version": "4.0.163",
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.113",
48
- "@ai-sdk/openai": "3.0.101",
48
+ "@ai-sdk/openai": "3.0.102",
49
49
  "@ai-sdk/provider": "3.0.15",
50
50
  "@ai-sdk/provider-utils": "4.0.48"
51
51
  },
@@ -151,6 +151,10 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
151
151
  }
152
152
 
153
153
  const isAnthropicModel = this.modelId.includes('anthropic');
154
+ const openAIModelId = /^(?:[^.]+\.)?(openai\..+)$/.exec(this.modelId)?.[1];
155
+ const isOpenAIModel = openAIModelId != null;
156
+ const isOpenAIGptOssModel =
157
+ openAIModelId?.startsWith('openai.gpt-oss-') ?? false;
154
158
  const isThinkingEnabled =
155
159
  bedrockOptions.reasoningConfig?.type === 'enabled' ||
156
160
  bedrockOptions.reasoningConfig?.type === 'adaptive';
@@ -279,7 +283,6 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
279
283
 
280
284
  const maxReasoningEffort =
281
285
  bedrockOptions.reasoningConfig?.maxReasoningEffort;
282
- const isOpenAIModel = this.modelId.startsWith('openai.');
283
286
 
284
287
  if (maxReasoningEffort != null) {
285
288
  if (isAnthropicModel) {
@@ -291,11 +294,20 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
291
294
  },
292
295
  };
293
296
  } else if (isOpenAIModel) {
294
- // OpenAI models on Bedrock expect `reasoning_effort` as a flat value
295
- bedrockOptions.additionalModelRequestFields = {
296
- ...bedrockOptions.additionalModelRequestFields,
297
- reasoning_effort: maxReasoningEffort,
298
- };
297
+ // gpt-oss models expect `reasoning_effort` as a flat value, while
298
+ // GPT-5.x models expect a nested `reasoning.effort` object.
299
+ bedrockOptions.additionalModelRequestFields = isOpenAIGptOssModel
300
+ ? {
301
+ ...bedrockOptions.additionalModelRequestFields,
302
+ reasoning_effort: maxReasoningEffort,
303
+ }
304
+ : {
305
+ ...bedrockOptions.additionalModelRequestFields,
306
+ reasoning: {
307
+ ...bedrockOptions.additionalModelRequestFields?.reasoning,
308
+ effort: maxReasoningEffort,
309
+ },
310
+ };
299
311
  } else {
300
312
  // other models (such as Nova 2) use reasoningConfig format
301
313
  bedrockOptions.additionalModelRequestFields = {
@@ -1185,6 +1197,13 @@ const BedrockRedactedReasoningSchema = z.object({
1185
1197
  data: z.string(),
1186
1198
  });
1187
1199
 
1200
+ const AmazonBedrockCacheDetailSchema = z
1201
+ .object({
1202
+ inputTokens: z.number(),
1203
+ ttl: z.string(),
1204
+ })
1205
+ .catchall(z.json());
1206
+
1188
1207
  // limited version of the schema, focused on what is needed for the implementation
1189
1208
  // this approach limits breakages when the API changes and increases efficiency
1190
1209
  const BedrockResponseSchema = z.object({
@@ -1227,16 +1246,16 @@ const BedrockResponseSchema = z.object({
1227
1246
  trace: z.unknown().nullish(),
1228
1247
  performanceConfig: z.object({ latency: z.string() }).nullish(),
1229
1248
  serviceTier: z.object({ type: z.string() }).nullish(),
1230
- usage: z.object({
1231
- inputTokens: z.number(),
1232
- outputTokens: z.number(),
1233
- totalTokens: z.number(),
1234
- cacheReadInputTokens: z.number().nullish(),
1235
- cacheWriteInputTokens: z.number().nullish(),
1236
- cacheDetails: z
1237
- .array(z.object({ inputTokens: z.number(), ttl: z.string() }))
1238
- .nullish(),
1239
- }),
1249
+ usage: z
1250
+ .object({
1251
+ inputTokens: z.number(),
1252
+ outputTokens: z.number(),
1253
+ totalTokens: z.number(),
1254
+ cacheReadInputTokens: z.number().nullish(),
1255
+ cacheWriteInputTokens: z.number().nullish(),
1256
+ cacheDetails: z.array(AmazonBedrockCacheDetailSchema).nullish(),
1257
+ })
1258
+ .catchall(z.json()),
1240
1259
  });
1241
1260
 
1242
1261
  // limited version of the schema, focussed on what is needed for the implementation
@@ -1302,12 +1321,12 @@ const BedrockStreamSchema = z.object({
1302
1321
  .object({
1303
1322
  cacheReadInputTokens: z.number().nullish(),
1304
1323
  cacheWriteInputTokens: z.number().nullish(),
1305
- cacheDetails: z
1306
- .array(z.object({ inputTokens: z.number(), ttl: z.string() }))
1307
- .nullish(),
1324
+ cacheDetails: z.array(AmazonBedrockCacheDetailSchema).nullish(),
1308
1325
  inputTokens: z.number(),
1309
1326
  outputTokens: z.number(),
1327
+ totalTokens: z.number().optional(),
1310
1328
  })
1329
+ .catchall(z.json())
1311
1330
  .nullish(),
1312
1331
  })
1313
1332
  .nullish(),
@@ -1,11 +1,17 @@
1
- import type { LanguageModelV3Usage } from '@ai-sdk/provider';
1
+ import type { JSONValue, LanguageModelV3Usage } from '@ai-sdk/provider';
2
2
 
3
3
  export type BedrockUsage = {
4
+ [key: string]: JSONValue | undefined;
4
5
  inputTokens: number;
5
6
  outputTokens: number;
6
7
  totalTokens?: number;
7
8
  cacheReadInputTokens?: number | null;
8
9
  cacheWriteInputTokens?: number | null;
10
+ cacheDetails?: Array<{
11
+ [key: string]: JSONValue | undefined;
12
+ inputTokens: number;
13
+ ttl: string;
14
+ }> | null;
9
15
  };
10
16
 
11
17
  export function convertBedrockUsage(