@openrouter/ai-sdk-provider 1.2.2 → 1.2.4

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.
@@ -863,6 +863,7 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
863
863
  ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
864
864
  ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
865
865
  ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
866
+ ReasoningFormat2["GoogleGeminiV1"] = "google-gemini-v1";
866
867
  return ReasoningFormat2;
867
868
  })(ReasoningFormat || {});
868
869
 
@@ -871,7 +872,7 @@ var CommonReasoningDetailSchema = z.object({
871
872
  id: z.string().nullish(),
872
873
  format: z.nativeEnum(ReasoningFormat).nullish(),
873
874
  index: z.number().optional()
874
- });
875
+ }).passthrough();
875
876
  var ReasoningDetailSummarySchema = z.object({
876
877
  type: z.literal("reasoning.summary" /* Summary */),
877
878
  summary: z.string()
@@ -924,8 +925,8 @@ var OpenRouterErrorResponseSchema = z2.object({
924
925
  message: z2.string(),
925
926
  type: z2.string().nullable().optional().default(null),
926
927
  param: z2.any().nullable().optional().default(null)
927
- })
928
- });
928
+ }).passthrough()
929
+ }).passthrough();
929
930
  var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
930
931
  errorSchema: OpenRouterErrorResponseSchema,
931
932
  errorToMessage: (data) => data.error.message
@@ -940,18 +941,18 @@ var OpenRouterProviderMetadataSchema = z3.object({
940
941
  promptTokens: z3.number(),
941
942
  promptTokensDetails: z3.object({
942
943
  cachedTokens: z3.number()
943
- }).optional(),
944
+ }).passthrough().optional(),
944
945
  completionTokens: z3.number(),
945
946
  completionTokensDetails: z3.object({
946
947
  reasoningTokens: z3.number()
947
- }).optional(),
948
+ }).passthrough().optional(),
948
949
  totalTokens: z3.number(),
949
950
  cost: z3.number().optional(),
950
951
  costDetails: z3.object({
951
952
  upstreamInferenceCost: z3.number()
952
- })
953
- })
954
- });
953
+ }).passthrough()
954
+ }).passthrough()
955
+ }).passthrough();
955
956
  var OpenRouterProviderOptionsSchema = z3.object({
956
957
  openrouter: z3.object({
957
958
  reasoning_details: z3.array(ReasoningDetailUnionSchema).optional()
@@ -1237,8 +1238,8 @@ var ImageResponseSchema = z6.object({
1237
1238
  type: z6.literal("image_url"),
1238
1239
  image_url: z6.object({
1239
1240
  url: z6.string()
1240
- })
1241
- });
1241
+ }).passthrough()
1242
+ }).passthrough();
1242
1243
  var ImageResponseWithUnknownSchema = z6.union([
1243
1244
  ImageResponseSchema,
1244
1245
  z6.unknown().transform(() => null)
@@ -1254,18 +1255,18 @@ var OpenRouterChatCompletionBaseResponseSchema = z7.object({
1254
1255
  prompt_tokens: z7.number(),
1255
1256
  prompt_tokens_details: z7.object({
1256
1257
  cached_tokens: z7.number()
1257
- }).nullish(),
1258
+ }).passthrough().nullish(),
1258
1259
  completion_tokens: z7.number(),
1259
1260
  completion_tokens_details: z7.object({
1260
1261
  reasoning_tokens: z7.number()
1261
- }).nullish(),
1262
+ }).passthrough().nullish(),
1262
1263
  total_tokens: z7.number(),
1263
1264
  cost: z7.number().optional(),
1264
1265
  cost_details: z7.object({
1265
1266
  upstream_inference_cost: z7.number().nullish()
1266
- }).nullish()
1267
- }).nullish()
1268
- });
1267
+ }).passthrough().nullish()
1268
+ }).passthrough().nullish()
1269
+ }).passthrough();
1269
1270
  var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1270
1271
  // Success response with choices
1271
1272
  OpenRouterChatCompletionBaseResponseSchema.extend({
@@ -1284,8 +1285,8 @@ var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1284
1285
  function: z7.object({
1285
1286
  name: z7.string(),
1286
1287
  arguments: z7.string()
1287
- })
1288
- })
1288
+ }).passthrough()
1289
+ }).passthrough()
1289
1290
  ).optional(),
