@openrouter/ai-sdk-provider 1.2.1 → 1.2.2

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.
@@ -1,6 +1,41 @@
1
1
  import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart } from '@ai-sdk/provider';
2
2
  export { LanguageModelV2, LanguageModelV2Prompt } from '@ai-sdk/provider';
3
3
  import { z } from 'zod/v4';
4
+ import * as models from '@openrouter/sdk/models';
5
+
6
+ declare enum ReasoningFormat {
7
+ Unknown = "unknown",
8
+ OpenAIResponsesV1 = "openai-responses-v1",
9
+ XAIResponsesV1 = "xai-responses-v1",
10
+ AnthropicClaudeV1 = "anthropic-claude-v1"
11
+ }
12
+
13
+ declare enum ReasoningDetailType {
14
+ Summary = "reasoning.summary",
15
+ Encrypted = "reasoning.encrypted",
16
+ Text = "reasoning.text"
17
+ }
18
+ declare const ReasoningDetailUnionSchema: z.ZodUnion<readonly [z.ZodObject<{
19
+ type: z.ZodLiteral<ReasoningDetailType.Summary>;
20
+ summary: z.ZodString;
21
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
+ format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
23
+ index: z.ZodOptional<z.ZodNumber>;
24
+ }, z.core.$strip>, z.ZodObject<{
25
+ type: z.ZodLiteral<ReasoningDetailType.Encrypted>;
26
+ data: z.ZodString;
27
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
+ format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
29
+ index: z.ZodOptional<z.ZodNumber>;
30
+ }, z.core.$strip>, z.ZodObject<{
31
+ type: z.ZodLiteral<ReasoningDetailType.Text>;
32
+ text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
33
+ signature: z.ZodOptional<z.ZodNullable<z.ZodString>>;
34
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
35
+ format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
36
+ index: z.ZodOptional<z.ZodNumber>;
37
+ }, z.core.$strip>]>;
38
+ type ReasoningDetailUnion = z.infer<typeof ReasoningDetailUnionSchema>;
4
39
 
