@openrouter/ai-sdk-provider 1.0.0-beta.7 → 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.d.mts CHANGED
@@ -39,6 +39,80 @@ type OpenRouterChatSettings = {
39
39
  monitor and detect abuse. Learn more.
40
40
  */
41
41
  user?: string;
42
+ /**
43
+ * Web search plugin configuration for enabling web search capabilities
44
+ */
45
+ plugins?: Array<{
46
+ id: 'web';
47
+ /**
48
+ * Maximum number of search results to include (default: 5)
49
+ */
50
+ max_results?: number;
51
+ /**
52
+ * Custom search prompt to guide the search query
53
+ */
54
+ search_prompt?: string;
55
+ }>;
56
+ /**
57
+ * Built-in web search options for models that support native web search
58
+ */
59
+ web_search_options?: {
60
+ /**
61
+ * Maximum number of search results to include
62
+ */
63
+ max_results?: number;
64
+ /**
65
+ * Custom search prompt to guide the search query
66
+ */
67
+ search_prompt?: string;
68
+ };
69
+ /**
70
+ * Provider routing preferences to control request routing behavior
71
+ */
72
+ provider?: {
73
+ /**
74
+ * List of provider slugs to try in order (e.g. ["anthropic", "openai"])
75
+ */
76
+ order?: string[];
77
+ /**
78
+ * Whether to allow backup providers when primary is unavailable (default: true)
79
+ */
80
+ allow_fallbacks?: boolean;
81
+ /**
82
+ * Only use providers that support all parameters in your request (default: false)
83
+ */
84
+ require_parameters?: boolean;
85
+ /**
86
+ * Control whether to use providers that may store data
87
+ */
88
+ data_collection?: 'allow' | 'deny';
89
+ /**
90
+ * List of provider slugs to allow for this request
91
+ */
92
+ only?: string[];
93
+ /**
94
+ * List of provider slugs to skip for this request
95
+ */
96
+ ignore?: string[];
97
+ /**
98
+ * List of quantization levels to filter by (e.g. ["int4", "int8"])
99
+ */
100
+ quantizations?: Array<'int4' | 'int8' | 'fp4' | 'fp6' | 'fp8' | 'fp16' | 'bf16' | 'fp32' | 'unknown'>;
101
+ /**
102
+ * Sort providers by price, throughput, or latency
103
+ */
104
+ sort?: 'price' | 'throughput' | 'latency';
105
+ /**
106
+ * Maximum pricing you want to pay for this request
107
+ */
108
+ max_price?: {
109
+ prompt?: number | string;
110
+ completion?: number | string;
111
+ image?: number | string;
112
+ audio?: number | string;
113
+ request?: number | string;
114
+ };
115
+ };
42
116
  } & OpenRouterSharedSettings;
43
117
 
