@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.d.mts CHANGED
@@ -217,7 +217,8 @@ declare enum ReasoningFormat {
217
217
  Unknown = "unknown",
218
218
  OpenAIResponsesV1 = "openai-responses-v1",
219
219
  XAIResponsesV1 = "xai-responses-v1",
220
- AnthropicClaudeV1 = "anthropic-claude-v1"
220
+ AnthropicClaudeV1 = "anthropic-claude-v1",
221
+ GoogleGeminiV1 = "google-gemini-v1"
221
222
  }
222
223
 
223
224
  declare enum ReasoningDetailType {
package/dist/index.d.ts CHANGED
@@ -217,7 +217,8 @@ declare enum ReasoningFormat {
217
217
  Unknown = "unknown",
218
218
  OpenAIResponsesV1 = "openai-responses-v1",
219
219
  XAIResponsesV1 = "xai-responses-v1",
220
- AnthropicClaudeV1 = "anthropic-claude-v1"
220
+ AnthropicClaudeV1 = "anthropic-claude-v1",
221
+ GoogleGeminiV1 = "google-gemini-v1"
221
222
  }
222
223
 
223
224
  declare enum ReasoningDetailType {
package/dist/index.js CHANGED
@@ -943,6 +943,7 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
943
943
  ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
944
944
  ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
945
945
  ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
946
+ ReasoningFormat2["GoogleGeminiV1"] = "google-gemini-v1";
946
947
  return ReasoningFormat2;
947
948
  })(ReasoningFormat || {});
948
949
 
@@ -951,7 +952,7 @@ var CommonReasoningDetailSchema = import_v4.z.object({
951
952
  id: import_v4.z.string().nullish(),
952
953
  format: import_v4.z.nativeEnum(ReasoningFormat).nullish(),
953
954
  index: import_v4.z.number().optional()
954
- });
955
+ }).passthrough();
955
956
  var ReasoningDetailSummarySchema = import_v4.z.object({
956
957
  type: import_v4.z.literal("reasoning.summary" /* Summary */),
957
958
  summary: import_v4.z.string()
@@ -1004,8 +1005,8 @@ var OpenRouterErrorResponseSchema = import_v42.z.object({
1004
1005
  message: import_v42.z.string(),
1005
1006
  type: import_v42.z.string().nullable().optional().default(null),
1006
1007
  param: import_v42.z.any().nullable().optional().default(null)
1007
- })
1008
- });
1008
+ }).passthrough()
1009
+ }).passthrough();
1009
1010
  var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
1010
1011
  errorSchema: OpenRouterErrorResponseSchema,
1011
1012
  errorToMessage: (data) => data.error.message
@@ -1020,18 +1021,18 @@ var OpenRouterProviderMetadataSchema = import_v43.z.object({
1020
1021
  promptTokens: import_v43.z.number(),
1021
1022
  promptTokensDetails: import_v43.z.object({
1022
1023
  cachedTokens: import_v43.z.number()
1023
- }).optional(),
1024
+ }).passthrough().optional(),
1024
1025
  completionTokens: import_v43.z.number(),
1025
1026
  completionTokensDetails: import_v43.z.object({
1026
1027
  reasoningTokens: import_v43.z.number()
1027
- }).optional(),
1028
+ }).passthrough().optional(),
1028
1029
  totalTokens: import_v43.z.number(),
1029
1030
  cost: import_v43.z.number().optional(),