5
40
  type OpenRouterProviderOptions = {
6
41
  models?: string[];
@@ -159,18 +194,21 @@ type OpenRouterChatSettings = {
159
194
  */
160
195
  user?: string;
161
196
  /**
162
- * Web search plugin configuration for enabling web search capabilities
197
+ * Plugin configurations for enabling various capabilities
163
198
  */
164
199
  plugins?: Array<{
165
- id: 'web';
166
- /**
167
- * Maximum number of search results to include (default: 5)
168
- */
200
+ id: models.IdWeb;
169
201
  max_results?: number;
170
- /**
171
- * Custom search prompt to guide the search query
172
- */
173
202
  search_prompt?: string;
203
+ engine?: models.Engine;
204
+ } | {
205
+ id: models.IdFileParser;
206
+ max_files?: number;
207
+ pdf?: {
208
+ engine?: models.PdfEngine;
209
+ };
210
+ } | {
211
+ id: models.IdModeration;
174
212
  }>;
175
213
  /**
176
214
  * Built-in web search options for models that support native web search
@@ -204,7 +242,7 @@ type OpenRouterChatSettings = {
204
242
  /**
205
243
  * Control whether to use providers that may store data
206
244
  */
207
- data_collection?: 'allow' | 'deny';
245
+ data_collection?: models.DataCollection;
208
246
  /**
209
247
  * List of provider slugs to allow for this request
210
248
  */
@@ -216,11 +254,11 @@ type OpenRouterChatSettings = {
216
254
  /**
217
255
  * List of quantization levels to filter by (e.g. ["int4", "int8"])
218
256
  */
219
- quantizations?: Array<'int4' | 'int8' | 'fp4' | 'fp6' | 'fp8' | 'fp16' | 'bf16' | 'fp32' | 'unknown'>;
257
+ quantizations?: Array<models.Quantization>;
220
258
  /**
221
259
  * Sort providers by price, throughput, or latency
222
260
  */
223
- sort?: 'price' | 'throughput' | 'latency';
261
+ sort?: models.Sort;
224
262
  /**
225
263
  * Maximum pricing you want to pay for this request
226
264
  */
@@ -234,40 +272,6 @@ type OpenRouterChatSettings = {
234
272
  };
235
273
  } & OpenRouterSharedSettings;
236
274
 
237
- declare enum ReasoningFormat {
238
- Unknown = "unknown",
239
- OpenAIResponsesV1 = "openai-responses-v1",
240
- XAIResponsesV1 = "xai-responses-v1",
241
- AnthropicClaudeV1 = "anthropic-claude-v1"
242
- }
243
-
244
- declare enum ReasoningDetailType {
245
- Summary = "reasoning.summary",
246
- Encrypted = "reasoning.encrypted",
247
- Text = "reasoning.text"
248
- }
249
- declare const ReasoningDetailUnionSchema: z.ZodUnion<readonly [z.ZodObject<{
250
- type: z.ZodLiteral<ReasoningDetailType.Summary>;
251
- summary: z.ZodString;
252
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
253
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
254
- index: z.ZodOptional<z.ZodNumber>;
255
- }, z.core.$strip>, z.ZodObject<{
256
- type: z.ZodLiteral<ReasoningDetailType.Encrypted>;
257
- data: z.ZodString;
258
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
259
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
260
- index: z.ZodOptional<z.ZodNumber>;
261
- }, z.core.$strip>, z.ZodObject<{
262
- type: z.ZodLiteral<ReasoningDetailType.Text>;
263
- text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
264
- signature: z.ZodOptional<z.ZodNullable<z.ZodString>>;
265
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
266
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
267
- index: z.ZodOptional<z.ZodNumber>;
268
- }, z.core.$strip>]>;
269
- type ReasoningDetailUnion = z.infer<typeof ReasoningDetailUnionSchema>;
270
-
271
275
  type OpenRouterChatConfig = {
272
276
  provider: string;
273
277
  compatibility: 'strict' | 'compatible';
@@ -1,6 +1,41 @@
1
1
  import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2ResponseMetadata, SharedV2Headers, LanguageModelV2StreamPart } from '@ai-sdk/provider';
2
2
  export { LanguageModelV2, LanguageModelV2Prompt } from '@ai-sdk/provider';
3
3
  import { z } from 'zod/v4';
4
+ import * as models from '@openrouter/sdk/models';
5
+
6
+ declare enum ReasoningFormat {
7
+ Unknown = "unknown",
8
+ OpenAIResponsesV1 = "openai-responses-v1",
9
+ XAIResponsesV1 = "xai-responses-v1",
10
+ AnthropicClaudeV1 = "anthropic-claude-v1"
11
+ }
12
+
13
+ declare enum ReasoningDetailType {
14
+ Summary = "reasoning.summary",
15
+ Encrypted = "reasoning.encrypted",
16
+ Text = "reasoning.text"
17
+ }
18
+ declare const ReasoningDetailUnionSchema: z.ZodUnion<readonly [z.ZodObject<{
19
+ type: z.ZodLiteral<ReasoningDetailType.Summary>;
20
+ summary: z.ZodString;
21
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
+ format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
23
+ index: z.ZodOptional<z.ZodNumber>;
24
+ }, z.core.$strip>, z.ZodObject<{
25
+ type: z.ZodLiteral<ReasoningDetailType.Encrypted>;
26
+ data: z.ZodString;
27
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
+ format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
29
+ index: z.ZodOptional<z.ZodNumber>;
30
+ }, z.core.$strip>, z.ZodObject<{
31
+ type: z.ZodLiteral<ReasoningDetailType.Text>;
32
+ text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
33
+ signature: z.ZodOptional<z.ZodNullable<z.ZodString>>;
34
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
35
+ format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
36
+ index: z.ZodOptional<z.ZodNumber>;
37
+ }, z.core.$strip>]>;
38
+ type ReasoningDetailUnion = z.infer<typeof ReasoningDetailUnionSchema>;
4
39
 
5
40
  type OpenRouterProviderOptions = {
6
41
  models?: string[];
@@ -159,18 +194,21 @@ type OpenRouterChatSettings = {
159
194
  */
160
195
  user?: string;
161
196
  /**
162
- * Web search plugin configuration for enabling web search capabilities
197
+ * Plugin configurations for enabling various capabilities
163
198
  */
164
199
  plugins?: Array<{
165
- id: 'web';
166
- /**
167
- * Maximum number of search results to include (default: 5)
168
- */
200
+ id: models.IdWeb;
169
201
  max_results?: number;
170
- /**
171
- * Custom search prompt to guide the search query
172
- */
173
202
  search_prompt?: string;
203
+ engine?: models.Engine;
204
+ } | {
205
+ id: models.IdFileParser;
206
+ max_files?: number;
207
+ pdf?: {
208
+ engine?: models.PdfEngine;
209
+ };
210
+ } | {
211
+ id: models.IdModeration;
174
212
  }>;
175
213
  /**
176
214
  * Built-in web search options for models that support native web search
@@ -204,7 +242,7 @@ type OpenRouterChatSettings = {
204
242
  /**
205
243
  * Control whether to use providers that may store data
206
244
  */
207
- data_collection?: 'allow' | 'deny';
245
+ data_collection?: models.DataCollection;
208
246
  /**
209
247
  * List of provider slugs to allow for this request
210
248
  */
@@ -216,11 +254,11 @@ type OpenRouterChatSettings = {
216
254
  /**
217
255
  * List of quantization levels to filter by (e.g. ["int4", "int8"])
218
256
  */
219
- quantizations?: Array<'int4' | 'int8' | 'fp4' | 'fp6' | 'fp8' | 'fp16' | 'bf16' | 'fp32' | 'unknown'>;
257
+ quantizations?: Array<models.Quantization>;
220
258
  /**
221
259
  * Sort providers by price, throughput, or latency
222
260
  */
223
- sort?: 'price' | 'throughput' | 'latency';
261
+ sort?: models.Sort;
224
262
  /**
225
263
  * Maximum pricing you want to pay for this request
226
264
  */
@@ -234,40 +272,6 @@ type OpenRouterChatSettings = {
234
272
  };
235
273
  } & OpenRouterSharedSettings;
236
274
 
237
- declare enum ReasoningFormat {
238
- Unknown = "unknown",
239
- OpenAIResponsesV1 = "openai-responses-v1",
240
- XAIResponsesV1 = "xai-responses-v1",
241
- AnthropicClaudeV1 = "anthropic-claude-v1"
242
- }
243
-
244
- declare enum ReasoningDetailType {
245
- Summary = "reasoning.summary",
246
- Encrypted = "reasoning.encrypted",
247
- Text = "reasoning.text"
248
- }
249
- declare const ReasoningDetailUnionSchema: z.ZodUnion<readonly [z.ZodObject<{
250
- type: z.ZodLiteral<ReasoningDetailType.Summary>;
251
- summary: z.ZodString;
252
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
253
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
254
- index: z.ZodOptional<z.ZodNumber>;
255
- }, z.core.$strip>, z.ZodObject<{
256
- type: z.ZodLiteral<ReasoningDetailType.Encrypted>;
257
- data: z.ZodString;
258
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
259
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
260
- index: z.ZodOptional<z.ZodNumber>;
261
- }, z.core.$strip>, z.ZodObject<{
262
- type: z.ZodLiteral<ReasoningDetailType.Text>;
263
- text: z.ZodOptional<z.ZodNullable<z.ZodString>>;
264
- signature: z.ZodOptional<z.ZodNullable<z.ZodString>>;
265
- id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
266
- format: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof ReasoningFormat>>>;
267
- index: z.ZodOptional<z.ZodNumber>;
268
- }, z.core.$strip>]>;
269
- type ReasoningDetailUnion = z.infer<typeof ReasoningDetailUnionSchema>;
270
-
271
275
  type OpenRouterChatConfig = {
272
276
  provider: string;
273
277
  compatibility: 'strict' | 'compatible';
@@ -242,6 +242,18 @@ var name9 = "AI_NoContentGeneratedError";
242
242
  var marker10 = `vercel.ai.error.${name9}`;
243
243
  var symbol10 = Symbol.for(marker10);
244
244
  var _a10;
245
+ var NoContentGeneratedError = class extends AISDKError {
246
+ // used in isInstance
247
+ constructor({
248
+ message = "No content generated."
249
+ } = {}) {
250
+ super({ name: name9, message });
251
+ this[_a10] = true;
252
+ }
253
+ static isInstance(error) {
254
+ return AISDKError.hasMarker(error, marker10);
255
+ }
256
+ };
245
257
  _a10 = symbol10;
246
258
  var name10 = "AI_NoSuchModelError";
247
259
  var marker11 = `vercel.ai.error.${name10}`;
@@ -922,12 +934,16 @@ var OutputUnionToReasoningDetailsSchema = import_v4.z.union([
922
934
  delta: import_v4.z.object({
923
935
  reasoning_details: import_v4.z.array(ReasoningDetailsWithUnknownSchema)
924
936
  })
925
- }).transform((data) => data.delta.reasoning_details.filter(isDefinedOrNotNull)),
937
+ }).transform(
938
+ (data) => data.delta.reasoning_details.filter(isDefinedOrNotNull)
939
+ ),
926
940
  import_v4.z.object({
927
941
  message: import_v4.z.object({
928
942
  reasoning_details: import_v4.z.array(ReasoningDetailsWithUnknownSchema)
929
943
  })
930
- }).transform((data) => data.message.reasoning_details.filter(isDefinedOrNotNull)),
944
+ }).transform(
945
+ (data) => data.message.reasoning_details.filter(isDefinedOrNotNull)
946
+ ),
931
947
  import_v4.z.object({
932
948
  text: import_v4.z.string(),
933
949
  reasoning_details: import_v4.z.array(ReasoningDetailsWithUnknownSchema)
@@ -1175,9 +1191,7 @@ function convertToOpenRouterChatMessages(prompt) {
1175
1191
  }
1176
1192
  }
1177
1193
  }
1178
- const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(
1179
- providerOptions
1180
- );
1194
+ const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
1181
1195
  const preservedReasoningDetails = parsedProviderOptions.success ? (_d = (_c = parsedProviderOptions.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details : void 0;
1182
1196
  messages.push({
1183
1197
  role: "assistant",
@@ -1240,7 +1254,10 @@ function getChatCompletionToolChoice(toolChoice) {
1240
1254
  }
1241
1255
  default: {
1242
1256
  toolChoice;
1243
- throw new Error(`Invalid tool choice type: ${toolChoice}`);
1257
+ throw new InvalidArgumentError({
1258
+ argument: "toolChoice",
1259
+ message: `Invalid tool choice type: ${JSON.stringify(toolChoice)}`
1260
+ });
1244
1261
  }
1245
1262
  }
1246
1263
  }
@@ -1283,57 +1300,89 @@ var OpenRouterChatCompletionBaseResponseSchema = import_v46.z.object({
1283
1300
  }).nullish()
1284
1301
  }).nullish()
1285
1302
  });