44
118
  type OpenRouterProviderOptions = {
@@ -162,6 +236,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
162
236
  warnings: Array<LanguageModelV2CallWarning>;
163
237
  providerMetadata?: {
164
238
  openrouter: {
239
+ provider: string;
165
240
  usage: OpenRouterUsageAccounting;
166
241
  };
167
242
  };
package/dist/index.d.ts CHANGED
@@ -39,6 +39,80 @@ type OpenRouterChatSettings = {
39
39
  monitor and detect abuse. Learn more.
40
40
  */
41
41
  user?: string;
42
+ /**
43
+ * Web search plugin configuration for enabling web search capabilities
44
+ */
45
+ plugins?: Array<{
46
+ id: 'web';
47
+ /**
48
+ * Maximum number of search results to include (default: 5)
49
+ */
50
+ max_results?: number;
51
+ /**
52
+ * Custom search prompt to guide the search query
53
+ */
54
+ search_prompt?: string;
55
+ }>;
56
+ /**
57
+ * Built-in web search options for models that support native web search
58
+ */
59
+ web_search_options?: {
60
+ /**
61
+ * Maximum number of search results to include
62
+ */
63
+ max_results?: number;
64
+ /**
65
+ * Custom search prompt to guide the search query
66
+ */
67
+ search_prompt?: string;
68
+ };
69
+ /**
70
+ * Provider routing preferences to control request routing behavior
71
+ */
72
+ provider?: {
73
+ /**
74
+ * List of provider slugs to try in order (e.g. ["anthropic", "openai"])
75
+ */
76
+ order?: string[];
77
+ /**
78
+ * Whether to allow backup providers when primary is unavailable (default: true)
79
+ */
80
+ allow_fallbacks?: boolean;
81
+ /**
82
+ * Only use providers that support all parameters in your request (default: false)
83
+ */
84
+ require_parameters?: boolean;
85
+ /**
86
+ * Control whether to use providers that may store data
87
+ */
88
+ data_collection?: 'allow' | 'deny';
89
+ /**
90
+ * List of provider slugs to allow for this request
91
+ */
92
+ only?: string[];
93
+ /**
94
+ * List of provider slugs to skip for this request
95
+ */
96
+ ignore?: string[];
97
+ /**
98
+ * List of quantization levels to filter by (e.g. ["int4", "int8"])
99
+ */
100
+ quantizations?: Array<'int4' | 'int8' | 'fp4' | 'fp6' | 'fp8' | 'fp16' | 'bf16' | 'fp32' | 'unknown'>;
101
+ /**
102
+ * Sort providers by price, throughput, or latency
103
+ */
104
+ sort?: 'price' | 'throughput' | 'latency';
105
+ /**
106
+ * Maximum pricing you want to pay for this request
107
+ */
108
+ max_price?: {
109
+ prompt?: number | string;
110
+ completion?: number | string;
111
+ image?: number | string;
112
+ audio?: number | string;
113
+ request?: number | string;
114
+ };
115
+ };
42
116
  } & OpenRouterSharedSettings;
43
117
 
44
118
  type OpenRouterProviderOptions = {
@@ -162,6 +236,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
162
236
  warnings: Array<LanguageModelV2CallWarning>;
163
237
  providerMetadata?: {
164
238
  openrouter: {
239
+ provider: string;
165
240
  usage: OpenRouterUsageAccounting;
166
241
  };
167
242
  };
package/dist/index.js CHANGED
@@ -53,7 +53,7 @@ __export(index_exports, {
53
53
  });
54
54
  module.exports = __toCommonJS(index_exports);
55
55
 
56
- // node_modules/.pnpm/@ai-sdk+provider@2.0.0-beta.1/node_modules/@ai-sdk/provider/dist/index.mjs
56
+ // node_modules/.pnpm/@ai-sdk+provider@2.0.0/node_modules/@ai-sdk/provider/dist/index.mjs
57
57
  var marker = "vercel.ai.error";
58
58
  var symbol = Symbol.for(marker);
59
59
  var _a;
@@ -447,28 +447,25 @@ var EventSourceParserStream = class extends TransformStream {
447
447
  }
448
448
  };
449
449
 
450
- // node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
450
+ // node_modules/.pnpm/@ai-sdk+provider-utils@3.0.1_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
451
451
  var z4 = __toESM(require("zod/v4"), 1);
452
452
 
453
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js
453
+ // node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js
454
454
  var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
455
455
 
456
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js
457
- var import_zod4 = require("zod");
456
+ // node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js
457
+ var import_zod3 = require("zod");
458
458
 
459
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
459
+ // node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
460
460
  var import_zod = require("zod");
461
461
 
462
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
462
+ // node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
463
463
  var import_zod2 = require("zod");
464
464
 
465
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
465
+ // node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
466
466
  var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
467
467
 
468
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
469
- var import_zod3 = require("zod");
470
-
471
- // node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
468
+ // node_modules/.pnpm/@ai-sdk+provider-utils@3.0.1_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
472
469
  function combineHeaders(...headers) {
473
470
  return headers.reduce(
474
471
  (combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
@@ -505,7 +502,7 @@ var createIdGenerator = ({
505
502
  };
506
503
  var generateId = createIdGenerator();
507
504
  function isAbortError(error) {
508
- return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
505
+ return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
509
506
  error.name === "TimeoutError");
510
507
  }
511
508
  var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
@@ -1226,6 +1223,7 @@ var import_v44 = require("zod/v4");
1226
1223
  var OpenRouterChatCompletionBaseResponseSchema = import_v44.z.object({
1227
1224
  id: import_v44.z.string().optional(),
1228
1225
  model: import_v44.z.string().optional(),
1226
+ provider: import_v44.z.string().optional(),
1229
1227
  usage: import_v44.z.object({
1230
1228
  prompt_tokens: import_v44.z.number(),
1231
1229
  prompt_tokens_details: import_v44.z.object({
@@ -1259,7 +1257,19 @@ var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBa
1259
1257
  arguments: import_v44.z.string()
1260
1258
  })
1261
1259
  })
1262
- ).optional()
1260
+ ).optional(),
1261
+ annotations: import_v44.z.array(
1262
+ import_v44.z.object({
1263
+ type: import_v44.z.enum(["url_citation"]),
1264
+ url_citation: import_v44.z.object({
1265
+ end_index: import_v44.z.number(),
1266
+ start_index: import_v44.z.number(),
1267
+ title: import_v44.z.string(),
1268
+ url: import_v44.z.string(),
1269
+ content: import_v44.z.string().optional()
1270
+ })
1271
+ })
1272
+ ).nullish()
1263
1273
  }),
1264
1274
  index: import_v44.z.number().nullish(),
1265
1275
  logprobs: import_v44.z.object({
@@ -1299,6 +1309,18 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v44.z.union([
1299
1309
  arguments: import_v44.z.string().nullish()
1300
1310
  })
1301
1311
  })
1312
+ ).nullish(),
1313
+ annotations: import_v44.z.array(
1314
+ import_v44.z.object({
1315
+ type: import_v44.z.enum(["url_citation"]),
1316
+ url_citation: import_v44.z.object({
1317
+ end_index: import_v44.z.number(),
1318
+ start_index: import_v44.z.number(),
1319
+ title: import_v44.z.string(),
1320
+ url: import_v44.z.string(),
1321
+ content: import_v44.z.string().optional()
1322
+ })
1323
+ })
1302
1324
  ).nullish()
1303
1325
  }).nullish(),