1030
1031
  costDetails: import_v43.z.object({
1031
1032
  upstreamInferenceCost: import_v43.z.number()
1032
- })
1033
- })
1034
- });
1033
+ }).passthrough()
1034
+ }).passthrough()
1035
+ }).passthrough();
1035
1036
  var OpenRouterProviderOptionsSchema = import_v43.z.object({
1036
1037
  openrouter: import_v43.z.object({
1037
1038
  reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional()
@@ -1317,8 +1318,8 @@ var ImageResponseSchema = import_v45.z.object({
1317
1318
  type: import_v45.z.literal("image_url"),
1318
1319
  image_url: import_v45.z.object({
1319
1320
  url: import_v45.z.string()
1320
- })
1321
- });
1321
+ }).passthrough()
1322
+ }).passthrough();
1322
1323
  var ImageResponseWithUnknownSchema = import_v45.z.union([
1323
1324
  ImageResponseSchema,
1324
1325
  import_v45.z.unknown().transform(() => null)
@@ -1334,18 +1335,18 @@ var OpenRouterChatCompletionBaseResponseSchema = import_v46.z.object({
1334
1335
  prompt_tokens: import_v46.z.number(),
1335
1336
  prompt_tokens_details: import_v46.z.object({
1336
1337
  cached_tokens: import_v46.z.number()
1337
- }).nullish(),
1338
+ }).passthrough().nullish(),
1338
1339
  completion_tokens: import_v46.z.number(),
1339
1340
  completion_tokens_details: import_v46.z.object({
1340
1341
  reasoning_tokens: import_v46.z.number()
1341
- }).nullish(),
1342
+ }).passthrough().nullish(),
1342
1343
  total_tokens: import_v46.z.number(),
1343
1344
  cost: import_v46.z.number().optional(),
1344
1345
  cost_details: import_v46.z.object({
1345
1346
  upstream_inference_cost: import_v46.z.number().nullish()
1346
- }).nullish()
1347
- }).nullish()
1348
- });
1347
+ }).passthrough().nullish()
1348
+ }).passthrough().nullish()
1349
+ }).passthrough();
1349
1350
  var OpenRouterNonStreamChatCompletionResponseSchema = import_v46.z.union([
1350
1351
  // Success response with choices
1351
1352
  OpenRouterChatCompletionBaseResponseSchema.extend({
@@ -1364,8 +1365,8 @@ var OpenRouterNonStreamChatCompletionResponseSchema = import_v46.z.union([
1364
1365
  function: import_v46.z.object({
1365
1366
  name: import_v46.z.string(),
1366
1367
  arguments: import_v46.z.string()
1367
- })
1368
- })
1368
+ }).passthrough()
1369
+ }).passthrough()
1369
1370
  ).optional(),
1370
1371
  annotations: import_v46.z.array(
1371
1372
  import_v46.z.union([
@@ -1378,16 +1379,16 @@ var OpenRouterNonStreamChatCompletionResponseSchema = import_v46.z.union([
1378
1379
  title: import_v46.z.string(),
1379
1380
  url: import_v46.z.string(),
1380
1381
  content: import_v46.z.string().optional()
1381
- })
1382
- }),
1382
+ }).passthrough()
1383
+ }).passthrough(),
1383
1384
  // File annotation from FileParserPlugin (old format)
1384
1385
  import_v46.z.object({
1385
1386
  type: import_v46.z.literal("file_annotation"),
1386
1387
  file_annotation: import_v46.z.object({
1387
1388
  file_id: import_v46.z.string(),
1388
1389
  quote: import_v46.z.string().optional()
1389
- })
1390
- }),
1390
+ }).passthrough()
1391
+ }).passthrough(),
1391
1392
  // File annotation from FileParserPlugin (new format)
1392
1393
  import_v46.z.object({
1393
1394
  type: import_v46.z.literal("file"),
@@ -1398,13 +1399,13 @@ var OpenRouterNonStreamChatCompletionResponseSchema = import_v46.z.union([
1398
1399
  import_v46.z.object({
1399
1400
  type: import_v46.z.string(),
1400
1401
  text: import_v46.z.string()
1401
- })
1402
+ }).passthrough()
1402
1403
  ).optional()
1403
- })
1404
- })
1404
+ }).passthrough()
1405
+ }).passthrough()
1405
1406
  ])
1406
1407
  ).nullish()
1407
- }),
1408
+ }).passthrough(),
1408
1409
  index: import_v46.z.number().nullish(),
1409
1410
  logprobs: import_v46.z.object({
1410
1411
  content: import_v46.z.array(
@@ -1415,13 +1416,13 @@ var OpenRouterNonStreamChatCompletionResponseSchema = import_v46.z.union([
1415
1416
  import_v46.z.object({
1416
1417
  token: import_v46.z.string(),
1417
1418
  logprob: import_v46.z.number()
1418
- })
1419
+ }).passthrough()
1419
1420
  )
1420
- })
1421
+ }).passthrough()
1421
1422
  ).nullable()
