@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.
@@ -157,6 +157,80 @@ type OpenRouterChatSettings = {
157
157
  monitor and detect abuse. Learn more.
158
158
  */
159
159
  user?: string;
160
+ /**
161
+ * Web search plugin configuration for enabling web search capabilities
162
+ */
163
+ plugins?: Array<{
164
+ id: 'web';
165
+ /**
166
+ * Maximum number of search results to include (default: 5)
167
+ */
168
+ max_results?: number;
169
+ /**
170
+ * Custom search prompt to guide the search query
171
+ */
172
+ search_prompt?: string;
173
+ }>;
174
+ /**
175
+ * Built-in web search options for models that support native web search
176
+ */
177
+ web_search_options?: {
178
+ /**
179
+ * Maximum number of search results to include
180
+ */
181
+ max_results?: number;
182
+ /**
183
+ * Custom search prompt to guide the search query
184
+ */
185
+ search_prompt?: string;
186
+ };
187
+ /**
188
+ * Provider routing preferences to control request routing behavior
189
+ */
190
+ provider?: {
191
+ /**
192
+ * List of provider slugs to try in order (e.g. ["anthropic", "openai"])
193
+ */
194
+ order?: string[];
195
+ /**
196
+ * Whether to allow backup providers when primary is unavailable (default: true)
197
+ */
198
+ allow_fallbacks?: boolean;
199
+ /**
200
+ * Only use providers that support all parameters in your request (default: false)
201
+ */
202
+ require_parameters?: boolean;
203
+ /**
204
+ * Control whether to use providers that may store data
205
+ */
206
+ data_collection?: 'allow' | 'deny';
207
+ /**
208
+ * List of provider slugs to allow for this request
209
+ */
210
+ only?: string[];
211
+ /**
212
+ * List of provider slugs to skip for this request
213
+ */
214
+ ignore?: string[];
215
+ /**
216
+ * List of quantization levels to filter by (e.g. ["int4", "int8"])
217
+ */
218
+ quantizations?: Array<'int4' | 'int8' | 'fp4' | 'fp6' | 'fp8' | 'fp16' | 'bf16' | 'fp32' | 'unknown'>;
219
+ /**
220
+ * Sort providers by price, throughput, or latency
221
+ */
222
+ sort?: 'price' | 'throughput' | 'latency';
223
+ /**
224
+ * Maximum pricing you want to pay for this request
225
+ */
226
+ max_price?: {
227
+ prompt?: number | string;
228
+ completion?: number | string;
229
+ image?: number | string;
230
+ audio?: number | string;
231
+ request?: number | string;
232
+ };
233
+ };
160
234
  } & OpenRouterSharedSettings;
161
235
 