1290
1291
  annotations: z7.array(
1291
1292
  z7.union([
@@ -1298,16 +1299,16 @@ var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1298
1299
  title: z7.string(),
1299
1300
  url: z7.string(),
1300
1301
  content: z7.string().optional()
1301
- })
1302
- }),
1302
+ }).passthrough()
1303
+ }).passthrough(),
1303
1304
  // File annotation from FileParserPlugin (old format)
1304
1305
  z7.object({
1305
1306
  type: z7.literal("file_annotation"),
1306
1307
  file_annotation: z7.object({
1307
1308
  file_id: z7.string(),
1308
1309
  quote: z7.string().optional()
1309
- })
1310
- }),
1310
+ }).passthrough()
1311
+ }).passthrough(),
1311
1312
  // File annotation from FileParserPlugin (new format)
1312
1313
  z7.object({
1313
1314
  type: z7.literal("file"),
@@ -1318,13 +1319,13 @@ var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1318
1319
  z7.object({
1319
1320
  type: z7.string(),
1320
1321
  text: z7.string()
1321
- })
1322
+ }).passthrough()
1322
1323
  ).optional()
1323
- })
1324
- })
1324
+ }).passthrough()
1325
+ }).passthrough()
1325
1326
  ])
1326
1327
  ).nullish()
1327
- }),
1328
+ }).passthrough(),
1328
1329
  index: z7.number().nullish(),
1329
1330
  logprobs: z7.object({
1330
1331
  content: z7.array(
@@ -1335,13 +1336,13 @@ var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1335
1336
  z7.object({
1336
1337
  token: z7.string(),
1337
1338
  logprob: z7.number()
1338
- })
1339
+ }).passthrough()
1339
1340
  )
1340
- })
1341
+ }).passthrough()
1341
1342
  ).nullable()
1342
- }).nullable().optional(),
1343
+ }).passthrough().nullable().optional(),
1343
1344
  finish_reason: z7.string().optional().nullable()
1344
- })
1345
+ }).passthrough()
1345
1346
  )
1346
1347
  }),
1347
1348
  // Error response (HTTP 200 with error payload)
@@ -1367,8 +1368,8 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
1367
1368
  function: z7.object({
1368
1369
  name: z7.string().nullish(),
1369
1370
  arguments: z7.string().nullish()
1370
- })
1371
- })
1371
+ }).passthrough()
1372
+ }).passthrough()
1372
1373
  ).nullish(),
1373
1374
  annotations: z7.array(
1374
1375
  z7.union([
@@ -1381,16 +1382,16 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
1381
1382
  title: z7.string(),
1382
1383
  url: z7.string(),
1383
1384
  content: z7.string().optional()
1384
- })
1385
- }),
1385
+ }).passthrough()
1386
+ }).passthrough(),
1386
1387
  // File annotation from FileParserPlugin (old format)
1387
1388
  z7.object({
1388
1389
  type: z7.literal("file_annotation"),
1389
1390
  file_annotation: z7.object({
1390
1391
  file_id: z7.string(),
1391
1392
  quote: z7.string().optional()
1392
- })
1393
- }),
1393
+ }).passthrough()
1394
+ }).passthrough(),
1394
1395
  // File annotation from FileParserPlugin (new format)
1395
1396
  z7.object({
1396
1397
  type: z7.literal("file"),
@@ -1401,13 +1402,13 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
1401
1402
  z7.object({
1402
1403
  type: z7.string(),
1403
1404
  text: z7.string()
1404
- })
1405
+ }).passthrough()
1405
1406
  ).optional()
1406
- })
1407
- })
1407
+ }).passthrough()
1408
+ }).passthrough()
1408
1409
  ])
1409
1410
  ).nullish()
1410
- }).nullish(),
1411
+ }).passthrough().nullish(),
1411
1412
  logprobs: z7.object({
1412
1413
  content: z7.array(
1413
1414
  z7.object({
@@ -1417,14 +1418,14 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
1417
1418
  z7.object({
1418
1419
  token: z7.string(),
1419
1420
  logprob: z7.number()
1420
- })
1421
+ }).passthrough()
1421
1422
  )
1422
- })
1423
+ }).passthrough()
1423
1424
  ).nullable()
1424
- }).nullish(),
1425
+ }).passthrough().nullish(),
1425
1426
  finish_reason: z7.string().nullable().optional(),