1422
- }).nullable().optional(),
1423
+ }).passthrough().nullable().optional(),
1423
1424
  finish_reason: import_v46.z.string().optional().nullable()
1424
- })
1425
+ }).passthrough()
1425
1426
  )
1426
1427
  }),
1427
1428
  // Error response (HTTP 200 with error payload)
@@ -1447,8 +1448,8 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
1447
1448
  function: import_v46.z.object({
1448
1449
  name: import_v46.z.string().nullish(),
1449
1450
  arguments: import_v46.z.string().nullish()
1450
- })
1451
- })
1451
+ }).passthrough()
1452
+ }).passthrough()
1452
1453
  ).nullish(),
1453
1454
  annotations: import_v46.z.array(
1454
1455
  import_v46.z.union([
@@ -1461,16 +1462,16 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
1461
1462
  title: import_v46.z.string(),
1462
1463
  url: import_v46.z.string(),
1463
1464
  content: import_v46.z.string().optional()
1464
- })
1465
- }),
1465
+ }).passthrough()
1466
+ }).passthrough(),
1466
1467
  // File annotation from FileParserPlugin (old format)
1467
1468
  import_v46.z.object({
1468
1469
  type: import_v46.z.literal("file_annotation"),
1469
1470
  file_annotation: import_v46.z.object({
1470
1471
  file_id: import_v46.z.string(),
1471
1472
  quote: import_v46.z.string().optional()
1472
- })
1473
- }),
1473
+ }).passthrough()
1474
+ }).passthrough(),
1474
1475
  // File annotation from FileParserPlugin (new format)
1475
1476
  import_v46.z.object({
1476
1477
  type: import_v46.z.literal("file"),
@@ -1481,13 +1482,13 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
1481
1482
  import_v46.z.object({
1482
1483
  type: import_v46.z.string(),
1483
1484
  text: import_v46.z.string()
1484
- })
1485
+ }).passthrough()
1485
1486
  ).optional()
1486
- })
1487
- })
1487
+ }).passthrough()
1488
+ }).passthrough()
1488
1489
  ])
1489
1490
  ).nullish()
1490
- }).nullish(),
1491
+ }).passthrough().nullish(),
1491
1492
  logprobs: import_v46.z.object({
1492
1493
  content: import_v46.z.array(
1493
1494
  import_v46.z.object({
@@ -1497,14 +1498,14 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
1497
1498
  import_v46.z.object({
1498
1499
  token: import_v46.z.string(),
1499
1500
  logprob: import_v46.z.number()
1500
- })
1501
+ }).passthrough()
1501
1502
  )
1502
- })
1503
+ }).passthrough()
1503
1504
  ).nullable()
1504
- }).nullish(),
1505
+ }).passthrough().nullish(),
1505
1506
  finish_reason: import_v46.z.string().nullable().optional(),
1506
1507
  index: import_v46.z.number().nullish()
1507
- })
1508
+ }).passthrough()
1508
1509
  )
1509
1510
  }),
1510
1511
  OpenRouterErrorResponseSchema
@@ -1590,7 +1591,9 @@ var OpenRouterChatLanguageModel = class {
1590
1591
  });
1591
1592
  }