162
236
  type OpenRouterChatConfig = {
@@ -187,6 +261,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
187
261
  warnings: Array<LanguageModelV2CallWarning>;
188
262
  providerMetadata?: {
189
263
  openrouter: {
264
+ provider: string;
190
265
  usage: OpenRouterUsageAccounting;
191
266
  };
192
267
  };
@@ -157,6 +157,80 @@ type OpenRouterChatSettings = {
157
157
  monitor and detect abuse. Learn more.
158
158
  */
159
159
  user?: string;
160
+ /**
161
+ * Web search plugin configuration for enabling web search capabilities
162
+ */
163
+ plugins?: Array<{
164
+ id: 'web';
165
+ /**
166
+ * Maximum number of search results to include (default: 5)
167
+ */
168
+ max_results?: number;
169
+ /**
170
+ * Custom search prompt to guide the search query
171
+ */
172
+ search_prompt?: string;
173
+ }>;
174
+ /**
175
+ * Built-in web search options for models that support native web search
176
+ */
177
+ web_search_options?: {
178
+ /**
179
+ * Maximum number of search results to include
180
+ */
181
+ max_results?: number;
182
+ /**
183
+ * Custom search prompt to guide the search query
184
+ */
185
+ search_prompt?: string;
186
+ };
187
+ /**
188
+ * Provider routing preferences to control request routing behavior
189
+ */
190
+ provider?: {
191
+ /**
192
+ * List of provider slugs to try in order (e.g. ["anthropic", "openai"])
193
+ */
194
+ order?: string[];
195
+ /**
196
+ * Whether to allow backup providers when primary is unavailable (default: true)
197
+ */
198
+ allow_fallbacks?: boolean;
199
+ /**
200
+ * Only use providers that support all parameters in your request (default: false)
201
+ */
202
+ require_parameters?: boolean;
203
+ /**
204
+ * Control whether to use providers that may store data
205
+ */
206
+ data_collection?: 'allow' | 'deny';
207
+ /**
208
+ * List of provider slugs to allow for this request
209
+ */
210
+ only?: string[];
211
+ /**
212
+ * List of provider slugs to skip for this request
213
+ */
214
+ ignore?: string[];
215
+ /**
216
+ * List of quantization levels to filter by (e.g. ["int4", "int8"])
217
+ */
218
+ quantizations?: Array<'int4' | 'int8' | 'fp4' | 'fp6' | 'fp8' | 'fp16' | 'bf16' | 'fp32' | 'unknown'>;
219
+ /**
220
+ * Sort providers by price, throughput, or latency
221
+ */
222
+ sort?: 'price' | 'throughput' | 'latency';
223
+ /**
224
+ * Maximum pricing you want to pay for this request
225
+ */
226
+ max_price?: {
227
+ prompt?: number | string;
228
+ completion?: number | string;
229
+ image?: number | string;
230
+ audio?: number | string;
231
+ request?: number | string;
232
+ };
233
+ };
160
234
  } & OpenRouterSharedSettings;
161
235
 
162
236
  type OpenRouterChatConfig = {
@@ -187,6 +261,7 @@ declare class OpenRouterChatLanguageModel implements LanguageModelV2 {
187
261
  warnings: Array<LanguageModelV2CallWarning>;
188
262
  providerMetadata?: {
189
263
  openrouter: {
264
+ provider: string;
190
265
  usage: OpenRouterUsageAccounting;
191
266
  };
192
267
  };
@@ -52,7 +52,7 @@ __export(index_exports, {
52
52
  });
53
53
  module.exports = __toCommonJS(index_exports);
54
54
 
55
- // node_modules/.pnpm/@ai-sdk+provider@2.0.0-beta.1/node_modules/@ai-sdk/provider/dist/index.mjs
55
+ // node_modules/.pnpm/@ai-sdk+provider@2.0.0/node_modules/@ai-sdk/provider/dist/index.mjs
56
56
  var marker = "vercel.ai.error";
57
57
  var symbol = Symbol.for(marker);
58
58
  var _a;
@@ -436,28 +436,25 @@ var EventSourceParserStream = class extends TransformStream {
436
436
  }
437
437
  };
438
438
 
439
- // 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
439
+ // node_modules/.pnpm/@ai-sdk+provider-utils@3.0.1_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
440
440
  var z4 = __toESM(require("zod/v4"), 1);
441
441
 
442
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js
442
+ // node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js
443
443
  var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
444
444
 
445
- // node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js
446
- var import_zod4 = require("zod");
445
+ // node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js
446
+ var import_zod3 = require("zod");
447
447
 
448
- // 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
448
+ // 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
449
449
  var import_zod = require("zod");
450
450
 
451
- // 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
451
+ // 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
452
452
  var import_zod2 = require("zod");
453
453
 
454
- // 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
454
+ // 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
455
455
  var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
456
456
 
457
- // 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
458
- var import_zod3 = require("zod");
459
-
460
- // 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
457
+ // node_modules/.pnpm/@ai-sdk+provider-utils@3.0.1_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
461
458
  function combineHeaders(...headers) {
462
459
  return headers.reduce(
463
460
  (combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
@@ -494,7 +491,7 @@ var createIdGenerator = ({
494
491
  };
495
492
  var generateId = createIdGenerator();
496
493
  function isAbortError(error) {
497
- return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
494
+ return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
498
495
  error.name === "TimeoutError");
499
496
  }
500
497
  var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
@@ -1180,6 +1177,7 @@ var import_v44 = require("zod/v4");
1180
1177
  var OpenRouterChatCompletionBaseResponseSchema = import_v44.z.object({
1181
1178
  id: import_v44.z.string().optional(),
1182
1179
  model: import_v44.z.string().optional(),
1180
+ provider: import_v44.z.string().optional(),
1183
1181
  usage: import_v44.z.object({
1184
1182
  prompt_tokens: import_v44.z.number(),
1185
1183
  prompt_tokens_details: import_v44.z.object({
@@ -1213,7 +1211,19 @@ var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBa
1213
1211
  arguments: import_v44.z.string()
1214
1212
  })
1215
1213
  })
1216
- ).optional()
1214
+ ).optional(),
1215
+ annotations: import_v44.z.array(
1216
+ import_v44.z.object({
1217
+ type: import_v44.z.enum(["url_citation"]),
1218
+ url_citation: import_v44.z.object({
1219
+ end_index: import_v44.z.number(),
1220
+ start_index: import_v44.z.number(),
1221
+ title: import_v44.z.string(),
1222
+ url: import_v44.z.string(),
1223
+ content: import_v44.z.string().optional()
1224
+ })
1225
+ })
1226
+ ).nullish()
1217
1227
  }),
1218
1228
  index: import_v44.z.number().nullish(),
1219
1229
  logprobs: import_v44.z.object({
@@ -1253,6 +1263,18 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v44.z.union([
1253
1263
  arguments: import_v44.z.string().nullish()
1254
1264
  })
1255
1265
  })
1266
+ ).nullish(),
1267
+ annotations: import_v44.z.array(
1268
+ import_v44.z.object({
1269
+ type: import_v44.z.enum(["url_citation"]),
1270
+ url_citation: import_v44.z.object({
1271
+ end_index: import_v44.z.number(),
1272
+ start_index: import_v44.z.number(),
1273
+ title: import_v44.z.string(),
1274
+ url: import_v44.z.string(),
1275
+ content: import_v44.z.string().optional()
1276
+ })
1277
+ })
1256
1278
  ).nullish()
1257
1279
  }).nullish(),
