@openrouter/ai-sdk-provider 1.0.0 → 1.1.1

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
@@ -1223,6 +1223,7 @@ var import_v44 = require("zod/v4");
1223
1223
  var OpenRouterChatCompletionBaseResponseSchema = import_v44.z.object({
1224
1224
  id: import_v44.z.string().optional(),
1225
1225
  model: import_v44.z.string().optional(),
1226
+ provider: import_v44.z.string().optional(),
1226
1227
  usage: import_v44.z.object({
1227
1228
  prompt_tokens: import_v44.z.number(),
1228
1229
  prompt_tokens_details: import_v44.z.object({
@@ -1256,7 +1257,19 @@ var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBa
1256
1257
  arguments: import_v44.z.string()
1257
1258
  })
1258
1259
  })
1259
- ).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()
1260
1273
  }),
1261
1274
  index: import_v44.z.number().nullish(),
1262
1275
  logprobs: import_v44.z.object({
@@ -1296,6 +1309,18 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v44.z.union([
1296
1309
  arguments: import_v44.z.string().nullish()
1297
1310
  })
1298
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
+ })
1299
1324
  ).nullish()
1300
1325
  }).nullish(),
1301
1326
  logprobs: import_v44.z.object({
@@ -1378,7 +1403,12 @@ var OpenRouterChatLanguageModel = class {
1378
1403
  // OpenRouter specific settings:
1379
1404
  include_reasoning: this.settings.includeReasoning,
1380
1405
  reasoning: this.settings.reasoning,
1381
- 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
1382
1412
  }, this.config.extraBody), this.settings.extraBody);
1383
1413
  if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
1384
1414
  return __spreadProps(__spreadValues({}, baseArgs), {
@@ -1399,7 +1429,7 @@ var OpenRouterChatLanguageModel = class {
1399
1429
  type: "function",
1400
1430
  function: {
1401
1431
  name: tool.name,
1402
- description: tool.type,
1432
+ description: tool.description,
1403
1433
  parameters: tool.inputSchema
1404
1434
  }
1405
1435
  }));
@@ -1411,7 +1441,7 @@ var OpenRouterChatLanguageModel = class {
1411
1441
  return baseArgs;
1412
1442
  }
1413
1443
  async doGenerate(options) {
1414
- 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;
1415
1445
  const providerOptions = options.providerOptions || {};
1416
1446
  const openrouterOptions = providerOptions.openrouter || {};
1417
1447
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
@@ -1505,6 +1535,24 @@ var OpenRouterChatLanguageModel = class {
1505
1535
  });
1506
1536
  }
1507
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
+ }
1508
1556
  return {
1509
1557
  content,
1510
1558
  finishReason: mapOpenRouterFinishReason(choice.finish_reason),
@@ -1512,19 +1560,20 @@ var OpenRouterChatLanguageModel = class {
1512
1560
  warnings: [],
1513
1561
  providerMetadata: {
1514
1562
  openrouter: {
1563
+ provider: (_k = response.provider) != null ? _k : "",
1515
1564
  usage: {
1516
- promptTokens: (_k = usageInfo.inputTokens) != null ? _k : 0,
1517
- completionTokens: (_l = usageInfo.outputTokens) != null ? _l : 0,
1518
- totalTokens: (_m = usageInfo.totalTokens) != null ? _m : 0,
1519
- 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,
1520
1569
  promptTokensDetails: {
1521
- 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
1522
1571
  },
1523
1572
  completionTokensDetails: {
1524
- 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
1525
1574
  },
1526
1575
  costDetails: {
1527
- 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
1528
1577
  }
1529
1578
  }
1530
1579
  }
@@ -1577,6 +1626,7 @@ var OpenRouterChatLanguageModel = class {
1577
1626
  let textId;
1578
1627
  let reasoningId;
1579
1628
  let openrouterResponseId;
1629
+ let provider;
1580
1630
  return {
1581
1631
  stream: response.pipeThrough(
1582
1632
  new TransformStream({
@@ -1593,6 +1643,9 @@ var OpenRouterChatLanguageModel = class {
1593
1643
  controller.enqueue({ type: "error", error: value.error });
1594
1644
  return;
1595
1645
  }
1646
+ if (value.provider) {
1647
+ provider = value.provider;
1648
+ }
1596
1649
  if (value.id) {
1597
1650
  openrouterResponseId = value.id;
1598
1651
  controller.enqueue({
@@ -1704,6 +1757,24 @@ var OpenRouterChatLanguageModel = class {
1704
1757
  id: textId || generateId()
1705
1758
  });
1706
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
+ }
1707
1778
  if (delta.tool_calls != null) {
1708
1779
  for (const toolCallDelta of delta.tool_calls) {
1709
1780
  const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
@@ -1826,14 +1897,18 @@ var OpenRouterChatLanguageModel = class {
1826
1897
  id: textId || generateId()
1827
1898
  });
1828
1899
  }
1900
+ const openrouterMetadata = {
1901
+ usage: openrouterUsage
1902
+ };
1903
+ if (provider !== void 0) {
1904
+ openrouterMetadata.provider = provider;
1905
+ }
1829
1906
  controller.enqueue({
1830
1907
  type: "finish",
1831
1908
  finishReason,
1832
1909
  usage,
1833
1910
  providerMetadata: {
1834
- openrouter: {
1835
- usage: openrouterUsage
1836
- }
1911
+ openrouter: openrouterMetadata
1837
1912
  }
1838
1913
  });
1839
1914
  }