1304
1326
  logprobs: import_v44.z.object({
@@ -1381,7 +1403,12 @@ var OpenRouterChatLanguageModel = class {
1381
1403
  // OpenRouter specific settings:
1382
1404
  include_reasoning: this.settings.includeReasoning,
1383
1405
  reasoning: this.settings.reasoning,
1384
- usage: this.settings.usage
1406
+ usage: this.settings.usage,
1407
+ // Web search settings:
1408
+ plugins: this.settings.plugins,
1409
+ web_search_options: this.settings.web_search_options,
1410
+ // Provider routing settings:
1411
+ provider: this.settings.provider
1385
1412
  }, this.config.extraBody), this.settings.extraBody);
1386
1413
  if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
1387
1414
  return __spreadProps(__spreadValues({}, baseArgs), {
@@ -1414,7 +1441,7 @@ var OpenRouterChatLanguageModel = class {
1414
1441
  return baseArgs;
1415
1442
  }
1416
1443
  async doGenerate(options) {
1417
- var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1444
+ 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;
1418
1445
  const providerOptions = options.providerOptions || {};
1419
1446
  const openrouterOptions = providerOptions.openrouter || {};
1420
1447
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
@@ -1508,6 +1535,24 @@ var OpenRouterChatLanguageModel = class {
1508
1535
  });
1509
1536
  }
1510
1537
  }