1258
1280
  logprobs: import_v44.z.object({
@@ -1335,7 +1357,12 @@ var OpenRouterChatLanguageModel = class {
1335
1357
  // OpenRouter specific settings:
1336
1358
  include_reasoning: this.settings.includeReasoning,
1337
1359
  reasoning: this.settings.reasoning,
1338
- usage: this.settings.usage
1360
+ usage: this.settings.usage,
1361
+ // Web search settings:
1362
+ plugins: this.settings.plugins,
1363
+ web_search_options: this.settings.web_search_options,
1364
+ // Provider routing settings:
1365
+ provider: this.settings.provider
1339
1366
  }, this.config.extraBody), this.settings.extraBody);
1340
1367
  if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
1341
1368
  return __spreadProps(__spreadValues({}, baseArgs), {
@@ -1368,7 +1395,7 @@ var OpenRouterChatLanguageModel = class {
1368
1395
  return baseArgs;
1369
1396
  }
1370
1397
  async doGenerate(options) {
1371
- var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
1398
+ 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;
1372
1399
  const providerOptions = options.providerOptions || {};
1373
1400
  const openrouterOptions = providerOptions.openrouter || {};
1374
1401
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
@@ -1462,6 +1489,24 @@ var OpenRouterChatLanguageModel = class {
1462
1489
  });
1463
1490
  }
1464
1491
  }
