@openrouter/ai-sdk-provider 1.0.0 → 1.1.0

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
@@ -1188,6 +1188,7 @@ import { z as z5 } from "zod/v4";
1188
1188
  var OpenRouterChatCompletionBaseResponseSchema = z5.object({
1189
1189
  id: z5.string().optional(),
1190
1190
  model: z5.string().optional(),
1191
+ provider: z5.string().optional(),
1191
1192
  usage: z5.object({
1192
1193
  prompt_tokens: z5.number(),
1193
1194
  prompt_tokens_details: z5.object({
@@ -1221,7 +1222,19 @@ var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBa
1221
1222
  arguments: z5.string()
1222
1223
  })
1223
1224
  })
1224
- ).optional()
1225
+ ).optional(),
1226
+ annotations: z5.array(
1227
+ z5.object({
1228
+ type: z5.enum(["url_citation"]),
1229
+ url_citation: z5.object({
1230
+ end_index: z5.number(),
1231
+ start_index: z5.number(),
1232
+ title: z5.string(),
1233
+ url: z5.string(),
1234
+ content: z5.string().optional()
1235
+ })
1236
+ })
1237
+ ).nullish()
1225
1238
  }),
1226
1239
  index: z5.number().nullish(),
1227
1240
  logprobs: z5.object({
@@ -1261,6 +1274,18 @@ var OpenRouterStreamChatCompletionChunkSchema = z5.union([
1261
1274
  arguments: z5.string().nullish()
1262
1275
  })
1263
1276
  })
1277
+ ).nullish(),
1278
+ annotations: z5.array(
1279
+ z5.object({
1280
+ type: z5.enum(["url_citation"]),
1281
+ url_citation: z5.object({
1282
+ end_index: z5.number(),
1283
+ start_index: z5.number(),
1284
+ title: z5.string(),
1285
+ url: z5.string(),
1286
+ content: z5.string().optional()
1287
+ })
1288
+ })
1264
1289
  ).nullish()
1265
1290
  }).nullish(),
1266
1291
  logprobs: z5.object({
@@ -1343,7 +1368,12 @@ var OpenRouterChatLanguageModel = class {
1343
1368
  // OpenRouter specific settings:
1344
1369
  include_reasoning: this.settings.includeReasoning,
1345
1370
  reasoning: this.settings.reasoning,
1346
- usage: this.settings.usage
1371
+ usage: this.settings.usage,
1372
+ // Web search settings:
1373
+ plugins: this.settings.plugins,
1374
+ web_search_options: this.settings.web_search_options,
1375
+ // Provider routing settings:
1376
+ provider: this.settings.provider
1347
1377
  }, this.config.extraBody), this.settings.extraBody);
1348
1378
  if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
1349
1379
  return __spreadProps(__spreadValues({}, baseArgs), {
@@ -1376,7 +1406,7 @@ var OpenRouterChatLanguageModel = class {
1376
1406
  return baseArgs;
1377
1407
  }
1378
1408
  async doGenerate(options) {
1379
- var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1409
+ 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;
1380
1410
  const providerOptions = options.providerOptions || {};
1381
1411
  const openrouterOptions = providerOptions.openrouter || {};
1382
1412
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
@@ -1470,6 +1500,24 @@ var OpenRouterChatLanguageModel = class {
1470
1500
  });
1471
1501
  }
1472
1502
  }