1592
1593
  if (tools && tools.length > 0) {
1593
- const mappedTools = tools.filter((tool) => tool.type === "function").map((tool) => ({
1594
+ const mappedTools = tools.filter(
1595
+ (tool) => tool.type === "function"
1596
+ ).map((tool) => ({
1594
1597
  type: "function",
1595
1598
  function: {
1596
1599
  name: tool.name,
@@ -1625,8 +1628,9 @@ var OpenRouterChatLanguageModel = class {
1625
1628
  fetch: this.config.fetch
1626
1629
  });
1627
1630
  if ("error" in responseValue) {
1631
+ const errorData = responseValue.error;
1628
1632
  throw new APICallError({
1629
- message: responseValue.error.message,
1633
+ message: errorData.message,
1630
1634
  url: this.config.url({
1631
1635
  path: "/chat/completions",
1632
1636
  modelId: this.modelId
@@ -1634,7 +1638,7 @@ var OpenRouterChatLanguageModel = class {
1634
1638
  requestBodyValues: args,
1635
1639
  statusCode: 200,
1636
1640
  responseHeaders,
1637
- data: responseValue.error
1641
+ data: errorData
1638
1642
  });
1639
1643
  }
1640
1644
  const response = responseValue;
@@ -1664,7 +1668,12 @@ var OpenRouterChatLanguageModel = class {
1664
1668
  if (detail.text) {
1665
1669
  return {
1666
1670
  type: "reasoning",
1667
- text: detail.text
1671
+ text: detail.text,
1672
+ providerMetadata: {
1673
+ openrouter: {
1674
+ reasoning_details: [detail]
1675
+ }
1676
+ }
1668
1677
  };
1669
1678
  }
1670
1679
  break;
@@ -1673,7 +1682,12 @@ var OpenRouterChatLanguageModel = class {
1673
1682
  if (detail.summary) {
1674
1683
  return {
1675
1684
  type: "reasoning",
1676
- text: detail.summary
1685
+ text: detail.summary,
1686
+ providerMetadata: {
1687
+ openrouter: {
1688
+ reasoning_details: [detail]
1689
+ }
1690
+ }
1677
1691
  };
1678
1692
  }
1679
1693
  break;
@@ -1682,7 +1696,12 @@ var OpenRouterChatLanguageModel = class {
1682
1696
  if (detail.data) {
1683
1697
  return {
1684
1698
  type: "reasoning",
1685
- text: "[REDACTED]"
1699
+ text: "[REDACTED]",
1700
+ providerMetadata: {
1701
+ openrouter: {
1702
+ reasoning_details: [detail]
1703
+ }
1704
+ }
1686
1705
  };
1687
1706
  }
1688
1707
  break;
@@ -1712,7 +1731,12 @@ var OpenRouterChatLanguageModel = class {
1712
1731
  type: "tool-call",
1713
1732
  toolCallId: (_j = toolCall.id) != null ? _j : generateId(),
1714
1733
  toolName: toolCall.function.name,
1715
- input: toolCall.function.arguments
1734
+ input: toolCall.function.arguments,
1735
+ providerMetadata: {
1736
+ openrouter: {
1737
+ reasoning_details: reasoningDetails
1738
+ }
1739
+ }
1716
1740
  });
1717
1741
  }
1718
1742
  }
@@ -1898,7 +1922,18 @@ var OpenRouterChatLanguageModel = class {
1898
1922
  });
1899
1923
  };
1900
1924
  if (delta.reasoning_details && delta.reasoning_details.length > 0) {
1901
- accumulatedReasoningDetails.push(...delta.reasoning_details);
1925
+ for (const detail of delta.reasoning_details) {
1926
+ if (detail.type === "reasoning.text" /* Text */) {
1927
+ const lastDetail = accumulatedReasoningDetails[accumulatedReasoningDetails.length - 1];
1928
+ if ((lastDetail == null ? void 0 : lastDetail.type) === "reasoning.text" /* Text */) {
1929
+ lastDetail.text = (lastDetail.text || "") + (detail.text || "");
1930
+ } else {
1931
+ accumulatedReasoningDetails.push(__spreadValues({}, detail));
1932
+ }
1933
+ } else {
1934
+ accumulatedReasoningDetails.push(detail);
1935
+ }
1936
+ }
1902
1937
  for (const detail of delta.reasoning_details) {
1903
1938
  switch (detail.type) {
1904
1939
  case "reasoning.text" /* Text */: {
@@ -2027,7 +2062,12 @@ var OpenRouterChatLanguageModel = class {
2027
2062
  type: "tool-call",
2028
2063
  toolCallId: toolCall2.id,
2029
2064
  toolName: toolCall2.function.name,
2030
- input: toolCall2.function.arguments
2065
+ input: toolCall2.function.arguments,
2066
+ providerMetadata: {
2067
+ openrouter: {
2068
+ reasoning_details: accumulatedReasoningDetails
2069
+ }
2070
+ }
2031
2071
  });
2032
2072
  toolCall2.sent = true;
2033
2073
  }
@@ -2065,7 +2105,12 @@ var OpenRouterChatLanguageModel = class {
2065
2105
  type: "tool-call",
2066
2106
  toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
2067
2107
  toolName: toolCall.function.name,
2068
- input: toolCall.function.arguments
2108
+ input: toolCall.function.arguments,
2109
+ providerMetadata: {
2110
+ openrouter: {
2111
+ reasoning_details: accumulatedReasoningDetails
2112
+ }
2113
+ }
2069
2114
  });
2070
2115
  toolCall.sent = true;
2071
2116
  }
@@ -2091,7 +2136,12 @@ var OpenRouterChatLanguageModel = class {
2091
2136
  toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId(),
2092
2137
  toolName: toolCall.function.name,
2093
2138
  // Coerce invalid arguments to an empty JSON object
2094
- input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
2139
+ input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
2140
+ providerMetadata: {
2141
+ openrouter: {
2142
+ reasoning_details: accumulatedReasoningDetails
2143
+ }
2144
+ }
2095
2145
  });
2096
2146
  toolCall.sent = true;
2097
2147
  }
@@ -2256,22 +2306,22 @@ var OpenRouterCompletionChunkSchema = import_v47.z.union([
2256
2306
  tokens: import_v47.z.array(import_v47.z.string()),
2257
2307
  token_logprobs: import_v47.z.array(import_v47.z.number()),
2258
2308
  top_logprobs: import_v47.z.array(import_v47.z.record(import_v47.z.string(), import_v47.z.number())).nullable()
2259
- }).nullable().optional()
2260
- })
2309
+ }).passthrough().nullable().optional()
2310
+ }).passthrough()
2261
2311
  ),
