@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.
package/dist/index.mjs CHANGED
@@ -908,6 +908,7 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
908
908
  ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
909
909
  ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
910
910
  ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
911
+ ReasoningFormat2["GoogleGeminiV1"] = "google-gemini-v1";
911
912
  return ReasoningFormat2;
912
913
  })(ReasoningFormat || {});
913
914
 
@@ -916,7 +917,7 @@ var CommonReasoningDetailSchema = z.object({
916
917
  id: z.string().nullish(),
917
918
  format: z.nativeEnum(ReasoningFormat).nullish(),
918
919
  index: z.number().optional()
919
- });
920
+ }).passthrough();
920
921
  var ReasoningDetailSummarySchema = z.object({
921
922
  type: z.literal("reasoning.summary" /* Summary */),
922
923
  summary: z.string()
@@ -969,8 +970,8 @@ var OpenRouterErrorResponseSchema = z2.object({
969
970
  message: z2.string(),
970
971
  type: z2.string().nullable().optional().default(null),
971
972
  param: z2.any().nullable().optional().default(null)
972
- })
973
- });
973
+ }).passthrough()
974
+ }).passthrough();
974
975
  var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
975
976
  errorSchema: OpenRouterErrorResponseSchema,
976
977
  errorToMessage: (data) => data.error.message
@@ -985,18 +986,18 @@ var OpenRouterProviderMetadataSchema = z3.object({
985
986
  promptTokens: z3.number(),
986
987
  promptTokensDetails: z3.object({
987
988
  cachedTokens: z3.number()
988
- }).optional(),
989
+ }).passthrough().optional(),
989
990
  completionTokens: z3.number(),
990
991
  completionTokensDetails: z3.object({
991
992
  reasoningTokens: z3.number()
992
- }).optional(),
993
+ }).passthrough().optional(),
993
994
  totalTokens: z3.number(),
994
995
  cost: z3.number().optional(),
995
996
  costDetails: z3.object({
996
997
  upstreamInferenceCost: z3.number()
997
- })
998
- })
999
- });
998
+ }).passthrough()
999
+ }).passthrough()
1000
+ }).passthrough();
1000
1001
  var OpenRouterProviderOptionsSchema = z3.object({
1001
1002
  openrouter: z3.object({
1002
1003
  reasoning_details: z3.array(ReasoningDetailUnionSchema).optional()
@@ -1282,8 +1283,8 @@ var ImageResponseSchema = z6.object({
1282
1283
  type: z6.literal("image_url"),
1283
1284
  image_url: z6.object({
1284
1285
  url: z6.string()
1285
- })
1286
- });
1286
+ }).passthrough()
1287
+ }).passthrough();
1287
1288
  var ImageResponseWithUnknownSchema = z6.union([
1288
1289
  ImageResponseSchema,
1289
1290
  z6.unknown().transform(() => null)
@@ -1299,18 +1300,18 @@ var OpenRouterChatCompletionBaseResponseSchema = z7.object({
1299
1300
  prompt_tokens: z7.number(),
1300
1301
  prompt_tokens_details: z7.object({
1301
1302
  cached_tokens: z7.number()
1302
- }).nullish(),
1303
+ }).passthrough().nullish(),
1303
1304
  completion_tokens: z7.number(),
1304
1305
  completion_tokens_details: z7.object({
1305
1306
  reasoning_tokens: z7.number()
1306
- }).nullish(),
1307
+ }).passthrough().nullish(),
1307
1308
  total_tokens: z7.number(),
1308
1309
  cost: z7.number().optional(),
1309
1310
  cost_details: z7.object({
1310
1311
  upstream_inference_cost: z7.number().nullish()
1311
- }).nullish()
1312
- }).nullish()
1313
- });
1312
+ }).passthrough().nullish()
1313
+ }).passthrough().nullish()
1314
+ }).passthrough();
1314
1315
  var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1315
1316
  // Success response with choices
1316
1317
  OpenRouterChatCompletionBaseResponseSchema.extend({
@@ -1329,8 +1330,8 @@ var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1329
1330
  function: z7.object({
1330
1331
  name: z7.string(),
1331
1332
  arguments: z7.string()
1332
- })
1333
- })
1333
+ }).passthrough()
1334
+ }).passthrough()
1334
1335
  ).optional(),