1286
- var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
1287
- choices: import_v46.z.array(
1288
- import_v46.z.object({
1289
- message: import_v46.z.object({
1290
- role: import_v46.z.literal("assistant"),
1291
- content: import_v46.z.string().nullable().optional(),
1292
- reasoning: import_v46.z.string().nullable().optional(),
1293
- reasoning_details: ReasoningDetailArraySchema.nullish(),
1294
- images: ImageResponseArraySchema.nullish(),
1295
- tool_calls: import_v46.z.array(
1296
- import_v46.z.object({
1297
- id: import_v46.z.string().optional().nullable(),
1298
- type: import_v46.z.literal("function"),
1299
- function: import_v46.z.object({
1300
- name: import_v46.z.string(),
1301
- arguments: import_v46.z.string()
1302
- })
1303
- })
1304
- ).optional(),
1305
- annotations: import_v46.z.array(
1306
- import_v46.z.object({
1307
- type: import_v46.z.enum(["url_citation"]),
1308
- url_citation: import_v46.z.object({
1309
- end_index: import_v46.z.number(),
1310
- start_index: import_v46.z.number(),
1311
- title: import_v46.z.string(),
1312
- url: import_v46.z.string(),
1313
- content: import_v46.z.string().optional()
1303
+ var OpenRouterNonStreamChatCompletionResponseSchema = import_v46.z.union([
1304
+ // Success response with choices
1305
+ OpenRouterChatCompletionBaseResponseSchema.extend({
1306
+ choices: import_v46.z.array(
1307
+ import_v46.z.object({
1308
+ message: import_v46.z.object({
1309
+ role: import_v46.z.literal("assistant"),
1310
+ content: import_v46.z.string().nullable().optional(),
1311
+ reasoning: import_v46.z.string().nullable().optional(),
1312
+ reasoning_details: ReasoningDetailArraySchema.nullish(),
1313
+ images: ImageResponseArraySchema.nullish(),
1314
+ tool_calls: import_v46.z.array(
1315
+ import_v46.z.object({
1316
+ id: import_v46.z.string().optional().nullable(),
1317
+ type: import_v46.z.literal("function"),
1318
+ function: import_v46.z.object({
1319
+ name: import_v46.z.string(),
1320
+ arguments: import_v46.z.string()
1321
+ })
1314
1322
  })
1315
- })
1316
- ).nullish()
1317
- }),
1318
- index: import_v46.z.number().nullish(),
1319
- logprobs: import_v46.z.object({
1320
- content: import_v46.z.array(
1321
- import_v46.z.object({
1322
- token: import_v46.z.string(),
1323
- logprob: import_v46.z.number(),
1324
- top_logprobs: import_v46.z.array(
1323
+ ).optional(),
1324
+ annotations: import_v46.z.array(
1325
+ import_v46.z.union([
1326
+ // URL citation from web search
1327
+ import_v46.z.object({
1328
+ type: import_v46.z.literal("url_citation"),
1329
+ url_citation: import_v46.z.object({
1330
+ end_index: import_v46.z.number(),
1331
+ start_index: import_v46.z.number(),
1332
+ title: import_v46.z.string(),
1333
+ url: import_v46.z.string(),
1334
+ content: import_v46.z.string().optional()
1335
+ })
1336
+ }),
1337
+ // File annotation from FileParserPlugin (old format)
1338
+ import_v46.z.object({
1339
+ type: import_v46.z.literal("file_annotation"),
1340
+ file_annotation: import_v46.z.object({
1341
+ file_id: import_v46.z.string(),
1342
+ quote: import_v46.z.string().optional()
1343
+ })
1344
+ }),
1345
+ // File annotation from FileParserPlugin (new format)
1325
1346
  import_v46.z.object({
1326
- token: import_v46.z.string(),
1327
- logprob: import_v46.z.number()
1347
+ type: import_v46.z.literal("file"),
1348
+ file: import_v46.z.object({
1349
+ hash: import_v46.z.string(),
1350
+ name: import_v46.z.string(),
1351
+ content: import_v46.z.array(
1352
+ import_v46.z.object({
1353
+ type: import_v46.z.string(),
1354
+ text: import_v46.z.string()
1355
+ })
1356
+ ).optional()
1357
+ })
1328
1358
  })
1329
- )
1330
- })
1331
- ).nullable()
1332
- }).nullable().optional(),
1333
- finish_reason: import_v46.z.string().optional().nullable()
1334
- })
1335
- )
1336
- });
1359
+ ])
1360
+ ).nullish()
1361
+ }),
1362
+ index: import_v46.z.number().nullish(),
1363
+ logprobs: import_v46.z.object({
1364
+ content: import_v46.z.array(
1365
+ import_v46.z.object({
1366
+ token: import_v46.z.string(),
1367
+ logprob: import_v46.z.number(),
1368
+ top_logprobs: import_v46.z.array(
1369
+ import_v46.z.object({
1370
+ token: import_v46.z.string(),
1371
+ logprob: import_v46.z.number()
1372
+ })
1373
+ )
1374
+ })
1375
+ ).nullable()
1376
+ }).nullable().optional(),
1377
+ finish_reason: import_v46.z.string().optional().nullable()
1378
+ })
1379
+ )
1380
+ }),
1381
+ // Error response (HTTP 200 with error payload)
1382
+ OpenRouterErrorResponseSchema.extend({
1383
+ user_id: import_v46.z.string().optional()
1384
+ })
1385
+ ]);
1337
1386
  var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