1538
+ if (choice.message.annotations) {
1539
+ for (const annotation of choice.message.annotations) {
1540
+ if (annotation.type === "url_citation") {
1541
+ content.push({
1542
+ type: "source",
1543
+ sourceType: "url",
1544
+ id: annotation.url_citation.url,
1545
+ url: annotation.url_citation.url,
1546
+ title: annotation.url_citation.title,
1547
+ providerMetadata: {
1548
+ openrouter: {
1549
+ content: annotation.url_citation.content || ""
1550
+ }
1551
+ }
1552
+ });
1553
+ }
1554
+ }
1555
+ }
1511
1556
  return {
1512
1557
  content,
1513
1558
  finishReason: mapOpenRouterFinishReason(choice.finish_reason),
@@ -1515,19 +1560,20 @@ var OpenRouterChatLanguageModel = class {
1515
1560
  warnings: [],
1516
1561
  providerMetadata: {
1517
1562
  openrouter: {
1563
+ provider: (_k = response.provider) != null ? _k : "",
1518
1564
  usage: {
1519
- promptTokens: (_k = usageInfo.inputTokens) != null ? _k : 0,
1520
- completionTokens: (_l = usageInfo.outputTokens) != null ? _l : 0,
1521
- totalTokens: (_m = usageInfo.totalTokens) != null ? _m : 0,
1522
- cost: (_n = response.usage) == null ? void 0 : _n.cost,
1565
+ promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
1566
+ completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
1567
+ totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
1568
+ cost: (_o = response.usage) == null ? void 0 : _o.cost,
1523
1569
  promptTokensDetails: {
1524
- cachedTokens: (_q = (_p = (_o = response.usage) == null ? void 0 : _o.prompt_tokens_details) == null ? void 0 : _p.cached_tokens) != null ? _q : 0
1570
+ cachedTokens: (_r = (_q = (_p = response.usage) == null ? void 0 : _p.prompt_tokens_details) == null ? void 0 : _q.cached_tokens) != null ? _r : 0
1525
1571
  },
1526
1572
  completionTokensDetails: {
1527
- reasoningTokens: (_t = (_s = (_r = response.usage) == null ? void 0 : _r.completion_tokens_details) == null ? void 0 : _s.reasoning_tokens) != null ? _t : 0
1573
+ reasoningTokens: (_u = (_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? _u : 0
1528
1574
  },
1529
1575
  costDetails: {
1530
- upstreamInferenceCost: (_w = (_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? _w : 0
1576
+ upstreamInferenceCost: (_x = (_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? _x : 0
1531
1577
  }
1532
1578
  }
1533
1579
  }
@@ -1580,6 +1626,7 @@ var OpenRouterChatLanguageModel = class {
1580
1626
  let textId;
1581
1627
  let reasoningId;
1582
1628
  let openrouterResponseId;
1629
+ let provider;
1583
1630
  return {
1584
1631
  stream: response.pipeThrough(
1585
1632
  new TransformStream({
@@ -1596,6 +1643,9 @@ var OpenRouterChatLanguageModel = class {
1596
1643
  controller.enqueue({ type: "error", error: value.error });
1597
1644
  return;
1598
1645
  }
1646
+ if (value.provider) {
1647
+ provider = value.provider;
1648
+ }
1599
1649
  if (value.id) {
1600
1650
  openrouterResponseId = value.id;
1601
1651
  controller.enqueue({
@@ -1682,10 +1732,17 @@ var OpenRouterChatLanguageModel = class {
1682
1732
  }
1683
1733
  }
1684
1734
  }
1685
- } else if (delta.reasoning != null) {
1735
+ } else if (delta.reasoning) {
1686
1736
  emitReasoningChunk(delta.reasoning);
1687
1737
  }
1688
- if (delta.content != null) {
1738
+ if (delta.content) {
1739
+ if (reasoningStarted && !textStarted) {
1740
+ controller.enqueue({
1741
+ type: "reasoning-end",
1742
+ id: reasoningId || generateId()
1743
+ });
1744
+ reasoningStarted = false;
1745
+ }
1689
1746
  if (!textStarted) {
1690
1747
  textId = openrouterResponseId || generateId();
1691
1748
  controller.enqueue({
@@ -1700,6 +1757,24 @@ var OpenRouterChatLanguageModel = class {
1700
1757
  id: textId || generateId()
1701
1758
  });
1702
1759
  }
1760
+ if (delta.annotations) {
1761
+ for (const annotation of delta.annotations) {
1762
+ if (annotation.type === "url_citation") {
1763
+ controller.enqueue({
1764
+ type: "source",
1765
+ sourceType: "url",
1766
+ id: annotation.url_citation.url,
1767
+ url: annotation.url_citation.url,
1768
+ title: annotation.url_citation.title,
1769
+ providerMetadata: {
1770
+ openrouter: {
1771
+ content: annotation.url_citation.content || ""
1772
+ }
1773
+ }
1774
+ });
1775
+ }
1776
+ }
1777
+ }
1703
1778
  if (delta.tool_calls != null) {
1704
1779
  for (const toolCallDelta of delta.tool_calls) {
1705
1780
  const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
@@ -1810,26 +1885,30 @@ var OpenRouterChatLanguageModel = class {
1810
1885
  }
1811
1886
  }
1812
1887
  }
1888
+ if (reasoningStarted) {
1889
+ controller.enqueue({
1890
+ type: "reasoning-end",
1891
+ id: reasoningId || generateId()
1892
+ });
1893
+ }
1813
1894
  if (textStarted) {
1814
1895
  controller.enqueue({
1815
1896
  type: "text-end",
1816
1897
  id: textId || generateId()
1817
1898
  });
1818
1899
  }
1819
- if (reasoningStarted) {
1820
- controller.enqueue({
1821
- type: "reasoning-end",
1822
- id: reasoningId || generateId()
1823
- });
1900
+ const openrouterMetadata = {
1901
+ usage: openrouterUsage
1902
+ };
1903
+ if (provider !== void 0) {
1904
+ openrouterMetadata.provider = provider;
1824
1905
  }
1825
1906
  controller.enqueue({
1826
1907
  type: "finish",
1827
1908
  finishReason,
1828
1909
  usage,
1829
1910
  providerMetadata: {
1830
- openrouter: {
1831
- usage: openrouterUsage
1832
- }
1911
+ openrouter: openrouterMetadata
1833
1912
  }
1834
1913
  });
1835
1914
  }