@openrouter/ai-sdk-provider 1.2.1 → 1.2.3
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 +17 -13
- package/dist/index.d.ts +17 -13
- package/dist/index.js +217 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +217 -103
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +49 -45
- package/dist/internal/index.d.ts +49 -45
- package/dist/internal/index.js +214 -100
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +214 -100
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +11 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart, ProviderV2 } from '@ai-sdk/provider';
|
|
2
2
|
export { LanguageModelV2, LanguageModelV2Prompt } from '@ai-sdk/provider';
|
|
3
|
+
import * as models from '@openrouter/sdk/models';
|
|
3
4
|
import { z } from 'zod/v4';
|
|
4
5
|
|
|
5
6
|
type OpenRouterChatModelId = string;
|
|
@@ -41,18 +42,21 @@ type OpenRouterChatSettings = {
|
|
|
41
42
|
*/
|
|
42
43
|
user?: string;
|
|
43
44
|
/**
|
|
44
|
-
*
|
|
45
|
+
* Plugin configurations for enabling various capabilities
|
|
45
46
|
*/
|
|
46
47
|
plugins?: Array<{
|
|
47
|
-
id:
|
|
48
|
-
/**
|
|
49
|
-
* Maximum number of search results to include (default: 5)
|
|
50
|
-
*/
|
|
48
|
+
id: models.IdWeb;
|
|
51
49
|
max_results?: number;
|
|
52
|
-
/**
|
|
53
|
-
* Custom search prompt to guide the search query
|
|
54
|
-
*/
|
|
55
50
|
search_prompt?: string;
|
|
51
|
+
engine?: models.Engine;
|
|
52
|
+
} | {
|
|
53
|
+
id: models.IdFileParser;
|
|
54
|
+
max_files?: number;
|
|
55
|
+
pdf?: {
|
|
56
|
+
engine?: models.PdfEngine;
|
|
57
|
+
};
|
|
58
|
+
} | {
|
|
59
|
+
id: models.IdModeration;
|
|
56
60
|
}>;
|
|
57
61
|
/**
|
|
58
62
|
* Built-in web search options for models that support native web search
|
|
@@ -86,7 +90,7 @@ type OpenRouterChatSettings = {
|
|
|
86
90
|
/**
|
|
87
91
|
* Control whether to use providers that may store data
|
|
88
92
|
*/
|
|
89
|
-
data_collection?:
|
|
93
|
+
data_collection?: models.DataCollection;
|
|
90
94
|
/**
|
|
91
95
|
* List of provider slugs to allow for this request
|
|
92
96
|
*/
|
|
@@ -98,11 +102,11 @@ type OpenRouterChatSettings = {
|
|
|
98
102
|
/**
|
|
99
103
|
* List of quantization levels to filter by (e.g. ["int4", "int8"])
|
|
100
104
|
*/
|
|
101
|
-
quantizations?: Array<
|
|
105
|
+
quantizations?: Array<models.Quantization>;
|
|
102
106
|
/**
|
|
103
107
|
* Sort providers by price, throughput, or latency
|
|
104
108
|
*/
|
|
105
|
-
sort?:
|
|
109
|
+
sort?: models.Sort;
|
|
106
110
|
/**
|
|
107
111
|
* Maximum pricing you want to pay for this request
|
|
108
112
|
*/
|
|
@@ -322,7 +326,7 @@ declare class OpenRouterCompletionLanguageModel implements LanguageModelV2 {
|
|
|
322
326
|
doStream(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
|
|
323
327
|
}
|
|
324
328
|
|
|
325
|
-
interface OpenRouterProvider extends
|
|
329
|
+
interface OpenRouterProvider extends ProviderV2 {
|
|
326
330
|
(modelId: OpenRouterChatModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
|
|
327
331
|
(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
|
|
328
332
|
languageModel(modelId: OpenRouterChatModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart, ProviderV2 } from '@ai-sdk/provider';
|
|
2
2
|
export { LanguageModelV2, LanguageModelV2Prompt } from '@ai-sdk/provider';
|
|
3
|
+
import * as models from '@openrouter/sdk/models';
|
|
3
4
|
import { z } from 'zod/v4';
|
|
4
5
|
|
|
5
6
|
type OpenRouterChatModelId = string;
|
|
@@ -41,18 +42,21 @@ type OpenRouterChatSettings = {
|
|
|
41
42
|
*/
|
|
42
43
|
user?: string;
|
|
43
44
|
/**
|
|
44
|
-
*
|
|
45
|
+
* Plugin configurations for enabling various capabilities
|
|
45
46
|
*/
|
|
46
47
|
plugins?: Array<{
|
|
47
|
-
id:
|
|
48
|
-
/**
|
|
49
|
-
* Maximum number of search results to include (default: 5)
|
|
50
|
-
*/
|
|
48
|
+
id: models.IdWeb;
|
|
51
49
|
max_results?: number;
|
|
52
|
-
/**
|
|
53
|
-
* Custom search prompt to guide the search query
|
|
54
|
-
*/
|
|
55
50
|
search_prompt?: string;
|
|
51
|
+
engine?: models.Engine;
|
|
52
|
+
} | {
|
|
53
|
+
id: models.IdFileParser;
|
|
54
|
+
max_files?: number;
|
|
55
|
+
pdf?: {
|
|
56
|
+
engine?: models.PdfEngine;
|
|
57
|
+
};
|
|
58
|
+
} | {
|
|
59
|
+
id: models.IdModeration;
|
|
56
60
|
}>;
|
|
57
61
|
/**
|
|
58
62
|
* Built-in web search options for models that support native web search
|
|
@@ -86,7 +90,7 @@ type OpenRouterChatSettings = {
|
|
|
86
90
|
/**
|
|
87
91
|
* Control whether to use providers that may store data
|
|
88
92
|
*/
|
|
89
|
-
data_collection?:
|
|
93
|
+
data_collection?: models.DataCollection;
|
|
90
94
|
/**
|
|
91
95
|
* List of provider slugs to allow for this request
|
|
92
96
|
*/
|
|
@@ -98,11 +102,11 @@ type OpenRouterChatSettings = {
|
|
|
98
102
|
/**
|
|
99
103
|
* List of quantization levels to filter by (e.g. ["int4", "int8"])
|
|
100
104
|
*/
|
|
101
|
-
quantizations?: Array<
|
|
105
|
+
quantizations?: Array<models.Quantization>;
|
|
102
106
|
/**
|
|
103
107
|
* Sort providers by price, throughput, or latency
|
|
104
108
|
*/
|
|
105
|
-
sort?:
|
|
109
|
+
sort?: models.Sort;
|
|
106
110
|
/**
|
|
107
111
|
* Maximum pricing you want to pay for this request
|
|
108
112
|
*/
|
|
@@ -322,7 +326,7 @@ declare class OpenRouterCompletionLanguageModel implements LanguageModelV2 {
|
|
|
322
326
|
doStream(options: LanguageModelV2CallOptions): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>>;
|
|
323
327
|
}
|
|
324
328
|
|
|
325
|
-
interface OpenRouterProvider extends
|
|
329
|
+
interface OpenRouterProvider extends ProviderV2 {
|
|
326
330
|
(modelId: OpenRouterChatModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
|
|
327
331
|
(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
|
|
328
332
|
languageModel(modelId: OpenRouterChatModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
|
package/dist/index.js
CHANGED
|
@@ -253,6 +253,18 @@ var name9 = "AI_NoContentGeneratedError";
|
|
|
253
253
|
var marker10 = `vercel.ai.error.${name9}`;
|
|
254
254
|
var symbol10 = Symbol.for(marker10);
|
|
255
255
|
var _a10;
|
|
256
|
+
var NoContentGeneratedError = class extends AISDKError {
|
|
257
|
+
// used in isInstance
|
|
258
|
+
constructor({
|
|
259
|
+
message = "No content generated."
|
|
260
|
+
} = {}) {
|
|
261
|
+
super({ name: name9, message });
|
|
262
|
+
this[_a10] = true;
|
|
263
|
+
}
|
|
264
|
+
static isInstance(error) {
|
|
265
|
+
return AISDKError.hasMarker(error, marker10);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
256
268
|
_a10 = symbol10;
|
|
257
269
|
var name10 = "AI_NoSuchModelError";
|
|
258
270
|
var marker11 = `vercel.ai.error.${name10}`;
|
|
@@ -939,7 +951,7 @@ var CommonReasoningDetailSchema = import_v4.z.object({
|
|
|
939
951
|
id: import_v4.z.string().nullish(),
|
|
940
952
|
format: import_v4.z.nativeEnum(ReasoningFormat).nullish(),
|
|
941
953
|
index: import_v4.z.number().optional()
|
|
942
|
-
});
|
|
954
|
+
}).passthrough();
|
|
943
955
|
var ReasoningDetailSummarySchema = import_v4.z.object({
|
|
944
956
|
type: import_v4.z.literal("reasoning.summary" /* Summary */),
|
|
945
957
|
summary: import_v4.z.string()
|
|
@@ -968,12 +980,16 @@ var OutputUnionToReasoningDetailsSchema = import_v4.z.union([
|
|
|
968
980
|
delta: import_v4.z.object({
|
|
969
981
|
reasoning_details: import_v4.z.array(ReasoningDetailsWithUnknownSchema)
|
|
970
982
|
})
|
|
971
|
-
}).transform(
|
|
983
|
+
}).transform(
|
|
984
|
+
(data) => data.delta.reasoning_details.filter(isDefinedOrNotNull)
|
|
985
|
+
),
|
|
972
986
|
import_v4.z.object({
|
|
973
987
|
message: import_v4.z.object({
|
|
974
988
|
reasoning_details: import_v4.z.array(ReasoningDetailsWithUnknownSchema)
|
|
975
989
|
})
|
|
976
|
-
}).transform(
|
|
990
|
+
}).transform(
|
|
991
|
+
(data) => data.message.reasoning_details.filter(isDefinedOrNotNull)
|
|
992
|
+
),
|
|
977
993
|
import_v4.z.object({
|
|
978
994
|
text: import_v4.z.string(),
|
|
979
995
|
reasoning_details: import_v4.z.array(ReasoningDetailsWithUnknownSchema)
|
|
@@ -988,8 +1004,8 @@ var OpenRouterErrorResponseSchema = import_v42.z.object({
|
|
|
988
1004
|
message: import_v42.z.string(),
|
|
989
1005
|
type: import_v42.z.string().nullable().optional().default(null),
|
|
990
1006
|
param: import_v42.z.any().nullable().optional().default(null)
|
|
991
|
-
})
|
|
992
|
-
});
|
|
1007
|
+
}).passthrough()
|
|
1008
|
+
}).passthrough();
|
|
993
1009
|
var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
994
1010
|
errorSchema: OpenRouterErrorResponseSchema,
|
|
995
1011
|
errorToMessage: (data) => data.error.message
|
|
@@ -1004,18 +1020,18 @@ var OpenRouterProviderMetadataSchema = import_v43.z.object({
|
|
|
1004
1020
|
promptTokens: import_v43.z.number(),
|
|
1005
1021
|
promptTokensDetails: import_v43.z.object({
|
|
1006
1022
|
cachedTokens: import_v43.z.number()
|
|
1007
|
-
}).optional(),
|
|
1023
|
+
}).passthrough().optional(),
|
|
1008
1024
|
completionTokens: import_v43.z.number(),
|
|
1009
1025
|
completionTokensDetails: import_v43.z.object({
|
|
1010
1026
|
reasoningTokens: import_v43.z.number()
|
|
1011
|
-
}).optional(),
|
|
1027
|
+
}).passthrough().optional(),
|
|
1012
1028
|
totalTokens: import_v43.z.number(),
|
|
1013
1029
|
cost: import_v43.z.number().optional(),
|
|
1014
1030
|
costDetails: import_v43.z.object({
|
|
1015
1031
|
upstreamInferenceCost: import_v43.z.number()
|
|
1016
|
-
})
|
|
1017
|
-
})
|
|
1018
|
-
});
|
|
1032
|
+
}).passthrough()
|
|
1033
|
+
}).passthrough()
|
|
1034
|
+
}).passthrough();
|
|
1019
1035
|
var OpenRouterProviderOptionsSchema = import_v43.z.object({
|
|
1020
1036
|
openrouter: import_v43.z.object({
|
|
1021
1037
|
reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional()
|
|
@@ -1221,9 +1237,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1221
1237
|
}
|
|
1222
1238
|
}
|
|
1223
1239
|
}
|
|
1224
|
-
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(
|
|
1225
|
-
providerOptions
|
|
1226
|
-
);
|
|
1240
|
+
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
|
|
1227
1241
|
const preservedReasoningDetails = parsedProviderOptions.success ? (_d = (_c = parsedProviderOptions.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details : void 0;
|
|
1228
1242
|
messages.push({
|
|
1229
1243
|
role: "assistant",
|
|
@@ -1286,7 +1300,10 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
1286
1300
|
}
|
|
1287
1301
|
default: {
|
|
1288
1302
|
toolChoice;
|
|
1289
|
-
throw new
|
|
1303
|
+
throw new InvalidArgumentError({
|
|
1304
|
+
argument: "toolChoice",
|
|
1305
|
+
message: `Invalid tool choice type: ${JSON.stringify(toolChoice)}`
|
|
1306
|
+
});
|
|
1290
1307
|
}
|
|
1291
1308
|
}
|
|
1292
1309
|
}
|
|
@@ -1300,8 +1317,8 @@ var ImageResponseSchema = import_v45.z.object({
|
|
|
1300
1317
|
type: import_v45.z.literal("image_url"),
|
|
1301
1318
|
image_url: import_v45.z.object({
|
|
1302
1319
|
url: import_v45.z.string()
|
|
1303
|
-
})
|
|
1304
|
-
});
|
|
1320
|
+
}).passthrough()
|
|
1321
|
+
}).passthrough();
|
|
1305
1322
|
var ImageResponseWithUnknownSchema = import_v45.z.union([
|
|
1306
1323
|
ImageResponseSchema,
|
|
1307
1324
|
import_v45.z.unknown().transform(() => null)
|
|
@@ -1317,69 +1334,101 @@ var OpenRouterChatCompletionBaseResponseSchema = import_v46.z.object({
|
|
|
1317
1334
|
prompt_tokens: import_v46.z.number(),
|
|
1318
1335
|
prompt_tokens_details: import_v46.z.object({
|
|
1319
1336
|
cached_tokens: import_v46.z.number()
|
|
1320
|
-
}).nullish(),
|
|
1337
|
+
}).passthrough().nullish(),
|
|
1321
1338
|
completion_tokens: import_v46.z.number(),
|
|
1322
1339
|
completion_tokens_details: import_v46.z.object({
|
|
1323
1340
|
reasoning_tokens: import_v46.z.number()
|
|
1324
|
-
}).nullish(),
|
|
1341
|
+
}).passthrough().nullish(),
|
|
1325
1342
|
total_tokens: import_v46.z.number(),
|
|
1326
1343
|
cost: import_v46.z.number().optional(),
|
|
1327
1344
|
cost_details: import_v46.z.object({
|
|
1328
1345
|
upstream_inference_cost: import_v46.z.number().nullish()
|
|
1329
|
-
}).nullish()
|
|
1330
|
-
}).nullish()
|
|
1331
|
-
});
|
|
1332
|
-
var OpenRouterNonStreamChatCompletionResponseSchema =
|
|
1333
|
-
choices
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
start_index: import_v46.z.number(),
|
|
1357
|
-
title: import_v46.z.string(),
|
|
1358
|
-
url: import_v46.z.string(),
|
|
1359
|
-
content: import_v46.z.string().optional()
|
|
1360
|
-
})
|
|
1361
|
-
})
|
|
1362
|
-
).nullish()
|
|
1363
|
-
}),
|
|
1364
|
-
index: import_v46.z.number().nullish(),
|
|
1365
|
-
logprobs: import_v46.z.object({
|
|
1366
|
-
content: import_v46.z.array(
|
|
1367
|
-
import_v46.z.object({
|
|
1368
|
-
token: import_v46.z.string(),
|
|
1369
|
-
logprob: import_v46.z.number(),
|
|
1370
|
-
top_logprobs: import_v46.z.array(
|
|
1346
|
+
}).passthrough().nullish()
|
|
1347
|
+
}).passthrough().nullish()
|
|
1348
|
+
}).passthrough();
|
|
1349
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = import_v46.z.union([
|
|
1350
|
+
// Success response with choices
|
|
1351
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1352
|
+
choices: import_v46.z.array(
|
|
1353
|
+
import_v46.z.object({
|
|
1354
|
+
message: import_v46.z.object({
|
|
1355
|
+
role: import_v46.z.literal("assistant"),
|
|
1356
|
+
content: import_v46.z.string().nullable().optional(),
|
|
1357
|
+
reasoning: import_v46.z.string().nullable().optional(),
|
|
1358
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1359
|
+
images: ImageResponseArraySchema.nullish(),
|
|
1360
|
+
tool_calls: import_v46.z.array(
|
|
1361
|
+
import_v46.z.object({
|
|
1362
|
+
id: import_v46.z.string().optional().nullable(),
|
|
1363
|
+
type: import_v46.z.literal("function"),
|
|
1364
|
+
function: import_v46.z.object({
|
|
1365
|
+
name: import_v46.z.string(),
|
|
1366
|
+
arguments: import_v46.z.string()
|
|
1367
|
+
}).passthrough()
|
|
1368
|
+
}).passthrough()
|
|
1369
|
+
).optional(),
|
|
1370
|
+
annotations: import_v46.z.array(
|
|
1371
|
+
import_v46.z.union([
|
|
1372
|
+
// URL citation from web search
|
|
1371
1373
|
import_v46.z.object({
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1374
|
+
type: import_v46.z.literal("url_citation"),
|
|
1375
|
+
url_citation: import_v46.z.object({
|
|
1376
|
+
end_index: import_v46.z.number(),
|
|
1377
|
+
start_index: import_v46.z.number(),
|
|
1378
|
+
title: import_v46.z.string(),
|
|
1379
|
+
url: import_v46.z.string(),
|
|
1380
|
+
content: import_v46.z.string().optional()
|
|
1381
|
+
}).passthrough()
|
|
1382
|
+
}).passthrough(),
|
|
1383
|
+
// File annotation from FileParserPlugin (old format)
|
|
1384
|
+
import_v46.z.object({
|
|
1385
|
+
type: import_v46.z.literal("file_annotation"),
|
|
1386
|
+
file_annotation: import_v46.z.object({
|
|
1387
|
+
file_id: import_v46.z.string(),
|
|
1388
|
+
quote: import_v46.z.string().optional()
|
|
1389
|
+
}).passthrough()
|
|
1390
|
+
}).passthrough(),
|
|
1391
|
+
// File annotation from FileParserPlugin (new format)
|
|
1392
|
+
import_v46.z.object({
|
|
1393
|
+
type: import_v46.z.literal("file"),
|
|
1394
|
+
file: import_v46.z.object({
|
|
1395
|
+
hash: import_v46.z.string(),
|
|
1396
|
+
name: import_v46.z.string(),
|
|
1397
|
+
content: import_v46.z.array(
|
|
1398
|
+
import_v46.z.object({
|
|
1399
|
+
type: import_v46.z.string(),
|
|
1400
|
+
text: import_v46.z.string()
|
|
1401
|
+
}).passthrough()
|
|
1402
|
+
).optional()
|
|
1403
|
+
}).passthrough()
|
|
1404
|
+
}).passthrough()
|
|
1405
|
+
])
|
|
1406
|
+
).nullish()
|
|
1407
|
+
}).passthrough(),
|
|
1408
|
+
index: import_v46.z.number().nullish(),
|
|
1409
|
+
logprobs: import_v46.z.object({
|
|
1410
|
+
content: import_v46.z.array(
|
|
1411
|
+
import_v46.z.object({
|
|
1412
|
+
token: import_v46.z.string(),
|
|
1413
|
+
logprob: import_v46.z.number(),
|
|
1414
|
+
top_logprobs: import_v46.z.array(
|
|
1415
|
+
import_v46.z.object({
|
|
1416
|
+
token: import_v46.z.string(),
|
|
1417
|
+
logprob: import_v46.z.number()
|
|
1418
|
+
}).passthrough()
|
|
1419
|
+
)
|
|
1420
|
+
}).passthrough()
|
|
1421
|
+
).nullable()
|
|
1422
|
+
}).passthrough().nullable().optional(),
|
|
1423
|
+
finish_reason: import_v46.z.string().optional().nullable()
|
|
1424
|
+
}).passthrough()
|
|
1425
|
+
)
|
|
1426
|
+
}),
|
|
1427
|
+
// Error response (HTTP 200 with error payload)
|
|
1428
|
+
OpenRouterErrorResponseSchema.extend({
|
|
1429
|
+
user_id: import_v46.z.string().optional()
|
|
1430
|
+
})
|
|
1431
|
+
]);
|
|
1383
1432
|
var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
|
|
1384
1433
|
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1385
1434
|
choices: import_v46.z.array(
|
|
@@ -1398,22 +1447,47 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
|
|
|
1398
1447
|
function: import_v46.z.object({
|
|
1399
1448
|
name: import_v46.z.string().nullish(),
|
|
1400
1449
|
arguments: import_v46.z.string().nullish()
|
|
1401
|
-
})
|
|
1402
|
-
})
|
|
1450
|
+
}).passthrough()
|
|
1451
|
+
}).passthrough()
|
|
1403
1452
|
).nullish(),
|
|
1404
1453
|
annotations: import_v46.z.array(
|
|
1405
|
-
import_v46.z.
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1454
|
+
import_v46.z.union([
|
|
1455
|
+
// URL citation from web search
|
|
1456
|
+
import_v46.z.object({
|
|
1457
|
+
type: import_v46.z.literal("url_citation"),
|
|
1458
|
+
url_citation: import_v46.z.object({
|
|
1459
|
+
end_index: import_v46.z.number(),
|
|
1460
|
+
start_index: import_v46.z.number(),
|
|
1461
|
+
title: import_v46.z.string(),
|
|
1462
|
+
url: import_v46.z.string(),
|
|
1463
|
+
content: import_v46.z.string().optional()
|
|
1464
|
+
}).passthrough()
|
|
1465
|
+
}).passthrough(),
|
|
1466
|
+
// File annotation from FileParserPlugin (old format)
|
|
1467
|
+
import_v46.z.object({
|
|
1468
|
+
type: import_v46.z.literal("file_annotation"),
|
|
1469
|
+
file_annotation: import_v46.z.object({
|
|
1470
|
+
file_id: import_v46.z.string(),
|
|
1471
|
+
quote: import_v46.z.string().optional()
|
|
1472
|
+
}).passthrough()
|
|
1473
|
+
}).passthrough(),
|
|
1474
|
+
// File annotation from FileParserPlugin (new format)
|
|
1475
|
+
import_v46.z.object({
|
|
1476
|
+
type: import_v46.z.literal("file"),
|
|
1477
|
+
file: import_v46.z.object({
|
|
1478
|
+
hash: import_v46.z.string(),
|
|
1479
|
+
name: import_v46.z.string(),
|
|
1480
|
+
content: import_v46.z.array(
|
|
1481
|
+
import_v46.z.object({
|
|
1482
|
+
type: import_v46.z.string(),
|
|
1483
|
+
text: import_v46.z.string()
|
|
1484
|
+
}).passthrough()
|
|
1485
|
+
).optional()
|
|
1486
|
+
}).passthrough()
|
|
1487
|
+
}).passthrough()
|
|
1488
|
+
])
|
|
1415
1489
|
).nullish()
|
|
1416
|
-
}).nullish(),
|
|
1490
|
+
}).passthrough().nullish(),
|
|
1417
1491
|
logprobs: import_v46.z.object({
|
|
1418
1492
|
content: import_v46.z.array(
|
|
1419
1493
|
import_v46.z.object({
|
|
@@ -1423,14 +1497,14 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
|
|
|
1423
1497
|
import_v46.z.object({
|
|
1424
1498
|
token: import_v46.z.string(),
|
|
1425
1499
|
logprob: import_v46.z.number()
|
|
1426
|
-
})
|
|
1500
|
+
}).passthrough()
|
|
1427
1501
|
)
|
|
1428
|
-
})
|
|
1502
|
+
}).passthrough()
|
|
1429
1503
|
).nullable()
|
|
1430
|
-
}).nullish(),
|
|
1504
|
+
}).passthrough().nullish(),
|
|
1431
1505
|
finish_reason: import_v46.z.string().nullable().optional(),
|
|
1432
1506
|
index: import_v46.z.number().nullish()
|
|
1433
|
-
})
|
|
1507
|
+
}).passthrough()
|
|
1434
1508
|
)
|
|
1435
1509
|
}),
|
|
1436
1510
|
OpenRouterErrorResponseSchema
|
|
@@ -1536,7 +1610,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1536
1610
|
const providerOptions = options.providerOptions || {};
|
|
1537
1611
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1538
1612
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
1539
|
-
const { value:
|
|
1613
|
+
const { value: responseValue, responseHeaders } = await postJsonToApi({
|
|
1540
1614
|
url: this.config.url({
|
|
1541
1615
|
path: "/chat/completions",
|
|
1542
1616
|
modelId: this.modelId
|
|
@@ -1550,9 +1624,26 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1550
1624
|
abortSignal: options.abortSignal,
|
|
1551
1625
|
fetch: this.config.fetch
|
|
1552
1626
|
});
|
|
1627
|
+
if ("error" in responseValue) {
|
|
1628
|
+
const errorData = responseValue.error;
|
|
1629
|
+
throw new APICallError({
|
|
1630
|
+
message: errorData.message,
|
|
1631
|
+
url: this.config.url({
|
|
1632
|
+
path: "/chat/completions",
|
|
1633
|
+
modelId: this.modelId
|
|
1634
|
+
}),
|
|
1635
|
+
requestBodyValues: args,
|
|
1636
|
+
statusCode: 200,
|
|
1637
|
+
responseHeaders,
|
|
1638
|
+
data: errorData
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
const response = responseValue;
|
|
1553
1642
|
const choice = response.choices[0];
|
|
1554
1643
|
if (!choice) {
|
|
1555
|
-
throw new
|
|
1644
|
+
throw new NoContentGeneratedError({
|
|
1645
|
+
message: "No choice in response"
|
|
1646
|
+
});
|
|
1556
1647
|
}
|
|
1557
1648
|
const usageInfo = response.usage ? {
|
|
1558
1649
|
inputTokens: (_a15 = response.usage.prompt_tokens) != null ? _a15 : 0,
|
|
@@ -1912,7 +2003,10 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1912
2003
|
};
|
|
1913
2004
|
const toolCall2 = toolCalls[index];
|
|
1914
2005
|
if (toolCall2 == null) {
|
|
1915
|
-
throw new
|
|
2006
|
+
throw new InvalidResponseDataError({
|
|
2007
|
+
data: { index, toolCallsLength: toolCalls.length },
|
|
2008
|
+
message: `Tool call at index ${index} is missing after creation.`
|
|
2009
|
+
});
|
|
1916
2010
|
}
|
|
1917
2011
|
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1918
2012
|
toolCall2.inputStarted = true;
|
|
@@ -1942,7 +2036,14 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1942
2036
|
}
|
|
1943
2037
|
const toolCall = toolCalls[index];
|
|
1944
2038
|
if (toolCall == null) {
|
|
1945
|
-
throw new
|
|
2039
|
+
throw new InvalidResponseDataError({
|
|
2040
|
+
data: {
|
|
2041
|
+
index,
|
|
2042
|
+
toolCallsLength: toolCalls.length,
|
|
2043
|
+
toolCallDelta
|
|
2044
|
+
},
|
|
2045
|
+
message: `Tool call at index ${index} is missing during merge.`
|
|
2046
|
+
});
|
|
1946
2047
|
}
|
|
1947
2048
|
if (!toolCall.inputStarted) {
|
|
1948
2049
|
toolCall.inputStarted = true;
|
|
@@ -2156,22 +2257,22 @@ var OpenRouterCompletionChunkSchema = import_v47.z.union([
|
|
|
2156
2257
|
tokens: import_v47.z.array(import_v47.z.string()),
|
|
2157
2258
|
token_logprobs: import_v47.z.array(import_v47.z.number()),
|
|
2158
2259
|
top_logprobs: import_v47.z.array(import_v47.z.record(import_v47.z.string(), import_v47.z.number())).nullable()
|
|
2159
|
-
}).nullable().optional()
|
|
2160
|
-
})
|
|
2260
|
+
}).passthrough().nullable().optional()
|
|
2261
|
+
}).passthrough()
|
|
2161
2262
|
),
|
|
2162
2263
|
usage: import_v47.z.object({
|
|
2163
2264
|
prompt_tokens: import_v47.z.number(),
|
|
2164
2265
|
prompt_tokens_details: import_v47.z.object({
|
|
2165
2266
|
cached_tokens: import_v47.z.number()
|
|
2166
|
-
}).nullish(),
|
|
2267
|
+
}).passthrough().nullish(),
|
|
2167
2268
|
completion_tokens: import_v47.z.number(),
|
|
2168
2269
|
completion_tokens_details: import_v47.z.object({
|
|
2169
2270
|
reasoning_tokens: import_v47.z.number()
|
|
2170
|
-
}).nullish(),
|
|
2271
|
+
}).passthrough().nullish(),
|
|
2171
2272
|
total_tokens: import_v47.z.number(),
|
|
2172
2273
|
cost: import_v47.z.number().optional()
|
|
2173
|
-
}).nullish()
|
|
2174
|
-
}),
|
|
2274
|
+
}).passthrough().nullish()
|
|
2275
|
+
}).passthrough(),
|
|
2175
2276
|
OpenRouterErrorResponseSchema
|
|
2176
2277
|
]);
|
|
2177
2278
|
|
|
@@ -2267,11 +2368,24 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
2267
2368
|
fetch: this.config.fetch
|
|
2268
2369
|
});
|
|
2269
2370
|
if ("error" in response) {
|
|
2270
|
-
|
|
2371
|
+
const errorData = response.error;
|
|
2372
|
+
throw new APICallError({
|
|
2373
|
+
message: errorData.message,
|
|
2374
|
+
url: this.config.url({
|
|
2375
|
+
path: "/completions",
|
|
2376
|
+
modelId: this.modelId
|
|
2377
|
+
}),
|
|
2378
|
+
requestBodyValues: args,
|
|
2379
|
+
statusCode: 200,
|
|
2380
|
+
responseHeaders,
|
|
2381
|
+
data: errorData
|
|
2382
|
+
});
|
|
2271
2383
|
}
|
|
2272
2384
|
const choice = response.choices[0];
|
|
2273
2385
|
if (!choice) {
|
|
2274
|
-
throw new
|
|
2386
|
+
throw new NoContentGeneratedError({
|
|
2387
|
+
message: "No choice in OpenRouter completion response"
|
|
2388
|
+
});
|
|
2275
2389
|
}
|
|
2276
2390
|
return {
|
|
2277
2391
|
content: [
|
|
@@ -2438,9 +2552,6 @@ var OpenRouter = class {
|
|
|
2438
2552
|
}
|
|
2439
2553
|
};
|
|
2440
2554
|
|
|
2441
|
-
// src/version.ts
|
|
2442
|
-
var VERSION = false ? "0.0.0-test" : "1.2.1";
|
|
2443
|
-
|
|
2444
2555
|
// src/utils/remove-undefined.ts
|
|
2445
2556
|
function removeUndefinedEntries2(record) {
|
|
2446
2557
|
return Object.fromEntries(
|
|
@@ -2460,6 +2571,9 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
2460
2571
|
});
|
|
2461
2572
|
}
|
|
2462
2573
|
|
|
2574
|
+
// src/version.ts
|
|
2575
|
+
var VERSION = false ? "0.0.0-test" : "1.2.3";
|
|
2576
|
+
|
|
2463
2577
|
// src/provider.ts
|
|
2464
2578
|
function createOpenRouter(options = {}) {
|
|
2465
2579
|
var _a15, _b, _c;
|