2262
2312
  usage: import_v47.z.object({
2263
2313
  prompt_tokens: import_v47.z.number(),
2264
2314
  prompt_tokens_details: import_v47.z.object({
2265
2315
  cached_tokens: import_v47.z.number()
2266
- }).nullish(),
2316
+ }).passthrough().nullish(),
2267
2317
  completion_tokens: import_v47.z.number(),
2268
2318
  completion_tokens_details: import_v47.z.object({
2269
2319
  reasoning_tokens: import_v47.z.number()
2270
- }).nullish(),
2320
+ }).passthrough().nullish(),
2271
2321
  total_tokens: import_v47.z.number(),
2272
2322
  cost: import_v47.z.number().optional()
2273
- }).nullish()
2274
- }),
2323
+ }).passthrough().nullish()
2324
+ }).passthrough(),
2275
2325
  OpenRouterErrorResponseSchema
2276
2326
  ]);
2277
2327
 
@@ -2367,8 +2417,9 @@ var OpenRouterCompletionLanguageModel = class {
2367
2417
  fetch: this.config.fetch
2368
2418
  });
2369
2419
  if ("error" in response) {
2420
+ const errorData = response.error;
2370
2421
  throw new APICallError({
2371
- message: response.error.message,
2422
+ message: errorData.message,
2372
2423
  url: this.config.url({
2373
2424
  path: "/completions",
2374
2425
  modelId: this.modelId
@@ -2376,7 +2427,7 @@ var OpenRouterCompletionLanguageModel = class {
2376
2427
  requestBodyValues: args,
2377
2428
  statusCode: 200,
2378
2429
  responseHeaders,
2379
- data: response.error
2430
+ data: errorData
2380
2431
  });
2381
2432
  }
2382
2433
  const choice = response.choices[0];
@@ -2570,7 +2621,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
2570
2621
  }
2571
2622
 
2572
2623
  // src/version.ts
2573
- var VERSION = false ? "0.0.0-test" : "1.2.2";
2624
+ var VERSION = false ? "0.0.0-test" : "1.2.4";
2574
2625
 
2575
2626
  // src/provider.ts
2576
2627
  function createOpenRouter(options = {}) {