@openrouter/ai-sdk-provider 1.2.0 → 1.2.1

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.
@@ -873,19 +873,40 @@ function convertUint8ArrayToBase64(array) {
873
873
 
874
874
  // src/schemas/reasoning-details.ts
875
875
  var import_v4 = require("zod/v4");
876
+
877
+ // src/utils/type-guards.ts
878
+ function isDefinedOrNotNull(value) {
879
+ return value !== null && value !== void 0;
880
+ }
881
+
882
+ // src/schemas/format.ts
883
+ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
884
+ ReasoningFormat2["Unknown"] = "unknown";
885
+ ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
886
+ ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
887
+ ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
888
+ return ReasoningFormat2;
889
+ })(ReasoningFormat || {});
890
+
891
+ // src/schemas/reasoning-details.ts
892
+ var CommonReasoningDetailSchema = import_v4.z.object({
893
+ id: import_v4.z.string().nullish(),
894
+ format: import_v4.z.nativeEnum(ReasoningFormat).nullish(),
895
+ index: import_v4.z.number().optional()
896
+ });
876
897
  var ReasoningDetailSummarySchema = import_v4.z.object({
877
898
  type: import_v4.z.literal("reasoning.summary" /* Summary */),
878
899
  summary: import_v4.z.string()
879
- });
900
+ }).extend(CommonReasoningDetailSchema.shape);
880
901
  var ReasoningDetailEncryptedSchema = import_v4.z.object({
881
902
  type: import_v4.z.literal("reasoning.encrypted" /* Encrypted */),
882
903
  data: import_v4.z.string()
883
- });
904
+ }).extend(CommonReasoningDetailSchema.shape);
884
905
  var ReasoningDetailTextSchema = import_v4.z.object({
885
906
  type: import_v4.z.literal("reasoning.text" /* Text */),
886
907
  text: import_v4.z.string().nullish(),
887
908
  signature: import_v4.z.string().nullish()
888
- });
909
+ }).extend(CommonReasoningDetailSchema.shape);
889
910
  var ReasoningDetailUnionSchema = import_v4.z.union([
890
911
  ReasoningDetailSummarySchema,
891
912
  ReasoningDetailEncryptedSchema,
@@ -896,6 +917,22 @@ var ReasoningDetailsWithUnknownSchema = import_v4.z.union([
896
917
  import_v4.z.unknown().transform(() => null)
897
918
  ]);
898
919
  var ReasoningDetailArraySchema = import_v4.z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
920
+ var OutputUnionToReasoningDetailsSchema = import_v4.z.union([
921
+ import_v4.z.object({
922
+ delta: import_v4.z.object({
923
+ reasoning_details: import_v4.z.array(ReasoningDetailsWithUnknownSchema)
924
+ })
925
+ }).transform((data) => data.delta.reasoning_details.filter(isDefinedOrNotNull)),
926
+ import_v4.z.object({
927
+ message: import_v4.z.object({
928
+ reasoning_details: import_v4.z.array(ReasoningDetailsWithUnknownSchema)
929
+ })
930
+ }).transform((data) => data.message.reasoning_details.filter(isDefinedOrNotNull)),
931
+ import_v4.z.object({
932
+ text: import_v4.z.string(),
933
+ reasoning_details: import_v4.z.array(ReasoningDetailsWithUnknownSchema)
934
+ }).transform((data) => data.reasoning_details.filter(isDefinedOrNotNull))
935
+ ]);
899
936
 
900
937
  // src/schemas/error-response.ts
901
938
  var import_v42 = require("zod/v4");
@@ -912,6 +949,33 @@ var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
912
949
  errorToMessage: (data) => data.error.message
913
950
  });
914
951
 