1426
1427
  index: z7.number().nullish()
1427
- })
1428
+ }).passthrough()
1428
1429
  )
1429
1430
  }),
1430
1431
  OpenRouterErrorResponseSchema
@@ -1510,7 +1511,9 @@ var OpenRouterChatLanguageModel = class {
1510
1511
  });
1511
1512
  }
1512
1513
  if (tools && tools.length > 0) {
1513
- const mappedTools = tools.filter((tool) => tool.type === "function").map((tool) => ({
1514
+ const mappedTools = tools.filter(
1515
+ (tool) => tool.type === "function"
1516
+ ).map((tool) => ({
1514
1517
  type: "function",
1515
1518
  function: {
1516
1519
  name: tool.name,
@@ -1545,8 +1548,9 @@ var OpenRouterChatLanguageModel = class {
1545
1548
  fetch: this.config.fetch
1546
1549
  });
1547
1550
  if ("error" in responseValue) {
1551
+ const errorData = responseValue.error;
1548
1552
  throw new APICallError({
1549
- message: responseValue.error.message,
1553
+ message: errorData.message,
1550
1554
  url: this.config.url({
1551
1555
  path: "/chat/completions",
1552
1556
  modelId: this.modelId
@@ -1554,7 +1558,7 @@ var OpenRouterChatLanguageModel = class {
1554
1558
  requestBodyValues: args,
1555
1559
  statusCode: 200,
1556
1560
  responseHeaders,
1557
- data: responseValue.error
1561
+ data: errorData
1558
1562
  });
1559
1563
  }
1560
1564
  const response = responseValue;
@@ -1584,7 +1588,12 @@ var OpenRouterChatLanguageModel = class {
1584
1588
  if (detail.text) {
1585
1589
  return {
1586
1590
  type: "reasoning",
1587
- text: detail.text
1591
+ text: detail.text,
1592
+ providerMetadata: {
1593
+ openrouter: {
1594
+ reasoning_details: [detail]
1595
+ }
1596
+ }
1588
1597
  };
1589
1598
  }
1590
1599
  break;
@@ -1593,7 +1602,12 @@ var OpenRouterChatLanguageModel = class {
1593
1602
  if (detail.summary) {
1594
1603
  return {
1595
1604
  type: "reasoning",
1596
- text: detail.summary
1605
+ text: detail.summary,
1606
+ providerMetadata: {
1607
+ openrouter: {
1608
+ reasoning_details: [detail]
1609
+ }
1610
+ }
1597
1611
  };
1598
1612
  }
1599
1613
  break;
@@ -1602,7 +1616,12 @@ var OpenRouterChatLanguageModel = class {
1602
1616
  if (detail.data) {
1603
1617
  return {
1604
1618
  type: "reasoning",
1605
- text: "[REDACTED]"
1619
+ text: "[REDACTED]",
1620
+ providerMetadata: {
1621
+ openrouter: {
1622
+ reasoning_details: [detail]
1623
+ }
1624
+ }
1606
1625
  };
1607
1626
  }
1608
1627
  break;
@@ -1632,7 +1651,12 @@ var OpenRouterChatLanguageModel = class {
1632
1651
  type: "tool-call",
1633
1652
  toolCallId: (_j = toolCall.id) != null ? _j : generateId(),
1634
1653
  toolName: toolCall.function.name,
1635
- input: toolCall.function.arguments
1654
+ input: toolCall.function.arguments,
1655
+ providerMetadata: {
1656
+ openrouter: {
1657
+ reasoning_details: reasoningDetails
1658
+ }
1659
+ }
1636
1660
  });
1637
1661
  }
1638
1662
  }
@@ -1818,7 +1842,18 @@ var OpenRouterChatLanguageModel = class {
1818
1842
  });
1819
1843
  };
1820
1844
  if (delta.reasoning_details && delta.reasoning_details.length > 0) {
1821
- accumulatedReasoningDetails.push(...delta.reasoning_details);
1845
+ for (const detail of delta.reasoning_details) {
1846
+ if (detail.type === "reasoning.text" /* Text */) {
1847
+ const lastDetail = accumulatedReasoningDetails[accumulatedReasoningDetails.length - 1];
1848
+ if ((lastDetail == null ? void 0 : lastDetail.type) === "reasoning.text" /* Text */) {
1849
+ lastDetail.text = (lastDetail.text || "") + (detail.text || "");
1850
+ } else {
1851
+ accumulatedReasoningDetails.push(__spreadValues({}, detail));
1852
+ }
1853
+ } else {
1854
+ accumulatedReasoningDetails.push(detail);
1855
+ }
1856
+ }
1822
1857
  for (const detail of delta.reasoning_details) {
1823
1858
  switch (detail.type) {
1824
1859
  case "reasoning.text" /* Text */: {
@@ -1947,7 +1982,12 @@ var OpenRouterChatLanguageModel = class {
1947
1982
  type: "tool-call",
1948
1983
  toolCallId: toolCall2.id,
1949
1984
  toolName: toolCall2.function.name,
1950
- input: toolCall2.function.arguments
1985
+ input: toolCall2.function.arguments,
1986
+ providerMetadata: {
1987
+ openrouter: {
1988
+ reasoning_details: accumulatedReasoningDetails
1989
+ }
1990
+ }
1951
1991
  });
1952
1992
  toolCall2.sent = true;
1953
1993
  }
@@ -1985,7 +2025,12 @@ var OpenRouterChatLanguageModel = class {
1985
2025
  type: "tool-call",
1986
2026
  toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
1987
2027
  toolName: toolCall.function.name,
1988
- input: toolCall.function.arguments
2028
+ input: toolCall.function.arguments,
2029
+ providerMetadata: {
2030
+ openrouter: {
2031
+ reasoning_details: accumulatedReasoningDetails
2032
+ }
2033
+ }
1989
2034
  });
1990
2035
  toolCall.sent = true;
1991
2036
  }
@@ -2011,7 +2056,12 @@ var OpenRouterChatLanguageModel = class {
2011
2056
  toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId(),
2012
2057
  toolName: toolCall.function.name,
2013
2058
  // Coerce invalid arguments to an empty JSON object
2014
- input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
2059
+ input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
2060
+ providerMetadata: {
2061
+ openrouter: {
2062
+ reasoning_details: accumulatedReasoningDetails
2063
+ }
2064
+ }
2015
2065
  });
2016
2066
  toolCall.sent = true;
2017
2067
  }
@@ -2176,22 +2226,22 @@ var OpenRouterCompletionChunkSchema = z8.union([
2176
2226
  tokens: z8.array(z8.string()),
2177
2227
  token_logprobs: z8.array(z8.number()),
2178
2228
  top_logprobs: z8.array(z8.record(z8.string(), z8.number())).nullable()
2179
- }).nullable().optional()
2180
- })
2229
+ }).passthrough().nullable().optional()
2230
+ }).passthrough()
2181
2231
  ),