1335
1336
  annotations: z7.array(
1336
1337
  z7.union([
@@ -1343,16 +1344,16 @@ var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1343
1344
  title: z7.string(),
1344
1345
  url: z7.string(),
1345
1346
  content: z7.string().optional()
1346
- })
1347
- }),
1347
+ }).passthrough()
1348
+ }).passthrough(),
1348
1349
  // File annotation from FileParserPlugin (old format)
1349
1350
  z7.object({
1350
1351
  type: z7.literal("file_annotation"),
1351
1352
  file_annotation: z7.object({
1352
1353
  file_id: z7.string(),
1353
1354
  quote: z7.string().optional()
1354
- })
1355
- }),
1355
+ }).passthrough()
1356
+ }).passthrough(),
1356
1357
  // File annotation from FileParserPlugin (new format)
1357
1358
  z7.object({
1358
1359
  type: z7.literal("file"),
@@ -1363,13 +1364,13 @@ var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1363
1364
  z7.object({
1364
1365
  type: z7.string(),
1365
1366
  text: z7.string()
1366
- })
1367
+ }).passthrough()
1367
1368
  ).optional()
1368
- })
1369
- })
1369
+ }).passthrough()
1370
+ }).passthrough()
1370
1371
  ])
1371
1372
  ).nullish()
1372
- }),
1373
+ }).passthrough(),
1373
1374
  index: z7.number().nullish(),
1374
1375
  logprobs: z7.object({
1375
1376
  content: z7.array(
@@ -1380,13 +1381,13 @@ var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1380
1381
  z7.object({
1381
1382
  token: z7.string(),
1382
1383
  logprob: z7.number()
1383
- })
1384
+ }).passthrough()
1384
1385
  )
1385
- })
1386
+ }).passthrough()
1386
1387
  ).nullable()
1387
- }).nullable().optional(),
1388
+ }).passthrough().nullable().optional(),
1388
1389
  finish_reason: z7.string().optional().nullable()
1389
- })
1390
+ }).passthrough()
1390
1391
  )
1391
1392
  }),
1392
1393
  // Error response (HTTP 200 with error payload)
@@ -1412,8 +1413,8 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
1412
1413
  function: z7.object({
1413
1414
  name: z7.string().nullish(),
1414
1415
  arguments: z7.string().nullish()
1415
- })
1416
- })
1416
+ }).passthrough()
1417
+ }).passthrough()
1417
1418
  ).nullish(),
1418
1419
  annotations: z7.array(
1419
1420
  z7.union([
@@ -1426,16 +1427,16 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
1426
1427
  title: z7.string(),
1427
1428
  url: z7.string(),
1428
1429
  content: z7.string().optional()
1429
- })
1430
- }),
1430
+ }).passthrough()
1431
+ }).passthrough(),
1431
1432
  // File annotation from FileParserPlugin (old format)
1432
1433
  z7.object({
1433
1434
  type: z7.literal("file_annotation"),
1434
1435
  file_annotation: z7.object({
1435
1436
  file_id: z7.string(),
1436
1437
  quote: z7.string().optional()
1437
- })
1438
- }),
1438
+ }).passthrough()
1439
+ }).passthrough(),
1439
1440
  // File annotation from FileParserPlugin (new format)
1440
1441
  z7.object({
1441
1442
  type: z7.literal("file"),
@@ -1446,13 +1447,13 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
1446
1447
  z7.object({
1447
1448
  type: z7.string(),
1448
1449
  text: z7.string()
1449
- })
1450
+ }).passthrough()
1450
1451
  ).optional()
1451
- })
1452
- })
1452
+ }).passthrough()
1453
+ }).passthrough()
1453
1454
  ])
1454
1455
  ).nullish()
1455
- }).nullish(),
1456
+ }).passthrough().nullish(),
1456
1457
  logprobs: z7.object({
1457
1458
  content: z7.array(
1458
1459
  z7.object({
@@ -1462,14 +1463,14 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
1462
1463
  z7.object({
1463
1464
  token: z7.string(),
1464
1465
  logprob: z7.number()
1465
- })
1466
+ }).passthrough()
1466
1467
  )
1467
- })
1468
+ }).passthrough()
1468
1469
  ).nullable()
1469
- }).nullish(),
1470
+ }).passthrough().nullish(),
1470
1471
  finish_reason: z7.string().nullable().optional(),
1471
1472
  index: z7.number().nullish()
1472
- })
1473
+ }).passthrough()
1473
1474
  )
1474
1475
  }),
1475
1476
  OpenRouterErrorResponseSchema
