@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 +75 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.js +89 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -14
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +75 -0
- package/dist/internal/index.d.ts +75 -0
- package/dist/internal/index.js +89 -14
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +89 -14
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -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
|
};
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -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
|
};
|
package/dist/internal/index.js
CHANGED
|
@@ -1177,6 +1177,7 @@ var import_v44 = require("zod/v4");
|
|
|
1177
1177
|
var OpenRouterChatCompletionBaseResponseSchema = import_v44.z.object({
|
|
1178
1178
|
id: import_v44.z.string().optional(),
|
|
1179
1179
|
model: import_v44.z.string().optional(),
|
|
1180
|
+
provider: import_v44.z.string().optional(),
|
|
1180
1181
|
usage: import_v44.z.object({
|
|
1181
1182
|
prompt_tokens: import_v44.z.number(),
|
|
1182
1183
|
prompt_tokens_details: import_v44.z.object({
|
|
@@ -1210,7 +1211,19 @@ var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBa
|
|
|
1210
1211
|
arguments: import_v44.z.string()
|
|
1211
1212
|
})
|
|
1212
1213
|
})
|
|
1213
|
-
).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()
|
|
1214
1227
|
}),
|
|
1215
1228
|
index: import_v44.z.number().nullish(),
|
|
1216
1229
|
logprobs: import_v44.z.object({
|
|
@@ -1250,6 +1263,18 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v44.z.union([
|
|
|
1250
1263
|
arguments: import_v44.z.string().nullish()
|
|
1251
1264
|
})
|
|
1252
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
|
+
})
|
|
1253
1278
|
).nullish()
|
|
1254
1279
|
}).nullish(),
|
|
1255
1280
|
logprobs: import_v44.z.object({
|
|
@@ -1332,7 +1357,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1332
1357
|
// OpenRouter specific settings:
|
|
1333
1358
|
include_reasoning: this.settings.includeReasoning,
|
|
1334
1359
|
reasoning: this.settings.reasoning,
|
|
1335
|
-
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
|
|
1336
1366
|
}, this.config.extraBody), this.settings.extraBody);
|
|
1337
1367
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
1338
1368
|
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
@@ -1353,7 +1383,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1353
1383
|
type: "function",
|
|
1354
1384
|
function: {
|
|
1355
1385
|
name: tool.name,
|
|
1356
|
-
description: tool.
|
|
1386
|
+
description: tool.description,
|
|
1357
1387
|
parameters: tool.inputSchema
|
|
1358
1388
|
}
|
|
1359
1389
|
}));
|
|
@@ -1365,7 +1395,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1365
1395
|
return baseArgs;
|
|
1366
1396
|
}
|
|
1367
1397
|
async doGenerate(options) {
|
|
1368
|
-
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;
|
|
1369
1399
|
const providerOptions = options.providerOptions || {};
|
|
1370
1400
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1371
1401
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1459,6 +1489,24 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1459
1489
|
});
|
|
1460
1490
|
}
|
|
1461
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
|
+
}
|
|
1462
1510
|
return {
|
|
1463
1511
|
content,
|
|
1464
1512
|
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
@@ -1466,19 +1514,20 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1466
1514
|
warnings: [],
|
|
1467
1515
|
providerMetadata: {
|
|
1468
1516
|
openrouter: {
|
|
1517
|
+
provider: (_k = response.provider) != null ? _k : "",
|
|
1469
1518
|
usage: {
|
|
1470
|
-
promptTokens: (
|
|
1471
|
-
completionTokens: (
|
|
1472
|
-
totalTokens: (
|
|
1473
|
-
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,
|
|
1474
1523
|
promptTokensDetails: {
|
|
1475
|
-
cachedTokens: (
|
|
1524
|
+
cachedTokens: (_r = (_q = (_p = response.usage) == null ? void 0 : _p.prompt_tokens_details) == null ? void 0 : _q.cached_tokens) != null ? _r : 0
|
|
1476
1525
|
},
|
|
1477
1526
|
completionTokensDetails: {
|
|
1478
|
-
reasoningTokens: (
|
|
1527
|
+
reasoningTokens: (_u = (_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? _u : 0
|
|
1479
1528
|
},
|
|
1480
1529
|
costDetails: {
|
|
1481
|
-
upstreamInferenceCost: (
|
|
1530
|
+
upstreamInferenceCost: (_x = (_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? _x : 0
|
|
1482
1531
|
}
|
|
1483
1532
|
}
|
|
1484
1533
|
}
|
|
@@ -1531,6 +1580,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1531
1580
|
let textId;
|
|
1532
1581
|
let reasoningId;
|
|
1533
1582
|
let openrouterResponseId;
|
|
1583
|
+
let provider;
|
|
1534
1584
|
return {
|
|
1535
1585
|
stream: response.pipeThrough(
|
|
1536
1586
|
new TransformStream({
|
|
@@ -1547,6 +1597,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1547
1597
|
controller.enqueue({ type: "error", error: value.error });
|
|
1548
1598
|
return;
|
|
1549
1599
|
}
|
|
1600
|
+
if (value.provider) {
|
|
1601
|
+
provider = value.provider;
|
|
1602
|
+
}
|
|
1550
1603
|
if (value.id) {
|
|
1551
1604
|
openrouterResponseId = value.id;
|
|
1552
1605
|
controller.enqueue({
|
|
@@ -1658,6 +1711,24 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1658
1711
|
id: textId || generateId()
|
|
1659
1712
|
});
|
|
1660
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
|
+
}
|
|
1661
1732
|
if (delta.tool_calls != null) {
|
|
1662
1733
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1663
1734
|
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
|
|
@@ -1780,14 +1851,18 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1780
1851
|
id: textId || generateId()
|
|
1781
1852
|
});
|
|
1782
1853
|
}
|
|
1854
|
+
const openrouterMetadata = {
|
|
1855
|
+
usage: openrouterUsage
|
|
1856
|
+
};
|
|
1857
|
+
if (provider !== void 0) {
|
|
1858
|
+
openrouterMetadata.provider = provider;
|
|
1859
|
+
}
|
|
1783
1860
|
controller.enqueue({
|
|
1784
1861
|
type: "finish",
|
|
1785
1862
|
finishReason,
|
|
1786
1863
|
usage,
|
|
1787
1864
|
providerMetadata: {
|
|
1788
|
-
openrouter:
|
|
1789
|
-
usage: openrouterUsage
|
|
1790
|
-
}
|
|
1865
|
+
openrouter: openrouterMetadata
|
|
1791
1866
|
}
|
|
1792
1867
|
});
|
|
1793
1868
|
}
|