952
+ // src/schemas/provider-metadata.ts
953
+ var import_v43 = require("zod/v4");
954
+ var OpenRouterProviderMetadataSchema = import_v43.z.object({
955
+ provider: import_v43.z.string(),
956
+ reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional(),
957
+ usage: import_v43.z.object({
958
+ promptTokens: import_v43.z.number(),
959
+ promptTokensDetails: import_v43.z.object({
960
+ cachedTokens: import_v43.z.number()
961
+ }).optional(),
962
+ completionTokens: import_v43.z.number(),
963
+ completionTokensDetails: import_v43.z.object({
964
+ reasoningTokens: import_v43.z.number()
965
+ }).optional(),
966
+ totalTokens: import_v43.z.number(),
967
+ cost: import_v43.z.number().optional(),
968
+ costDetails: import_v43.z.object({
969
+ upstreamInferenceCost: import_v43.z.number()
970
+ })
971
+ })
972
+ });
973
+ var OpenRouterProviderOptionsSchema = import_v43.z.object({
974
+ openrouter: import_v43.z.object({
975
+ reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional()
976
+ }).optional()
977
+ }).optional();
978
+
915
979
  // src/utils/map-finish-reason.ts
916
980
  function mapOpenRouterFinishReason(finishReason) {
917
981
  switch (finishReason) {
@@ -979,7 +1043,7 @@ function getCacheControl(providerMetadata) {
979
1043
  return (_c = (_b = (_a15 = openrouter == null ? void 0 : openrouter.cacheControl) != null ? _a15 : openrouter == null ? void 0 : openrouter.cache_control) != null ? _b : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
980
1044
  }
981
1045
  function convertToOpenRouterChatMessages(prompt) {
982
- var _a15, _b, _c;
1046
+ var _a15, _b, _c, _d, _e;
983
1047
  const messages = [];
984
1048
  for (const { role, content, providerOptions } of prompt) {
985
1049
  switch (role) {
@@ -1010,7 +1074,7 @@ function convertToOpenRouterChatMessages(prompt) {
1010
1074
  const messageCacheControl = getCacheControl(providerOptions);
1011
1075
  const contentParts = content.map(
1012
1076
  (part) => {
1013
- var _a16, _b2, _c2, _d, _e, _f;
1077
+ var _a16, _b2, _c2, _d2, _e2, _f;
1014
1078
  const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
1015
1079
  switch (part.type) {
1016
1080
  case "text":
@@ -1036,7 +1100,7 @@ function convertToOpenRouterChatMessages(prompt) {
1036
1100
  };
1037
1101
  }
1038
1102
  const fileName = String(
1039
- (_f = (_e = (_d = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d.filename) != null ? _e : part.filename) != null ? _f : ""
1103
+ (_f = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f : ""
1040
1104
  );
1041
1105
  const fileData = getFileUrl({
1042
1106
  part,
@@ -1082,7 +1146,6 @@ function convertToOpenRouterChatMessages(prompt) {
1082
1146
  case "assistant": {
1083
1147
  let text = "";
1084
1148
  let reasoning = "";
1085
- const reasoningDetails = [];
1086
1149
  const toolCalls = [];
1087
1150
  for (const part of content) {
1088
1151
  switch (part.type) {
@@ -1103,10 +1166,6 @@ function convertToOpenRouterChatMessages(prompt) {
1103
1166
  }
1104
1167
  case "reasoning": {
1105
1168
  reasoning += part.text;
1106
- reasoningDetails.push({
1107
- type: "reasoning.text" /* Text */,
1108
- text: part.text
1109
- });
1110
1169
  break;
1111
1170
  }
1112
1171
  case "file":
@@ -1116,12 +1175,17 @@ function convertToOpenRouterChatMessages(prompt) {
1116
1175
  }
1117
1176
  }
1118
1177
  }
1178
+ const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(
1179
+ providerOptions
1180
+ );
1181
+ const preservedReasoningDetails = parsedProviderOptions.success ? (_d = (_c = parsedProviderOptions.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details : void 0;
1119
1182
  messages.push({
1120
1183
  role: "assistant",
1121
1184
  content: text,
1122
1185
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
1123
1186
  reasoning: reasoning || void 0,
1124
- reasoning_details: reasoningDetails.length > 0 ? reasoningDetails : void 0,
1187
+ // Only include reasoning_details if we have the preserved original version
1188
+ reasoning_details: preservedReasoningDetails && Array.isArray(preservedReasoningDetails) && preservedReasoningDetails.length > 0 ? preservedReasoningDetails : void 0,
1125
1189
  cache_control: getCacheControl(providerOptions)
1126
1190
  });
1127
1191
  break;
@@ -1133,7 +1197,7 @@ function convertToOpenRouterChatMessages(prompt) {
1133
1197
  role: "tool",
1134
1198
  tool_call_id: toolResponse.toolCallId,
1135
1199
  content: content2,
1136
- cache_control: (_c = getCacheControl(providerOptions)) != null ? _c : getCacheControl(toolResponse.providerOptions)
1200
+ cache_control: (_e = getCacheControl(providerOptions)) != null ? _e : getCacheControl(toolResponse.providerOptions)
1137
1201
  });
1138
1202
  }
1139
1203
  break;
@@ -1150,15 +1214,15 @@ function getToolResultContent(input) {
1150
1214
  }
1151
1215
 
1152
1216
  // src/chat/get-tool-choice.ts
1153
- var import_v43 = require("zod/v4");
1154
- var ChatCompletionToolChoiceSchema = import_v43.z.union([
1155
- import_v43.z.literal("auto"),
1156
- import_v43.z.literal("none"),
1157
- import_v43.z.literal("required"),
1158
- import_v43.z.object({
1159
- type: import_v43.z.literal("function"),
1160
- function: import_v43.z.object({
1161
- name: import_v43.z.string()
1217
+ var import_v44 = require("zod/v4");
1218
+ var ChatCompletionToolChoiceSchema = import_v44.z.union([
1219
+ import_v44.z.literal("auto"),
1220
+ import_v44.z.literal("none"),
1221
+ import_v44.z.literal("required"),
1222
+ import_v44.z.object({
1223
+ type: import_v44.z.literal("function"),
1224
+ function: import_v44.z.object({
1225
+ name: import_v44.z.string()
1162
1226
  })
1163
1227
  })
1164
1228
  ]);
@@ -1182,144 +1246,144 @@ function getChatCompletionToolChoice(toolChoice) {
1182
1246
  }
1183
1247
 
1184
1248
  // src/chat/schemas.ts
1185
- var import_v45 = require("zod/v4");
1249
+ var import_v46 = require("zod/v4");
1186
1250
 
1187
1251
  // src/schemas/image.ts
1188
- var import_v44 = require("zod/v4");
1189
- var ImageResponseSchema = import_v44.z.object({
1190
- type: import_v44.z.literal("image_url"),
1191
- image_url: import_v44.z.object({
1192
- url: import_v44.z.string()
1252
+ var import_v45 = require("zod/v4");
1253
+ var ImageResponseSchema = import_v45.z.object({
1254
+ type: import_v45.z.literal("image_url"),
1255
+ image_url: import_v45.z.object({
1256
+ url: import_v45.z.string()
1193
1257
  })
1194
1258
  });
1195
- var ImageResponseWithUnknownSchema = import_v44.z.union([
1259
+ var ImageResponseWithUnknownSchema = import_v45.z.union([
1196
1260
  ImageResponseSchema,
1197
- import_v44.z.unknown().transform(() => null)
1261
+ import_v45.z.unknown().transform(() => null)
1198
1262
  ]);
1199
- var ImageResponseArraySchema = import_v44.z.array(ImageResponseWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
1263
+ var ImageResponseArraySchema = import_v45.z.array(ImageResponseWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
1200
1264
 
1201
1265
  // src/chat/schemas.ts
1202
- var OpenRouterChatCompletionBaseResponseSchema = import_v45.z.object({
1203
- id: import_v45.z.string().optional(),
1204
- model: import_v45.z.string().optional(),
1205
- provider: import_v45.z.string().optional(),
1206
- usage: import_v45.z.object({
1207
- prompt_tokens: import_v45.z.number(),
1208
- prompt_tokens_details: import_v45.z.object({
1209
- cached_tokens: import_v45.z.number()
1266
+ var OpenRouterChatCompletionBaseResponseSchema = import_v46.z.object({
1267
+ id: import_v46.z.string().optional(),
1268
+ model: import_v46.z.string().optional(),
1269
+ provider: import_v46.z.string().optional(),
1270
+ usage: import_v46.z.object({
1271
+ prompt_tokens: import_v46.z.number(),
1272
+ prompt_tokens_details: import_v46.z.object({
1273
+ cached_tokens: import_v46.z.number()
1210
1274
  }).nullish(),
1211
- completion_tokens: import_v45.z.number(),
1212
- completion_tokens_details: import_v45.z.object({
1213
- reasoning_tokens: import_v45.z.number()
1275
+ completion_tokens: import_v46.z.number(),
1276
+ completion_tokens_details: import_v46.z.object({
1277
+ reasoning_tokens: import_v46.z.number()
1214
1278
  }).nullish(),
1215
- total_tokens: import_v45.z.number(),
1216
- cost: import_v45.z.number().optional(),
1217
- cost_details: import_v45.z.object({
1218
- upstream_inference_cost: import_v45.z.number().nullish()
1279
+ total_tokens: import_v46.z.number(),
1280
+ cost: import_v46.z.number().optional(),
1281
+ cost_details: import_v46.z.object({
1282
+ upstream_inference_cost: import_v46.z.number().nullish()
1219
1283
  }).nullish()
1220
1284
  }).nullish()
1221
1285
  });
1222
1286
  var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
1223
- choices: import_v45.z.array(
1224
- import_v45.z.object({
1225
- message: import_v45.z.object({
1226
- role: import_v45.z.literal("assistant"),
1227
- content: import_v45.z.string().nullable().optional(),
1228
- reasoning: import_v45.z.string().nullable().optional(),
1287
+ choices: import_v46.z.array(
1288
+ import_v46.z.object({
1289
+ message: import_v46.z.object({
1290
+ role: import_v46.z.literal("assistant"),
1291
+ content: import_v46.z.string().nullable().optional(),
1292
+ reasoning: import_v46.z.string().nullable().optional(),
1229
1293
  reasoning_details: ReasoningDetailArraySchema.nullish(),
1230
1294
  images: ImageResponseArraySchema.nullish(),
1231
- tool_calls: import_v45.z.array(
1232
- import_v45.z.object({
1233
- id: import_v45.z.string().optional().nullable(),
1234
- type: import_v45.z.literal("function"),
1235
- function: import_v45.z.object({
1236
- name: import_v45.z.string(),
1237
- arguments: import_v45.z.string()
1295
+ tool_calls: import_v46.z.array(
1296
+ import_v46.z.object({
1297
+ id: import_v46.z.string().optional().nullable(),
1298
+ type: import_v46.z.literal("function"),
1299
+ function: import_v46.z.object({
1300
+ name: import_v46.z.string(),
1301
+ arguments: import_v46.z.string()
1238
1302
  })
1239
1303
  })
1240
1304
  ).optional(),
1241
- annotations: import_v45.z.array(
1242
- import_v45.z.object({
1243
- type: import_v45.z.enum(["url_citation"]),
1244
- url_citation: import_v45.z.object({
1245
- end_index: import_v45.z.number(),
1246
- start_index: import_v45.z.number(),
1247
- title: import_v45.z.string(),
1248
- url: import_v45.z.string(),
1249
- content: import_v45.z.string().optional()
1305
+ annotations: import_v46.z.array(
1306
+ import_v46.z.object({
1307
+ type: import_v46.z.enum(["url_citation"]),
1308
+ url_citation: import_v46.z.object({
1309
+ end_index: import_v46.z.number(),
1310
+ start_index: import_v46.z.number(),
1311
+ title: import_v46.z.string(),
1312
+ url: import_v46.z.string(),
1313
+ content: import_v46.z.string().optional()
1250
1314
  })
1251
1315
  })
1252
1316
  ).nullish()
1253
1317
  }),
1254
- index: import_v45.z.number().nullish(),
1255
- logprobs: import_v45.z.object({
1256
- content: import_v45.z.array(
1257
- import_v45.z.object({
1258
- token: import_v45.z.string(),
1259
- logprob: import_v45.z.number(),
1260
- top_logprobs: import_v45.z.array(
1261
- import_v45.z.object({
1262
- token: import_v45.z.string(),
1263
- logprob: import_v45.z.number()
1318
+ index: import_v46.z.number().nullish(),
1319
+ logprobs: import_v46.z.object({
1320
+ content: import_v46.z.array(
1321
+ import_v46.z.object({
1322
+ token: import_v46.z.string(),
1323
+ logprob: import_v46.z.number(),
1324
+ top_logprobs: import_v46.z.array(
1325
+ import_v46.z.object({
1326
+ token: import_v46.z.string(),
1327
+ logprob: import_v46.z.number()
1264
1328
  })
1265
1329
  )
1266
1330
  })
1267
1331
  ).nullable()
1268
1332
  }).nullable().optional(),
1269
- finish_reason: import_v45.z.string().optional().nullable()
1333
+ finish_reason: import_v46.z.string().optional().nullable()
1270
1334
  })
1271
1335
  )
1272
1336
  });
1273
- var OpenRouterStreamChatCompletionChunkSchema = import_v45.z.union([
1337
+ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
1274
1338
  OpenRouterChatCompletionBaseResponseSchema.extend({
1275
- choices: import_v45.z.array(
1276
- import_v45.z.object({
1277
- delta: import_v45.z.object({
1278
- role: import_v45.z.enum(["assistant"]).optional(),
1279
- content: import_v45.z.string().nullish(),
1280
- reasoning: import_v45.z.string().nullish().optional(),
1339
+ choices: import_v46.z.array(
1340
+ import_v46.z.object({
1341
+ delta: import_v46.z.object({
1342
+ role: import_v46.z.enum(["assistant"]).optional(),
1343
+ content: import_v46.z.string().nullish(),
1344
+ reasoning: import_v46.z.string().nullish().optional(),
1281
1345
  reasoning_details: ReasoningDetailArraySchema.nullish(),
1282
1346
  images: ImageResponseArraySchema.nullish(),
1283
- tool_calls: import_v45.z.array(
1284
- import_v45.z.object({
1285
- index: import_v45.z.number().nullish(),
1286
- id: import_v45.z.string().nullish(),
1287
- type: import_v45.z.literal("function").optional(),
1288
- function: import_v45.z.object({
1289
- name: import_v45.z.string().nullish(),
1290
- arguments: import_v45.z.string().nullish()
1347
+ tool_calls: import_v46.z.array(
1348
+ import_v46.z.object({
1349
+ index: import_v46.z.number().nullish(),
1350
+ id: import_v46.z.string().nullish(),
1351
+ type: import_v46.z.literal("function").optional(),
1352
+ function: import_v46.z.object({
1353
+ name: import_v46.z.string().nullish(),
1354
+ arguments: import_v46.z.string().nullish()
1291
1355
  })
1292
1356
  })
1293
1357
  ).nullish(),
1294
- annotations: import_v45.z.array(
1295
- import_v45.z.object({
1296
- type: import_v45.z.enum(["url_citation"]),
1297
- url_citation: import_v45.z.object({
1298
- end_index: import_v45.z.number(),
1299
- start_index: import_v45.z.number(),
1300
- title: import_v45.z.string(),
1301
- url: import_v45.z.string(),
1302
- content: import_v45.z.string().optional()
1358
+ annotations: import_v46.z.array(
1359
+ import_v46.z.object({
1360
+ type: import_v46.z.enum(["url_citation"]),
1361
+ url_citation: import_v46.z.object({
1362
+ end_index: import_v46.z.number(),
1363
+ start_index: import_v46.z.number(),
1364
+ title: import_v46.z.string(),
1365
+ url: import_v46.z.string(),
1366
+ content: import_v46.z.string().optional()
1303
1367
  })
1304
1368
  })
1305
1369
  ).nullish()
1306
1370
  }).nullish(),
1307
- logprobs: import_v45.z.object({
1308
- content: import_v45.z.array(
1309
- import_v45.z.object({
1310
- token: import_v45.z.string(),
1311
- logprob: import_v45.z.number(),
1312
- top_logprobs: import_v45.z.array(
1313
- import_v45.z.object({
1314
- token: import_v45.z.string(),
1315
- logprob: import_v45.z.number()
1371
+ logprobs: import_v46.z.object({
1372
+ content: import_v46.z.array(
1373
+ import_v46.z.object({
1374
+ token: import_v46.z.string(),
1375
+ logprob: import_v46.z.number(),
1376
+ top_logprobs: import_v46.z.array(
1377
+ import_v46.z.object({
1378
+ token: import_v46.z.string(),
1379
+ logprob: import_v46.z.number()
1316
1380
  })
1317
1381
  )
1318
1382
  })
1319
1383
  ).nullable()
1320
1384
  }).nullish(),
1321
- finish_reason: import_v45.z.string().nullable().optional(),
1322
- index: import_v45.z.number().nullish()
1385
+ finish_reason: import_v46.z.string().nullable().optional(),
1386
+ index: import_v46.z.number().nullish()
1323
1387
  })
1324
1388
  )
1325
1389
  }),
@@ -1422,7 +1486,7 @@ var OpenRouterChatLanguageModel = class {
1422
1486
  return baseArgs;
1423
1487
  }
1424
1488
  async doGenerate(options) {
1425
- var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
1489
+ var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
1426
1490
  const providerOptions = options.providerOptions || {};
1427
1491
  const openrouterOptions = providerOptions.openrouter || {};
1428
1492
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
@@ -1549,24 +1613,25 @@ var OpenRouterChatLanguageModel = class {
1549
1613
  usage: usageInfo,
1550
1614
  warnings: [],
1551
1615
  providerMetadata: {
1552
- openrouter: {
1616
+ openrouter: OpenRouterProviderMetadataSchema.parse({
1553
1617
  provider: (_k = response.provider) != null ? _k : "",
1618
+ reasoning_details: (_l = choice.message.reasoning_details) != null ? _l : [],
1554
1619
  usage: {
1555
- promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
1556
- completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
1557
- totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
1558
- cost: (_o = response.usage) == null ? void 0 : _o.cost,
1620
+ promptTokens: (_m = usageInfo.inputTokens) != null ? _m : 0,
1621
+ completionTokens: (_n = usageInfo.outputTokens) != null ? _n : 0,
1622
+ totalTokens: (_o = usageInfo.totalTokens) != null ? _o : 0,
1623
+ cost: (_p = response.usage) == null ? void 0 : _p.cost,
1559
1624
  promptTokensDetails: {
1560
- cachedTokens: (_r = (_q = (_p = response.usage) == null ? void 0 : _p.prompt_tokens_details) == null ? void 0 : _q.cached_tokens) != null ? _r : 0
1625
+ cachedTokens: (_s = (_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : 0
1561
1626
  },
1562
1627
  completionTokensDetails: {
1563
- reasoningTokens: (_u = (_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? _u : 0
1628
+ reasoningTokens: (_v = (_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? _v : 0
1564
1629
  },
1565
1630
  costDetails: {
1566
- upstreamInferenceCost: (_x = (_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? _x : 0
1631
+ upstreamInferenceCost: (_y = (_x = (_w = response.usage) == null ? void 0 : _w.cost_details) == null ? void 0 : _x.upstream_inference_cost) != null ? _y : 0
1567
1632
  }
1568
1633
  }
1569
- }
1634
+ })
1570
1635
  },
1571
1636
  request: { body: args },
1572
1637
  response: {
@@ -1611,6 +1676,7 @@ var OpenRouterChatLanguageModel = class {
1611
1676
  cachedInputTokens: Number.NaN
1612
1677
  };
1613
1678
  const openrouterUsage = {};
1679
+ const accumulatedReasoningDetails = [];
1614
1680
  let textStarted = false;
1615
1681
  let reasoningStarted = false;
1616
1682
  let textId;
@@ -1696,6 +1762,7 @@ var OpenRouterChatLanguageModel = class {
1696
1762
  });
1697
1763
  };
1698
1764
  if (delta.reasoning_details && delta.reasoning_details.length > 0) {
1765
+ accumulatedReasoningDetails.push(...delta.reasoning_details);
1699
1766
  for (const detail of delta.reasoning_details) {
1700
1767
  switch (detail.type) {
1701
1768
  case "reasoning.text" /* Text */: {
@@ -1902,6 +1969,9 @@ var OpenRouterChatLanguageModel = class {
1902
1969
  if (provider !== void 0) {
1903
1970
  openrouterMetadata.provider = provider;
1904
1971
  }
1972
+ if (accumulatedReasoningDetails.length > 0) {
1973
+ openrouterMetadata.reasoning_details = accumulatedReasoningDetails;
1974
+ }
1905
1975
  controller.enqueue({
1906
1976
  type: "finish",
1907
1977
  finishReason,
@@ -2024,36 +2094,36 @@ ${assistantMessage}
2024
2094
  }
2025
2095
 
2026
2096
  // src/completion/schemas.ts
2027
- var import_v46 = require("zod/v4");
2028
- var OpenRouterCompletionChunkSchema = import_v46.z.union([
2029
- import_v46.z.object({
2030
- id: import_v46.z.string().optional(),
2031
- model: import_v46.z.string().optional(),
2032
- choices: import_v46.z.array(
2033
- import_v46.z.object({
2034
- text: import_v46.z.string(),
2035
- reasoning: import_v46.z.string().nullish().optional(),
2097
+ var import_v47 = require("zod/v4");
2098
+ var OpenRouterCompletionChunkSchema = import_v47.z.union([
2099
+ import_v47.z.object({
2100
+ id: import_v47.z.string().optional(),
2101
+ model: import_v47.z.string().optional(),
2102
+ choices: import_v47.z.array(
2103
+ import_v47.z.object({
2104
+ text: import_v47.z.string(),
2105
+ reasoning: import_v47.z.string().nullish().optional(),
2036
2106
  reasoning_details: ReasoningDetailArraySchema.nullish(),
2037
- finish_reason: import_v46.z.string().nullish(),
2038
- index: import_v46.z.number().nullish(),
2039
- logprobs: import_v46.z.object({
2040
- tokens: import_v46.z.array(import_v46.z.string()),
2041
- token_logprobs: import_v46.z.array(import_v46.z.number()),
2042
- top_logprobs: import_v46.z.array(import_v46.z.record(import_v46.z.string(), import_v46.z.number())).nullable()
2107
+ finish_reason: import_v47.z.string().nullish(),
2108
+ index: import_v47.z.number().nullish(),
2109
+ logprobs: import_v47.z.object({
2110
+ tokens: import_v47.z.array(import_v47.z.string()),
2111
+ token_logprobs: import_v47.z.array(import_v47.z.number()),
2112
+ top_logprobs: import_v47.z.array(import_v47.z.record(import_v47.z.string(), import_v47.z.number())).nullable()
2043
2113
  }).nullable().optional()
2044
2114
  })
2045
2115
  ),
2046
- usage: import_v46.z.object({
2047
- prompt_tokens: import_v46.z.number(),
2048
- prompt_tokens_details: import_v46.z.object({
2049
- cached_tokens: import_v46.z.number()
2116
+ usage: import_v47.z.object({
2117
+ prompt_tokens: import_v47.z.number(),
2118
+ prompt_tokens_details: import_v47.z.object({
2119
+ cached_tokens: import_v47.z.number()
2050
2120
  }).nullish(),
2051
- completion_tokens: import_v46.z.number(),
2052
- completion_tokens_details: import_v46.z.object({
2053
- reasoning_tokens: import_v46.z.number()
2121
+ completion_tokens: import_v47.z.number(),
2122
+ completion_tokens_details: import_v47.z.object({
2123
+ reasoning_tokens: import_v47.z.number()
2054
2124
  }).nullish(),
2055
- total_tokens: import_v46.z.number(),
2056
- cost: import_v46.z.number().optional()
2125
+ total_tokens: import_v47.z.number(),
2126
+ cost: import_v47.z.number().optional()
2057
2127
  }).nullish()
2058
2128
  }),
2059
2129
  OpenRouterErrorResponseSchema