@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
package/dist/internal/index.mjs
CHANGED
|
@@ -1143,6 +1143,7 @@ import { z as z5 } from "zod/v4";
|
|
|
1143
1143
|
var OpenRouterChatCompletionBaseResponseSchema = z5.object({
|
|
1144
1144
|
id: z5.string().optional(),
|
|
1145
1145
|
model: z5.string().optional(),
|
|
1146
|
+
provider: z5.string().optional(),
|
|
1146
1147
|
usage: z5.object({
|
|
1147
1148
|
prompt_tokens: z5.number(),
|
|
1148
1149
|
prompt_tokens_details: z5.object({
|
|
@@ -1176,7 +1177,19 @@ var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBa
|
|
|
1176
1177
|
arguments: z5.string()
|
|
1177
1178
|
})
|
|
1178
1179
|
})
|
|
1179
|
-
).optional()
|
|
1180
|
+
).optional(),
|
|
1181
|
+
annotations: z5.array(
|
|
1182
|
+
z5.object({
|
|
1183
|
+
type: z5.enum(["url_citation"]),
|
|
1184
|
+
url_citation: z5.object({
|
|
1185
|
+
end_index: z5.number(),
|
|
1186
|
+
start_index: z5.number(),
|
|
1187
|
+
title: z5.string(),
|
|
1188
|
+
url: z5.string(),
|
|
1189
|
+
content: z5.string().optional()
|
|
1190
|
+
})
|
|
1191
|
+
})
|
|
1192
|
+
).nullish()
|
|
1180
1193
|
}),
|
|
1181
1194
|
index: z5.number().nullish(),
|
|
1182
1195
|
logprobs: z5.object({
|
|
@@ -1216,6 +1229,18 @@ var OpenRouterStreamChatCompletionChunkSchema = z5.union([
|
|
|
1216
1229
|
arguments: z5.string().nullish()
|
|
1217
1230
|
})
|
|
1218
1231
|
})
|
|
1232
|
+
).nullish(),
|
|
1233
|
+
annotations: z5.array(
|
|
1234
|
+
z5.object({
|
|
1235
|
+
type: z5.enum(["url_citation"]),
|
|
1236
|
+
url_citation: z5.object({
|
|
1237
|
+
end_index: z5.number(),
|
|
1238
|
+
start_index: z5.number(),
|
|
1239
|
+
title: z5.string(),
|
|
1240
|
+
url: z5.string(),
|
|
1241
|
+
content: z5.string().optional()
|
|
1242
|
+
})
|
|
1243
|
+
})
|
|
1219
1244
|
).nullish()
|
|
1220
1245
|
}).nullish(),
|
|
1221
1246
|
logprobs: z5.object({
|
|
@@ -1298,7 +1323,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1298
1323
|
// OpenRouter specific settings:
|
|
1299
1324
|
include_reasoning: this.settings.includeReasoning,
|
|
1300
1325
|
reasoning: this.settings.reasoning,
|
|
1301
|
-
usage: this.settings.usage
|
|
1326
|
+
usage: this.settings.usage,
|
|
1327
|
+
// Web search settings:
|
|
1328
|
+
plugins: this.settings.plugins,
|
|
1329
|
+
web_search_options: this.settings.web_search_options,
|
|
1330
|
+
// Provider routing settings:
|
|
1331
|
+
provider: this.settings.provider
|
|
1302
1332
|
}, this.config.extraBody), this.settings.extraBody);
|
|
1303
1333
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
1304
1334
|
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
@@ -1319,7 +1349,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1319
1349
|
type: "function",
|
|
1320
1350
|
function: {
|
|
1321
1351
|
name: tool.name,
|
|
1322
|
-
description: tool.
|
|
1352
|
+
description: tool.description,
|
|
1323
1353
|
parameters: tool.inputSchema
|
|
1324
1354
|
}
|
|
1325
1355
|
}));
|
|
@@ -1331,7 +1361,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1331
1361
|
return baseArgs;
|
|
1332
1362
|
}
|
|
1333
1363
|
async doGenerate(options) {
|
|
1334
|
-
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1364
|
+
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;
|
|
1335
1365
|
const providerOptions = options.providerOptions || {};
|
|
1336
1366
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1337
1367
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1425,6 +1455,24 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1425
1455
|
});
|
|
1426
1456
|
}
|
|
1427
1457
|
}
|
|
1458
|
+
if (choice.message.annotations) {
|
|
1459
|
+
for (const annotation of choice.message.annotations) {
|
|
1460
|
+
if (annotation.type === "url_citation") {
|
|
1461
|
+
content.push({
|
|
1462
|
+
type: "source",
|
|
1463
|
+
sourceType: "url",
|
|
1464
|
+
id: annotation.url_citation.url,
|
|
1465
|
+
url: annotation.url_citation.url,
|
|
1466
|
+
title: annotation.url_citation.title,
|
|
1467
|
+
providerMetadata: {
|
|
1468
|
+
openrouter: {
|
|
1469
|
+
content: annotation.url_citation.content || ""
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1428
1476
|
return {
|
|
1429
1477
|
content,
|
|
1430
1478
|
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
@@ -1432,19 +1480,20 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1432
1480
|
warnings: [],
|
|
1433
1481
|
providerMetadata: {
|
|
1434
1482
|
openrouter: {
|
|
1483
|
+
provider: (_k = response.provider) != null ? _k : "",
|
|
1435
1484
|
usage: {
|
|
1436
|
-
promptTokens: (
|
|
1437
|
-
completionTokens: (
|
|
1438
|
-
totalTokens: (
|
|
1439
|
-
cost: (
|
|
1485
|
+
promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
|
|
1486
|
+
completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
|
|
1487
|
+
totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
|
|
1488
|
+
cost: (_o = response.usage) == null ? void 0 : _o.cost,
|
|
1440
1489
|
promptTokensDetails: {
|
|
1441
|
-
cachedTokens: (
|
|
1490
|
+
cachedTokens: (_r = (_q = (_p = response.usage) == null ? void 0 : _p.prompt_tokens_details) == null ? void 0 : _q.cached_tokens) != null ? _r : 0
|
|
1442
1491
|
},
|
|
1443
1492
|
completionTokensDetails: {
|
|
1444
|
-
reasoningTokens: (
|
|
1493
|
+
reasoningTokens: (_u = (_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? _u : 0
|
|
1445
1494
|
},
|
|
1446
1495
|
costDetails: {
|
|
1447
|
-
upstreamInferenceCost: (
|
|
1496
|
+
upstreamInferenceCost: (_x = (_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? _x : 0
|
|
1448
1497
|
}
|
|
1449
1498
|
}
|
|
1450
1499
|
}
|
|
@@ -1497,6 +1546,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1497
1546
|
let textId;
|
|
1498
1547
|
let reasoningId;
|
|
1499
1548
|
let openrouterResponseId;
|
|
1549
|
+
let provider;
|
|
1500
1550
|
return {
|
|
1501
1551
|
stream: response.pipeThrough(
|
|
1502
1552
|
new TransformStream({
|
|
@@ -1513,6 +1563,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1513
1563
|
controller.enqueue({ type: "error", error: value.error });
|
|
1514
1564
|
return;
|
|
1515
1565
|
}
|
|
1566
|
+
if (value.provider) {
|
|
1567
|
+
provider = value.provider;
|
|
1568
|
+
}
|
|
1516
1569
|
if (value.id) {
|
|
1517
1570
|
openrouterResponseId = value.id;
|
|
1518
1571
|
controller.enqueue({
|
|
@@ -1624,6 +1677,24 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1624
1677
|
id: textId || generateId()
|
|
1625
1678
|
});
|
|
1626
1679
|
}
|
|
1680
|
+
if (delta.annotations) {
|
|
1681
|
+
for (const annotation of delta.annotations) {
|
|
1682
|
+
if (annotation.type === "url_citation") {
|
|
1683
|
+
controller.enqueue({
|
|
1684
|
+
type: "source",
|
|
1685
|
+
sourceType: "url",
|
|
1686
|
+
id: annotation.url_citation.url,
|
|
1687
|
+
url: annotation.url_citation.url,
|
|
1688
|
+
title: annotation.url_citation.title,
|
|
1689
|
+
providerMetadata: {
|
|
1690
|
+
openrouter: {
|
|
1691
|
+
content: annotation.url_citation.content || ""
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1627
1698
|
if (delta.tool_calls != null) {
|
|
1628
1699
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1629
1700
|
const index = (_c = toolCallDelta.index) != null ? _c : toolCalls.length - 1;
|
|
@@ -1746,14 +1817,18 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1746
1817
|
id: textId || generateId()
|
|
1747
1818
|
});
|
|
1748
1819
|
}
|
|
1820
|
+
const openrouterMetadata = {
|
|
1821
|
+
usage: openrouterUsage
|
|
1822
|
+
};
|
|
1823
|
+
if (provider !== void 0) {
|
|
1824
|
+
openrouterMetadata.provider = provider;
|
|
1825
|
+
}
|
|
1749
1826
|
controller.enqueue({
|
|
1750
1827
|
type: "finish",
|
|
1751
1828
|
finishReason,
|
|
1752
1829
|
usage,
|
|
1753
1830
|
providerMetadata: {
|
|
1754
|
-
openrouter:
|
|
1755
|
-
usage: openrouterUsage
|
|
1756
|
-
}
|
|
1831
|
+
openrouter: openrouterMetadata
|
|
1757
1832
|
}
|
|
1758
1833
|
});
|
|
1759
1834
|
}
|