@@ -1555,7 +1556,9 @@ var OpenRouterChatLanguageModel = class {
1555
1556
  });
1556
1557
  }
1557
1558
  if (tools && tools.length > 0) {
1558
- const mappedTools = tools.filter((tool) => tool.type === "function").map((tool) => ({
1559
+ const mappedTools = tools.filter(
1560
+ (tool) => tool.type === "function"
1561
+ ).map((tool) => ({
1559
1562
  type: "function",
1560
1563
  function: {
1561
1564
  name: tool.name,
@@ -1590,8 +1593,9 @@ var OpenRouterChatLanguageModel = class {
1590
1593
  fetch: this.config.fetch
1591
1594
  });
1592
1595
  if ("error" in responseValue) {
1596
+ const errorData = responseValue.error;
1593
1597
  throw new APICallError({
1594
- message: responseValue.error.message,
1598
+ message: errorData.message,
1595
1599
  url: this.config.url({
1596
1600
  path: "/chat/completions",
1597
1601
  modelId: this.modelId
@@ -1599,7 +1603,7 @@ var OpenRouterChatLanguageModel = class {
1599
1603
  requestBodyValues: args,
1600
1604
  statusCode: 200,
1601
1605
  responseHeaders,
1602
- data: responseValue.error
1606
+ data: errorData
1603
1607
  });
1604
1608
  }
1605
1609
  const response = responseValue;
@@ -1629,7 +1633,12 @@ var OpenRouterChatLanguageModel = class {
1629
1633
  if (detail.text) {
1630
1634
  return {
1631
1635
  type: "reasoning",
1632
- text: detail.text
1636
+ text: detail.text,
1637
+ providerMetadata: {
1638
+ openrouter: {
1639
+ reasoning_details: [detail]
1640
+ }
1641
+ }
1633
1642
  };
1634
1643
  }
1635
1644
  break;
@@ -1638,7 +1647,12 @@ var OpenRouterChatLanguageModel = class {
1638
1647
  if (detail.summary) {
1639
1648
  return {
1640
1649
  type: "reasoning",
1641
- text: detail.summary
1650
+ text: detail.summary,
1651
+ providerMetadata: {
1652
+ openrouter: {
1653
+ reasoning_details: [detail]
1654
+ }
1655
+ }
1642
1656
  };
1643
1657
  }
1644
1658
  break;
@@ -1647,7 +1661,12 @@ var OpenRouterChatLanguageModel = class {
1647
1661
  if (detail.data) {
1648
1662
  return {
1649
1663
  type: "reasoning",
1650
- text: "[REDACTED]"
1664
+ text: "[REDACTED]",
1665
+ providerMetadata: {
1666
+ openrouter: {
1667
+ reasoning_details: [detail]
1668
+ }
1669
+ }
1651
1670
  };
1652
1671
  }
1653
1672
  break;
@@ -1677,7 +1696,12 @@ var OpenRouterChatLanguageModel = class {
1677
1696
  type: "tool-call",
1678
1697
  toolCallId: (_j = toolCall.id) != null ? _j : generateId(),
1679
1698
  toolName: toolCall.function.name,
1680
- input: toolCall.function.arguments
1699
+ input: toolCall.function.arguments,
1700
+ providerMetadata: {
1701
+ openrouter: {
1702
+ reasoning_details: reasoningDetails
1703
+ }
1704
+ }
1681
1705
  });
1682
1706
  }
1683
1707
  }
@@ -1863,7 +1887,18 @@ var OpenRouterChatLanguageModel = class {
1863
1887
  });
1864
1888
  };
1865
1889
  if (delta.reasoning_details && delta.reasoning_details.length > 0) {
1866
- accumulatedReasoningDetails.push(...delta.reasoning_details);
1890
+ for (const detail of delta.reasoning_details) {
1891
+ if (detail.type === "reasoning.text" /* Text */) {
1892
+ const lastDetail = accumulatedReasoningDetails[accumulatedReasoningDetails.length - 1];
1893
+ if ((lastDetail == null ? void 0 : lastDetail.type) === "reasoning.text" /* Text */) {
1894
+ lastDetail.text = (lastDetail.text || "") + (detail.text || "");
1895
+ } else {
1896
+ accumulatedReasoningDetails.push(__spreadValues({}, detail));
1897
+ }
1898
+ } else {
1899
+ accumulatedReasoningDetails.push(detail);
1900
+ }
1901
+ }
1867
1902
  for (const detail of delta.reasoning_details) {
1868
1903
  switch (detail.type) {
1869
1904
  case "reasoning.text" /* Text */: {
@@ -1992,7 +2027,12 @@ var OpenRouterChatLanguageModel = class {
1992
2027
  type: "tool-call",
1993
2028
  toolCallId: toolCall2.id,
1994
2029
  toolName: toolCall2.function.name,
1995
- input: toolCall2.function.arguments
2030
+ input: toolCall2.function.arguments,
2031
+ providerMetadata: {
2032
+ openrouter: {
2033
+ reasoning_details: accumulatedReasoningDetails
2034
+ }
2035
+ }
1996
2036
  });
1997
2037
  toolCall2.sent = true;
1998
2038
  }
@@ -2030,7 +2070,12 @@ var OpenRouterChatLanguageModel = class {
2030
2070
  type: "tool-call",
2031
2071
  toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
2032
2072
  toolName: toolCall.function.name,
2033
- input: toolCall.function.arguments
2073
+ input: toolCall.function.arguments,
2074
+ providerMetadata: {
2075
+ openrouter: {
2076
+ reasoning_details: accumulatedReasoningDetails
2077
+ }
2078
+ }
2034
2079
  });
2035
2080
  toolCall.sent = true;
2036
2081
  }
@@ -2056,7 +2101,12 @@ var OpenRouterChatLanguageModel = class {
2056
2101
  toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId(),
2057
2102
  toolName: toolCall.function.name,
2058
2103
  // Coerce invalid arguments to an empty JSON object
2059
- input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
2104
+ input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
2105
+ providerMetadata: {
2106
+ openrouter: {
2107
+ reasoning_details: accumulatedReasoningDetails
2108
+ }
2109
+ }
2060
2110
  });
2061
2111
  toolCall.sent = true;
2062
2112
  }
@@ -2221,22 +2271,22 @@ var OpenRouterCompletionChunkSchema = z8.union([
2221
2271
  tokens: z8.array(z8.string()),
2222
2272
  token_logprobs: z8.array(z8.number()),
2223
2273
  top_logprobs: z8.array(z8.record(z8.string(), z8.number())).nullable()
2224
- }).nullable().optional()
2225
- })
2274
+ }).passthrough().nullable().optional()
2275
+ }).passthrough()
2226
2276
  ),