1338
1387
  OpenRouterChatCompletionBaseResponseSchema.extend({
1339
1388
  choices: import_v46.z.array(
@@ -1356,16 +1405,41 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
1356
1405
  })
1357
1406
  ).nullish(),
1358
1407
  annotations: import_v46.z.array(
1359
- import_v46.z.object({
1360
- type: import_v46.z.enum(["url_citation"]),
1361
- url_citation: import_v46.z.object({
1362
- end_index: import_v46.z.number(),
1363
- start_index: import_v46.z.number(),
1364
- title: import_v46.z.string(),
1365
- url: import_v46.z.string(),
1366
- content: import_v46.z.string().optional()
1408
+ import_v46.z.union([
1409
+ // URL citation from web search
1410
+ import_v46.z.object({
1411
+ type: import_v46.z.literal("url_citation"),
1412
+ url_citation: import_v46.z.object({
1413
+ end_index: import_v46.z.number(),
1414
+ start_index: import_v46.z.number(),
1415
+ title: import_v46.z.string(),
1416
+ url: import_v46.z.string(),
1417
+ content: import_v46.z.string().optional()
1418
+ })
1419
+ }),
1420
+ // File annotation from FileParserPlugin (old format)
1421
+ import_v46.z.object({
1422
+ type: import_v46.z.literal("file_annotation"),
1423
+ file_annotation: import_v46.z.object({
1424
+ file_id: import_v46.z.string(),
1425
+ quote: import_v46.z.string().optional()
1426
+ })
1427
+ }),
1428
+ // File annotation from FileParserPlugin (new format)
1429
+ import_v46.z.object({
1430
+ type: import_v46.z.literal("file"),
1431
+ file: import_v46.z.object({
1432
+ hash: import_v46.z.string(),
1433
+ name: import_v46.z.string(),
1434
+ content: import_v46.z.array(
1435
+ import_v46.z.object({
1436
+ type: import_v46.z.string(),
1437
+ text: import_v46.z.string()
1438
+ })
1439
+ ).optional()
1440
+ })
1367
1441
  })
1368
- })
1442
+ ])
1369
1443
  ).nullish()
1370
1444
  }).nullish(),
