@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/internal/index.mjs
CHANGED
|
@@ -208,6 +208,18 @@ var name9 = "AI_NoContentGeneratedError";
|
|
|
208
208
|
var marker10 = `vercel.ai.error.${name9}`;
|
|
209
209
|
var symbol10 = Symbol.for(marker10);
|
|
210
210
|
var _a10;
|
|
211
|
+
var NoContentGeneratedError = class extends AISDKError {
|
|
212
|
+
// used in isInstance
|
|
213
|
+
constructor({
|
|
214
|
+
message = "No content generated."
|
|
215
|
+
} = {}) {
|
|
216
|
+
super({ name: name9, message });
|
|
217
|
+
this[_a10] = true;
|
|
218
|
+
}
|
|
219
|
+
static isInstance(error) {
|
|
220
|
+
return AISDKError.hasMarker(error, marker10);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
211
223
|
_a10 = symbol10;
|
|
212
224
|
var name10 = "AI_NoSuchModelError";
|
|
213
225
|
var marker11 = `vercel.ai.error.${name10}`;
|
|
@@ -859,7 +871,7 @@ var CommonReasoningDetailSchema = z.object({
|
|
|
859
871
|
id: z.string().nullish(),
|
|
860
872
|
format: z.nativeEnum(ReasoningFormat).nullish(),
|
|
861
873
|
index: z.number().optional()
|
|
862
|
-
});
|
|
874
|
+
}).passthrough();
|
|
863
875
|
var ReasoningDetailSummarySchema = z.object({
|
|
864
876
|
type: z.literal("reasoning.summary" /* Summary */),
|
|
865
877
|
summary: z.string()
|
|
@@ -888,12 +900,16 @@ var OutputUnionToReasoningDetailsSchema = z.union([
|
|
|
888
900
|
delta: z.object({
|
|
889
901
|
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
890
902
|
})
|
|
891
|
-
}).transform(
|
|
903
|
+
}).transform(
|
|
904
|
+
(data) => data.delta.reasoning_details.filter(isDefinedOrNotNull)
|
|
905
|
+
),
|
|
892
906
|
z.object({
|
|
893
907
|
message: z.object({
|
|
894
908
|
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
895
909
|
})
|
|
896
|
-
}).transform(
|
|
910
|
+
}).transform(
|
|
911
|
+
(data) => data.message.reasoning_details.filter(isDefinedOrNotNull)
|
|
912
|
+
),
|
|
897
913
|
z.object({
|
|
898
914
|
text: z.string(),
|
|
899
915
|
reasoning_details: z.array(ReasoningDetailsWithUnknownSchema)
|
|
@@ -908,8 +924,8 @@ var OpenRouterErrorResponseSchema = z2.object({
|
|
|
908
924
|
message: z2.string(),
|
|
909
925
|
type: z2.string().nullable().optional().default(null),
|
|
910
926
|
param: z2.any().nullable().optional().default(null)
|
|
911
|
-
})
|
|
912
|
-
});
|
|
927
|
+
}).passthrough()
|
|
928
|
+
}).passthrough();
|
|
913
929
|
var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
914
930
|
errorSchema: OpenRouterErrorResponseSchema,
|
|
915
931
|
errorToMessage: (data) => data.error.message
|
|
@@ -924,18 +940,18 @@ var OpenRouterProviderMetadataSchema = z3.object({
|
|
|
924
940
|
promptTokens: z3.number(),
|
|
925
941
|
promptTokensDetails: z3.object({
|
|
926
942
|
cachedTokens: z3.number()
|
|
927
|
-
}).optional(),
|
|
943
|
+
}).passthrough().optional(),
|
|
928
944
|
completionTokens: z3.number(),
|
|
929
945
|
completionTokensDetails: z3.object({
|
|
930
946
|
reasoningTokens: z3.number()
|
|
931
|
-
}).optional(),
|
|
947
|
+
}).passthrough().optional(),
|
|
932
948
|
totalTokens: z3.number(),
|
|
933
949
|
cost: z3.number().optional(),
|
|
934
950
|
costDetails: z3.object({
|
|
935
951
|
upstreamInferenceCost: z3.number()
|
|
936
|
-
})
|
|
937
|
-
})
|
|
938
|
-
});
|
|
952
|
+
}).passthrough()
|
|
953
|
+
}).passthrough()
|
|
954
|
+
}).passthrough();
|
|
939
955
|
var OpenRouterProviderOptionsSchema = z3.object({
|
|
940
956
|
openrouter: z3.object({
|
|
941
957
|
reasoning_details: z3.array(ReasoningDetailUnionSchema).optional()
|
|
@@ -1141,9 +1157,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1141
1157
|
}
|
|
1142
1158
|
}
|
|
1143
1159
|
}
|
|
1144
|
-
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(
|
|
1145
|
-
providerOptions
|
|
1146
|
-
);
|
|
1160
|
+
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
|
|
1147
1161
|
const preservedReasoningDetails = parsedProviderOptions.success ? (_d = (_c = parsedProviderOptions.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details : void 0;
|
|
1148
1162
|
messages.push({
|
|
1149
1163
|
role: "assistant",
|
|
@@ -1206,7 +1220,10 @@ function getChatCompletionToolChoice(toolChoice) {
|
|
|
1206
1220
|
}
|
|
1207
1221
|
default: {
|
|
1208
1222
|
toolChoice;
|
|
1209
|
-
throw new
|
|
1223
|
+
throw new InvalidArgumentError({
|
|
1224
|
+
argument: "toolChoice",
|
|
1225
|
+
message: `Invalid tool choice type: ${JSON.stringify(toolChoice)}`
|
|
1226
|
+
});
|
|
1210
1227
|
}
|
|
1211
1228
|
}
|
|
1212
1229
|
}
|
|
@@ -1220,8 +1237,8 @@ var ImageResponseSchema = z6.object({
|
|
|
1220
1237
|
type: z6.literal("image_url"),
|
|
1221
1238
|
image_url: z6.object({
|
|
1222
1239
|
url: z6.string()
|
|
1223
|
-
})
|
|
1224
|
-
});
|
|
1240
|
+
}).passthrough()
|
|
1241
|
+
}).passthrough();
|
|
1225
1242
|
var ImageResponseWithUnknownSchema = z6.union([
|
|
1226
1243
|
ImageResponseSchema,
|
|
1227
1244
|
z6.unknown().transform(() => null)
|
|
@@ -1237,69 +1254,101 @@ var OpenRouterChatCompletionBaseResponseSchema = z7.object({
|
|
|
1237
1254
|
prompt_tokens: z7.number(),
|
|
1238
1255
|
prompt_tokens_details: z7.object({
|
|
1239
1256
|
cached_tokens: z7.number()
|
|
1240
|
-
}).nullish(),
|
|
1257
|
+
}).passthrough().nullish(),
|
|
1241
1258
|
completion_tokens: z7.number(),
|
|
1242
1259
|
completion_tokens_details: z7.object({
|
|
1243
1260
|
reasoning_tokens: z7.number()
|
|
1244
|
-
}).nullish(),
|
|
1261
|
+
}).passthrough().nullish(),
|
|
1245
1262
|
total_tokens: z7.number(),
|
|
1246
1263
|
cost: z7.number().optional(),
|
|
1247
1264
|
cost_details: z7.object({
|
|
1248
1265
|
upstream_inference_cost: z7.number().nullish()
|
|
1249
|
-
}).nullish()
|
|
1250
|
-
}).nullish()
|
|
1251
|
-
});
|
|
1252
|
-
var OpenRouterNonStreamChatCompletionResponseSchema =
|
|
1253
|
-
choices
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
start_index: z7.number(),
|
|
1277
|
-
title: z7.string(),
|
|
1278
|
-
url: z7.string(),
|
|
1279
|
-
content: z7.string().optional()
|
|
1280
|
-
})
|
|
1281
|
-
})
|
|
1282
|
-
).nullish()
|
|
1283
|
-
}),
|
|
1284
|
-
index: z7.number().nullish(),
|
|
1285
|
-
logprobs: z7.object({
|
|
1286
|
-
content: z7.array(
|
|
1287
|
-
z7.object({
|
|
1288
|
-
token: z7.string(),
|
|
1289
|
-
logprob: z7.number(),
|
|
1290
|
-
top_logprobs: z7.array(
|
|
1266
|
+
}).passthrough().nullish()
|
|
1267
|
+
}).passthrough().nullish()
|
|
1268
|
+
}).passthrough();
|
|
1269
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
|
|
1270
|
+
// Success response with choices
|
|
1271
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1272
|
+
choices: z7.array(
|
|
1273
|
+
z7.object({
|
|
1274
|
+
message: z7.object({
|
|
1275
|
+
role: z7.literal("assistant"),
|
|
1276
|
+
content: z7.string().nullable().optional(),
|
|
1277
|
+
reasoning: z7.string().nullable().optional(),
|
|
1278
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1279
|
+
images: ImageResponseArraySchema.nullish(),
|
|
1280
|
+
tool_calls: z7.array(
|
|
1281
|
+
z7.object({
|
|
1282
|
+
id: z7.string().optional().nullable(),
|
|
1283
|
+
type: z7.literal("function"),
|
|
1284
|
+
function: z7.object({
|
|
1285
|
+
name: z7.string(),
|
|
1286
|
+
arguments: z7.string()
|
|
1287
|
+
}).passthrough()
|
|
1288
|
+
}).passthrough()
|
|
1289
|
+
).optional(),
|
|
1290
|
+
annotations: z7.array(
|
|
1291
|
+
z7.union([
|
|
1292
|
+
// URL citation from web search
|
|
1291
1293
|
z7.object({
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1294
|
+
type: z7.literal("url_citation"),
|
|
1295
|
+
url_citation: z7.object({
|
|
1296
|
+
end_index: z7.number(),
|
|
1297
|
+
start_index: z7.number(),
|
|
1298
|
+
title: z7.string(),
|
|
1299
|
+
url: z7.string(),
|
|
1300
|
+
content: z7.string().optional()
|
|
1301
|
+
}).passthrough()
|
|
1302
|
+
}).passthrough(),
|
|
1303
|
+
// File annotation from FileParserPlugin (old format)
|
|
1304
|
+
z7.object({
|
|
1305
|
+
type: z7.literal("file_annotation"),
|
|
1306
|
+
file_annotation: z7.object({
|
|
1307
|
+
file_id: z7.string(),
|
|
1308
|
+
quote: z7.string().optional()
|
|
1309
|
+
}).passthrough()
|
|
1310
|
+
}).passthrough(),
|
|
1311
|
+
// File annotation from FileParserPlugin (new format)
|
|
1312
|
+
z7.object({
|
|
1313
|
+
type: z7.literal("file"),
|
|
1314
|
+
file: z7.object({
|
|
1315
|
+
hash: z7.string(),
|
|
1316
|
+
name: z7.string(),
|
|
1317
|
+
content: z7.array(
|
|
1318
|
+
z7.object({
|
|
1319
|
+
type: z7.string(),
|
|
1320
|
+
text: z7.string()
|
|
1321
|
+
}).passthrough()
|
|
1322
|
+
).optional()
|
|
1323
|
+
}).passthrough()
|
|
1324
|
+
}).passthrough()
|
|
1325
|
+
])
|
|
1326
|
+
).nullish()
|
|
1327
|
+
}).passthrough(),
|
|
1328
|
+
index: z7.number().nullish(),
|
|
1329
|
+
logprobs: z7.object({
|
|
1330
|
+
content: z7.array(
|
|
1331
|
+
z7.object({
|
|
1332
|
+
token: z7.string(),
|
|
1333
|
+
logprob: z7.number(),
|
|
1334
|
+
top_logprobs: z7.array(
|
|
1335
|
+
z7.object({
|
|
1336
|
+
token: z7.string(),
|
|
1337
|
+
logprob: z7.number()
|
|
1338
|
+
}).passthrough()
|
|
1339
|
+
)
|
|
1340
|
+
}).passthrough()
|
|
1341
|
+
).nullable()
|
|
1342
|
+
}).passthrough().nullable().optional(),
|
|
1343
|
+
finish_reason: z7.string().optional().nullable()
|
|
1344
|
+
}).passthrough()
|
|
1345
|
+
)
|
|
1346
|
+
}),
|
|
1347
|
+
// Error response (HTTP 200 with error payload)
|
|
1348
|
+
OpenRouterErrorResponseSchema.extend({
|
|
1349
|
+
user_id: z7.string().optional()
|
|
1350
|
+
})
|
|
1351
|
+
]);
|
|
1303
1352
|
var OpenRouterStreamChatCompletionChunkSchema = z7.union([
|
|
1304
1353
|
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
1305
1354
|
choices: z7.array(
|
|
@@ -1318,22 +1367,47 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
|
|
|
1318
1367
|
function: z7.object({
|
|
1319
1368
|
name: z7.string().nullish(),
|
|
1320
1369
|
arguments: z7.string().nullish()
|
|
1321
|
-
})
|
|
1322
|
-
})
|
|
1370
|
+
}).passthrough()
|
|
1371
|
+
}).passthrough()
|
|
1323
1372
|
).nullish(),
|
|
1324
1373
|
annotations: z7.array(
|
|
1325
|
-
z7.
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1374
|
+
z7.union([
|
|
1375
|
+
// URL citation from web search
|
|
1376
|
+
z7.object({
|
|
1377
|
+
type: z7.literal("url_citation"),
|
|
1378
|
+
url_citation: z7.object({
|
|
1379
|
+
end_index: z7.number(),
|
|
1380
|
+
start_index: z7.number(),
|
|
1381
|
+
title: z7.string(),
|
|
1382
|
+
url: z7.string(),
|
|
1383
|
+
content: z7.string().optional()
|
|
1384
|
+
}).passthrough()
|
|
1385
|
+
}).passthrough(),
|
|
1386
|
+
// File annotation from FileParserPlugin (old format)
|
|
1387
|
+
z7.object({
|
|
1388
|
+
type: z7.literal("file_annotation"),
|
|
1389
|
+
file_annotation: z7.object({
|
|
1390
|
+
file_id: z7.string(),
|
|
1391
|
+
quote: z7.string().optional()
|
|
1392
|
+
}).passthrough()
|
|
1393
|
+
}).passthrough(),
|
|
1394
|
+
// File annotation from FileParserPlugin (new format)
|
|
1395
|
+
z7.object({
|
|
1396
|
+
type: z7.literal("file"),
|
|
1397
|
+
file: z7.object({
|
|
1398
|
+
hash: z7.string(),
|
|
1399
|
+
name: z7.string(),
|
|
1400
|
+
content: z7.array(
|
|
1401
|
+
z7.object({
|
|
1402
|
+
type: z7.string(),
|
|
1403
|
+
text: z7.string()
|
|
1404
|
+
}).passthrough()
|
|
1405
|
+
).optional()
|
|
1406
|
+
}).passthrough()
|
|
1407
|
+
}).passthrough()
|
|
1408
|
+
])
|
|
1335
1409
|
).nullish()
|
|
1336
|
-
}).nullish(),
|
|
1410
|
+
}).passthrough().nullish(),
|
|
1337
1411
|
logprobs: z7.object({
|
|
1338
1412
|
content: z7.array(
|
|
1339
1413
|
z7.object({
|
|
@@ -1343,14 +1417,14 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
|
|
|
1343
1417
|
z7.object({
|
|
1344
1418
|
token: z7.string(),
|
|
1345
1419
|
logprob: z7.number()
|
|
1346
|
-
})
|
|
1420
|
+
}).passthrough()
|
|
1347
1421
|
)
|
|
1348
|
-
})
|
|
1422
|
+
}).passthrough()
|
|
1349
1423
|
).nullable()
|
|
1350
|
-
}).nullish(),
|
|
1424
|
+
}).passthrough().nullish(),
|
|
1351
1425
|
finish_reason: z7.string().nullable().optional(),
|
|
1352
1426
|
index: z7.number().nullish()
|
|
1353
|
-
})
|
|
1427
|
+
}).passthrough()
|
|
1354
1428
|
)
|
|
1355
1429
|
}),
|
|
1356
1430
|
OpenRouterErrorResponseSchema
|
|
@@ -1456,7 +1530,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1456
1530
|
const providerOptions = options.providerOptions || {};
|
|
1457
1531
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1458
1532
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
1459
|
-
const { value:
|
|
1533
|
+
const { value: responseValue, responseHeaders } = await postJsonToApi({
|
|
1460
1534
|
url: this.config.url({
|
|
1461
1535
|
path: "/chat/completions",
|
|
1462
1536
|
modelId: this.modelId
|
|
@@ -1470,9 +1544,26 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1470
1544
|
abortSignal: options.abortSignal,
|
|
1471
1545
|
fetch: this.config.fetch
|
|
1472
1546
|
});
|
|
1547
|
+
if ("error" in responseValue) {
|
|
1548
|
+
const errorData = responseValue.error;
|
|
1549
|
+
throw new APICallError({
|
|
1550
|
+
message: errorData.message,
|
|
1551
|
+
url: this.config.url({
|
|
1552
|
+
path: "/chat/completions",
|
|
1553
|
+
modelId: this.modelId
|
|
1554
|
+
}),
|
|
1555
|
+
requestBodyValues: args,
|
|
1556
|
+
statusCode: 200,
|
|
1557
|
+
responseHeaders,
|
|
1558
|
+
data: errorData
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
const response = responseValue;
|
|
1473
1562
|
const choice = response.choices[0];
|
|
1474
1563
|
if (!choice) {
|
|
1475
|
-
throw new
|
|
1564
|
+
throw new NoContentGeneratedError({
|
|
1565
|
+
message: "No choice in response"
|
|
1566
|
+
});
|
|
1476
1567
|
}
|
|
1477
1568
|
const usageInfo = response.usage ? {
|
|
1478
1569
|
inputTokens: (_a15 = response.usage.prompt_tokens) != null ? _a15 : 0,
|
|
@@ -1832,7 +1923,10 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1832
1923
|
};
|
|
1833
1924
|
const toolCall2 = toolCalls[index];
|
|
1834
1925
|
if (toolCall2 == null) {
|
|
1835
|
-
throw new
|
|
1926
|
+
throw new InvalidResponseDataError({
|
|
1927
|
+
data: { index, toolCallsLength: toolCalls.length },
|
|
1928
|
+
message: `Tool call at index ${index} is missing after creation.`
|
|
1929
|
+
});
|
|
1836
1930
|
}
|
|
1837
1931
|
if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1838
1932
|
toolCall2.inputStarted = true;
|
|
@@ -1862,7 +1956,14 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1862
1956
|
}
|
|
1863
1957
|
const toolCall = toolCalls[index];
|
|
1864
1958
|
if (toolCall == null) {
|
|
1865
|
-
throw new
|
|
1959
|
+
throw new InvalidResponseDataError({
|
|
1960
|
+
data: {
|
|
1961
|
+
index,
|
|
1962
|
+
toolCallsLength: toolCalls.length,
|
|
1963
|
+
toolCallDelta
|
|
1964
|
+
},
|
|
1965
|
+
message: `Tool call at index ${index} is missing during merge.`
|
|
1966
|
+
});
|
|
1866
1967
|
}
|
|
1867
1968
|
if (!toolCall.inputStarted) {
|
|
1868
1969
|
toolCall.inputStarted = true;
|
|
@@ -2076,22 +2177,22 @@ var OpenRouterCompletionChunkSchema = z8.union([
|
|
|
2076
2177
|
tokens: z8.array(z8.string()),
|
|
2077
2178
|
token_logprobs: z8.array(z8.number()),
|
|
2078
2179
|
top_logprobs: z8.array(z8.record(z8.string(), z8.number())).nullable()
|
|
2079
|
-
}).nullable().optional()
|
|
2080
|
-
})
|
|
2180
|
+
}).passthrough().nullable().optional()
|
|
2181
|
+
}).passthrough()
|
|
2081
2182
|
),
|
|
2082
2183
|
usage: z8.object({
|
|
2083
2184
|
prompt_tokens: z8.number(),
|
|
2084
2185
|
prompt_tokens_details: z8.object({
|
|
2085
2186
|
cached_tokens: z8.number()
|
|
2086
|
-
}).nullish(),
|
|
2187
|
+
}).passthrough().nullish(),
|
|
2087
2188
|
completion_tokens: z8.number(),
|
|
2088
2189
|
completion_tokens_details: z8.object({
|
|
2089
2190
|
reasoning_tokens: z8.number()
|
|
2090
|
-
}).nullish(),
|
|
2191
|
+
}).passthrough().nullish(),
|
|
2091
2192
|
total_tokens: z8.number(),
|
|
2092
2193
|
cost: z8.number().optional()
|
|
2093
|
-
}).nullish()
|
|
2094
|
-
}),
|
|
2194
|
+
}).passthrough().nullish()
|
|
2195
|
+
}).passthrough(),
|
|
2095
2196
|
OpenRouterErrorResponseSchema
|
|
2096
2197
|
]);
|
|
2097
2198
|
|
|
@@ -2187,11 +2288,24 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
2187
2288
|
fetch: this.config.fetch
|
|
2188
2289
|
});
|
|
2189
2290
|
if ("error" in response) {
|
|
2190
|
-
|
|
2291
|
+
const errorData = response.error;
|
|
2292
|
+
throw new APICallError({
|
|
2293
|
+
message: errorData.message,
|
|
2294
|
+
url: this.config.url({
|
|
2295
|
+
path: "/completions",
|
|
2296
|
+
modelId: this.modelId
|
|
2297
|
+
}),
|
|
2298
|
+
requestBodyValues: args,
|
|
2299
|
+
statusCode: 200,
|
|
2300
|
+
responseHeaders,
|
|
2301
|
+
data: errorData
|
|
2302
|
+
});
|
|
2191
2303
|
}
|
|
2192
2304
|
const choice = response.choices[0];
|
|
2193
2305
|
if (!choice) {
|
|
2194
|
-
throw new
|
|
2306
|
+
throw new NoContentGeneratedError({
|
|
2307
|
+
message: "No choice in OpenRouter completion response"
|
|
2308
|
+
});
|
|
2195
2309
|
}
|
|
2196
2310
|
return {
|
|
2197
2311
|
content: [
|