1503
+ if (choice.message.annotations) {
1504
+ for (const annotation of choice.message.annotations) {
1505
+ if (annotation.type === "url_citation") {
1506
+ content.push({
1507
+ type: "source",
1508
+ sourceType: "url",
1509
+ id: annotation.url_citation.url,
1510
+ url: annotation.url_citation.url,
1511
+ title: annotation.url_citation.title,
1512
+ providerMetadata: {
1513
+ openrouter: {
1514
+ content: annotation.url_citation.content || ""
1515
+ }
1516
+ }
1517
+ });
1518
+ }
1519
+ }
1520
+ }
1473
1521
  return {
1474
1522
  content,
1475
1523
  finishReason: mapOpenRouterFinishReason(choice.finish_reason),
@@ -1477,19 +1525,20 @@ var OpenRouterChatLanguageModel = class {
1477
1525
  warnings: [],
1478
1526
  providerMetadata: {
1479
1527
  openrouter: {
1528
+ provider: (_k = response.provider) != null ? _k : "",
1480
1529
  usage: {
1481
- promptTokens: (_k = usageInfo.inputTokens) != null ? _k : 0,
1482
- completionTokens: (_l = usageInfo.outputTokens) != null ? _l : 0,
1483
- totalTokens: (_m = usageInfo.totalTokens) != null ? _m : 0,
1484
- cost: (_n = response.usage) == null ? void 0 : _n.cost,
1530
+ promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
1531
+ completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
1532
+ totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
1533
+ cost: (_o = response.usage) == null ? void 0 : _o.cost,
1485
1534
  promptTokensDetails: {
1486
- cachedTokens: (_q = (_p = (_o = response.usage) == null ? void 0 : _o.prompt_tokens_details) == null ? void 0 : _p.cached_tokens) != null ? _q : 0
1535
+ cachedTokens: (_r = (_q = (_p = response.usage) == null ? void 0 : _p.prompt_tokens_details) == null ? void 0 : _q.cached_tokens) != null ? _r : 0
1487
1536
  },
1488
1537
  completionTokensDetails: {
1489
- reasoningTokens: (_t = (_s = (_r = response.usage) == null ? void 0 : _r.completion_tokens_details) == null ? void 0 : _s.reasoning_tokens) != null ? _t : 0
1538
+ reasoningTokens: (_u = (_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? _u : 0
1490
1539
  },
1491
1540
  costDetails: {
1492
- upstreamInferenceCost: (_w = (_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? _w : 0
1541
+ upstreamInferenceCost: (_x = (_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? _x : 0
1493
1542
  }
1494
1543
  }
1495
1544
  }
@@ -1542,6 +1591,7 @@ var OpenRouterChatLanguageModel = class {
1542
1591
  let textId;
1543
1592
  let reasoningId;
1544
1593
  let openrouterResponseId;
1594
+ let provider;
1545
1595
  return {
1546
1596
  stream: response.pipeThrough(
1547
1597
  new TransformStream({
@@ -1558,6 +1608,9 @@ var OpenRouterChatLanguageModel = class {
1558
1608
  controller.enqueue({ type: "error", error: value.error });
1559
1609
  return;
1560
1610
  }
1611
+ if (value.provider) {
1612
+ provider = value.provider;
1613
+ }
1561
1614
  if (value.id) {
1562
1615
  openrouterResponseId = value.id;
1563
1616
  controller.enqueue({
@@ -1669,6 +1722,24 @@ var OpenRouterChatLanguageModel = class {
1669
1722
  id: textId || generateId()
1670
1723
  });
1671
1724
  }
1725
+ if (delta.annotations) {
1726
+ for (const annotation of delta.annotations) {
1727
+ if (annotation.type === "url_citation") {
1728
+ controller.enqueue({
1729
+ type: "source",
1730
+ sourceType: "url",
1731
+ id: annotation.url_citation.url,
1732
+ url: annotation.url_citation.url,
1733
+ title: annotation.url_citation.title,
1734
+ providerMetadata: {
1735
+ openrouter: {
1736
+ content: annotation.url_citation.content || ""
1737
+ }
1738
+ }
1739
+ });
1740
+ }
1741
+ }
1742
+ }
1672
1743
  if (delta.tool_calls != null) {
1673
1744
  for (const toolCallDelta of delta.tool_calls) {
1674
1745
  const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
@@ -1791,14 +1862,18 @@ var OpenRouterChatLanguageModel = class {
1791
1862
  id: textId || generateId()
1792
1863
  });
1793
1864
  }
1865
+ const openrouterMetadata = {
1866
+ usage: openrouterUsage
1867
+ };
1868
+ if (provider !== void 0) {
1869
+ openrouterMetadata.provider = provider;
1870
+ }
1794
1871
  controller.enqueue({
1795
1872
  type: "finish",
1796
1873
  finishReason,
1797
1874
  usage,
1798
1875
  providerMetadata: {
1799
- openrouter: {
1800
- usage: openrouterUsage
1801
- }
1876
+ openrouter: openrouterMetadata
1802
1877
  }
1803
1878
  });
1804
1879
  }