1371
1445
  logprobs: import_v46.z.object({
@@ -1490,7 +1564,7 @@ var OpenRouterChatLanguageModel = class {
1490
1564
  const providerOptions = options.providerOptions || {};
1491
1565
  const openrouterOptions = providerOptions.openrouter || {};
1492
1566
  const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
1493
- const { value: response, responseHeaders } = await postJsonToApi({
1567
+ const { value: responseValue, responseHeaders } = await postJsonToApi({
1494
1568
  url: this.config.url({
1495
1569
  path: "/chat/completions",
1496
1570
  modelId: this.modelId
@@ -1504,9 +1578,25 @@ var OpenRouterChatLanguageModel = class {
1504
1578
  abortSignal: options.abortSignal,
1505
1579
  fetch: this.config.fetch
1506
1580
  });
1581
+ if ("error" in responseValue) {
1582
+ throw new APICallError({
1583
+ message: responseValue.error.message,
1584
+ url: this.config.url({
1585
+ path: "/chat/completions",
1586
+ modelId: this.modelId
1587
+ }),
1588
+ requestBodyValues: args,
1589
+ statusCode: 200,
1590
+ responseHeaders,
1591
+ data: responseValue.error
1592
+ });
1593
+ }
1594
+ const response = responseValue;
1507
1595
  const choice = response.choices[0];
1508
1596
  if (!choice) {
1509
- throw new Error("No choice in response");
1597
+ throw new NoContentGeneratedError({
1598
+ message: "No choice in response"
1599
+ });
1510
1600
  }
1511
1601
  const usageInfo = response.usage ? {
1512
1602
  inputTokens: (_a15 = response.usage.prompt_tokens) != null ? _a15 : 0,
@@ -1866,7 +1956,10 @@ var OpenRouterChatLanguageModel = class {
1866
1956
  };
1867
1957
  const toolCall2 = toolCalls[index];
1868
1958
  if (toolCall2 == null) {
1869
- throw new Error("Tool call is missing");
1959
+ throw new InvalidResponseDataError({
1960
+ data: { index, toolCallsLength: toolCalls.length },
1961
+ message: `Tool call at index ${index} is missing after creation.`
1962
+ });
1870
1963
  }
1871
1964
  if (((_f = toolCall2.function) == null ? void 0 : _f.name) != null && ((_g = toolCall2.function) == null ? void 0 : _g.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
1872
1965
  toolCall2.inputStarted = true;
@@ -1896,7 +1989,14 @@ var OpenRouterChatLanguageModel = class {
1896
1989
  }
1897
1990
  const toolCall = toolCalls[index];
1898
1991
  if (toolCall == null) {
1899
- throw new Error("Tool call is missing");
1992
+ throw new InvalidResponseDataError({
1993
+ data: {
1994
+ index,
1995
+ toolCallsLength: toolCalls.length,
1996
+ toolCallDelta
1997
+ },
1998
+ message: `Tool call at index ${index} is missing during merge.`
1999
+ });
1900
2000
  }
1901
2001
  if (!toolCall.inputStarted) {
1902
2002
  toolCall.inputStarted = true;
@@ -2221,11 +2321,23 @@ var OpenRouterCompletionLanguageModel = class {
2221
2321
  fetch: this.config.fetch
2222
2322
  });
2223
2323
  if ("error" in response) {
2224
- throw new Error(`${response.error.message}`);
2324
+ throw new APICallError({
2325
+ message: response.error.message,
2326
+ url: this.config.url({
2327
+ path: "/completions",
2328
+ modelId: this.modelId
2329
+ }),
2330
+ requestBodyValues: args,
2331
+ statusCode: 200,
2332
+ responseHeaders,
2333
+ data: response.error
2334
+ });
2225
2335
  }
2226
2336
  const choice = response.choices[0];
2227
2337
  if (!choice) {
2228
- throw new Error("No choice in OpenRouter completion response");
2338
+ throw new NoContentGeneratedError({
2339
+ message: "No choice in OpenRouter completion response"
2340
+ });
2229
2341
  }
2230
2342
  return {
2231
2343
  content: [