2227
2277
  usage: z8.object({
2228
2278
  prompt_tokens: z8.number(),
2229
2279
  prompt_tokens_details: z8.object({
2230
2280
  cached_tokens: z8.number()
2231
- }).nullish(),
2281
+ }).passthrough().nullish(),
2232
2282
  completion_tokens: z8.number(),
2233
2283
  completion_tokens_details: z8.object({
2234
2284
  reasoning_tokens: z8.number()
2235
- }).nullish(),
2285
+ }).passthrough().nullish(),
2236
2286
  total_tokens: z8.number(),
2237
2287
  cost: z8.number().optional()
2238
- }).nullish()
2239
- }),
2288
+ }).passthrough().nullish()
2289
+ }).passthrough(),
2240
2290
  OpenRouterErrorResponseSchema
2241
2291
  ]);
2242
2292
 
@@ -2332,8 +2382,9 @@ var OpenRouterCompletionLanguageModel = class {
2332
2382
  fetch: this.config.fetch
2333
2383
  });
2334
2384
  if ("error" in response) {
2385
+ const errorData = response.error;
2335
2386
  throw new APICallError({
2336
- message: response.error.message,
2387
+ message: errorData.message,
2337
2388
  url: this.config.url({
2338
2389
  path: "/completions",
2339
2390
  modelId: this.modelId
@@ -2341,7 +2392,7 @@ var OpenRouterCompletionLanguageModel = class {
2341
2392
  requestBodyValues: args,
2342
2393
  statusCode: 200,
2343
2394
  responseHeaders,
2344
- data: response.error
2395
+ data: errorData
2345
2396
  });
2346
2397
  }
2347
2398
  const choice = response.choices[0];
@@ -2535,7 +2586,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
2535
2586
  }
2536
2587
 
2537
2588
  // src/version.ts
2538
- var VERSION = false ? "0.0.0-test" : "1.2.2";
2589
+ var VERSION = false ? "0.0.0-test" : "1.2.4";
2539
2590
 
2540
2591
  // src/provider.ts
2541
2592
  function createOpenRouter(options = {}) {