2182
2232
  usage: z8.object({
2183
2233
  prompt_tokens: z8.number(),
2184
2234
  prompt_tokens_details: z8.object({
2185
2235
  cached_tokens: z8.number()
2186
- }).nullish(),
2236
+ }).passthrough().nullish(),
2187
2237
  completion_tokens: z8.number(),
2188
2238
  completion_tokens_details: z8.object({
2189
2239
  reasoning_tokens: z8.number()
2190
- }).nullish(),
2240
+ }).passthrough().nullish(),
2191
2241
  total_tokens: z8.number(),
2192
2242
  cost: z8.number().optional()
2193
- }).nullish()
2194
- }),
2243
+ }).passthrough().nullish()
2244
+ }).passthrough(),
2195
2245
  OpenRouterErrorResponseSchema
2196
2246
  ]);
2197
2247
 
@@ -2287,8 +2337,9 @@ var OpenRouterCompletionLanguageModel = class {
2287
2337
  fetch: this.config.fetch
2288
2338
  });
2289
2339
  if ("error" in response) {
2340
+ const errorData = response.error;
2290
2341
  throw new APICallError({
2291
- message: response.error.message,
2342
+ message: errorData.message,
2292
2343
  url: this.config.url({
2293
2344
  path: "/completions",
2294
2345
  modelId: this.modelId
@@ -2296,7 +2347,7 @@ var OpenRouterCompletionLanguageModel = class {
2296
2347
  requestBodyValues: args,
2297
2348
  statusCode: 200,
2298
2349
  responseHeaders,
2299
- data: response.error
2350
+ data: errorData
2300
2351
  });
2301
2352
  }
2302
2353
  const choice = response.choices[0];