1492
+ if (choice.message.annotations) {
1493
+ for (const annotation of choice.message.annotations) {
1494
+ if (annotation.type === "url_citation") {
1495
+ content.push({
1496
+ type: "source",
1497
+ sourceType: "url",
1498
+ id: annotation.url_citation.url,
1499
+ url: annotation.url_citation.url,
1500
+ title: annotation.url_citation.title,
1501
+ providerMetadata: {
1502
+ openrouter: {
1503
+ content: annotation.url_citation.content || ""
1504
+ }
1505
+ }
1506
+ });
1507
+ }
1508
+ }
1509
+ }
1465
1510
  return {
1466
1511
  content,
1467
1512
  finishReason: mapOpenRouterFinishReason(choice.finish_reason),
@@ -1469,19 +1514,20 @@ var OpenRouterChatLanguageModel = class {
1469
1514
  warnings: [],
1470
1515
  providerMetadata: {
1471
1516
  openrouter: {
1517
+ provider: (_k = response.provider) != null ? _k : "",
1472
1518
  usage: {
1473
- promptTokens: (_k = usageInfo.inputTokens) != null ? _k : 0,
1474
- completionTokens: (_l = usageInfo.outputTokens) != null ? _l : 0,
1475
- totalTokens: (_m = usageInfo.totalTokens) != null ? _m : 0,
1476
- cost: (_n = response.usage) == null ? void 0 : _n.cost,
1519
+ promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
1520
+ completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
1521
+ totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
1522
+ cost: (_o = response.usage) == null ? void 0 : _o.cost,
1477
1523
  promptTokensDetails: {
1478
- cachedTokens: (_q = (_p = (_o = response.usage) == null ? void 0 : _o.prompt_tokens_details) == null ? void 0 : _p.cached_tokens) != null ? _q : 0
1524
+ cachedTokens: (_r = (_q = (_p = response.usage) == null ? void 0 : _p.prompt_tokens_details) == null ? void 0 : _q.cached_tokens) != null ? _r : 0
1479
1525
  },
1480
1526
  completionTokensDetails: {
1481
- reasoningTokens: (_t = (_s = (_r = response.usage) == null ? void 0 : _r.completion_tokens_details) == null ? void 0 : _s.reasoning_tokens) != null ? _t : 0
1527
+ reasoningTokens: (_u = (_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? _u : 0
1482
1528
  },
1483
1529
  costDetails: {
1484
- upstreamInferenceCost: (_w = (_v = (_u = response.usage) == null ? void 0 : _u.cost_details) == null ? void 0 : _v.upstream_inference_cost) != null ? _w : 0
1530
+ upstreamInferenceCost: (_x = (_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? _x : 0
1485
1531
  }
1486
1532
  }
1487
1533
  }
@@ -1534,6 +1580,7 @@ var OpenRouterChatLanguageModel = class {
1534
1580
  let textId;
1535
1581
  let reasoningId;
1536
1582
  let openrouterResponseId;
1583
+ let provider;
1537
1584
  return {
1538
1585
  stream: response.pipeThrough(
1539
1586
  new TransformStream({
@@ -1550,6 +1597,9 @@ var OpenRouterChatLanguageModel = class {
1550
1597
  controller.enqueue({ type: "error", error: value.error });
1551
1598
  return;
1552
1599
  }
1600
+ if (value.provider) {
1601
+ provider = value.provider;
1602
+ }
1553
1603
  if (value.id) {
1554
1604
  openrouterResponseId = value.id;
1555
1605
  controller.enqueue({
@@ -1636,10 +1686,17 @@ var OpenRouterChatLanguageModel = class {
1636
1686
  }
1637
1687
  }
1638
1688
  }
1639
- } else if (delta.reasoning != null) {
1689
+ } else if (delta.reasoning) {
1640
1690
  emitReasoningChunk(delta.reasoning);
1641
1691
  }
1642
- if (delta.content != null) {
1692
+ if (delta.content) {
1693
+ if (reasoningStarted && !textStarted) {
1694
+ controller.enqueue({
1695
+ type: "reasoning-end",
1696
+ id: reasoningId || generateId()
1697
+ });
1698
+ reasoningStarted = false;
1699
+ }
1643
1700
  if (!textStarted) {
1644
1701
  textId = openrouterResponseId || generateId();
1645
1702
  controller.enqueue({
@@ -1654,6 +1711,24 @@ var OpenRouterChatLanguageModel = class {
1654
1711
  id: textId || generateId()
1655
1712
  });
1656
1713
  }
1714
+ if (delta.annotations) {
1715
+ for (const annotation of delta.annotations) {
1716
+ if (annotation.type === "url_citation") {
1717
+ controller.enqueue({
1718
+ type: "source",
1719
+ sourceType: "url",
1720
+ id: annotation.url_citation.url,
1721
+ url: annotation.url_citation.url,
1722
+ title: annotation.url_citation.title,
1723
+ providerMetadata: {
1724
+ openrouter: {
1725
+ content: annotation.url_citation.content || ""
1726
+ }
1727
+ }
1728
+ });
1729
+ }
1730
+ }
1731
+ }
1657
1732
  if (delta.tool_calls != null) {
1658
1733
  for (const toolCallDelta of delta.tool_calls) {
1659
1734
  const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
@@ -1764,26 +1839,30 @@ var OpenRouterChatLanguageModel = class {
1764
1839
  }
1765
1840
  }
1766
1841
  }
1842
+ if (reasoningStarted) {
1843
+ controller.enqueue({
1844
+ type: "reasoning-end",
1845
+ id: reasoningId || generateId()
1846
+ });
1847
+ }
1767
1848
  if (textStarted) {
1768
1849
  controller.enqueue({
1769
1850
  type: "text-end",
1770
1851
  id: textId || generateId()
1771
1852
  });
1772
1853
  }
1773
- if (reasoningStarted) {
1774
- controller.enqueue({
1775
- type: "reasoning-end",
1776
- id: reasoningId || generateId()
1777
- });
1854
+ const openrouterMetadata = {
1855
+ usage: openrouterUsage
1856
+ };
1857
+ if (provider !== void 0) {
1858
+ openrouterMetadata.provider = provider;
1778
1859
  }
1779
1860
  controller.enqueue({
1780
1861
  type: "finish",
1781
1862
  finishReason,
1782
1863
  usage,
1783
1864
  providerMetadata: {
1784
- openrouter: {
1785
- usage: openrouterUsage
1786
- }
1865
+ openrouter: openrouterMetadata
1787
1866
  }
1788
1867
  });
1789
1868
  }