@openrouter/ai-sdk-provider 0.5.0 → 0.7.0-alpha.0

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.
@@ -56,8 +56,8 @@ type OpenRouterUsageAccounting = {
56
56
  cost?: number;
57
57
  };
58
58
 
59
- type OpenRouterChatModelId = string;
60
- type OpenRouterChatSettings = {
59
+ type OpenRouterCompletionModelId = string;
60
+ type OpenRouterCompletionSettings = {
61
61
  /**
62
62
  Modify the likelihood of specified tokens appearing in the completion.
63
63
 
@@ -71,7 +71,7 @@ type OpenRouterChatSettings = {
71
71
 
72
72
  As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
73
73
  token from being generated.
74
- */
74
+ */
75
75
  logitBias?: Record<number, number>;
76
76
  /**
77
77
  Return the log probabilities of the tokens. Including logprobs will increase
@@ -83,20 +83,15 @@ type OpenRouterChatSettings = {
83
83
 
84
84
  Setting to a number will return the log probabilities of the top n
85
85
  tokens that were generated.
86
- */
86
+ */
87
87
  logprobs?: boolean | number;
88
88
  /**
89
- Whether to enable parallel function calling during tool use. Default to true.
89
+ The suffix that comes after a completion of inserted text.
90
90
  */
91
- parallelToolCalls?: boolean;
92
- /**
93
- A unique identifier representing your end-user, which can help OpenRouter to
94
- monitor and detect abuse. Learn more.
95
- */
96
- user?: string;
91
+ suffix?: string;
97
92
  } & OpenRouterSharedSettings;
98
93
 
99
- type OpenRouterChatConfig = {
94
+ type OpenRouterCompletionConfig = {
100
95
  provider: string;
101
96
  compatibility: 'strict' | 'compatible';
102
97
  headers: () => Record<string, string | undefined>;
@@ -107,21 +102,21 @@ type OpenRouterChatConfig = {
107
102
  fetch?: typeof fetch;
108
103
  extraBody?: Record<string, unknown>;
109
104
  };
110
- declare class OpenRouterChatLanguageModel implements LanguageModelV1 {
105
+ declare class OpenRouterCompletionLanguageModel implements LanguageModelV1 {
111
106
  readonly specificationVersion = "v1";
112
- readonly defaultObjectGenerationMode = "tool";
113
- readonly modelId: OpenRouterChatModelId;
114
- readonly settings: OpenRouterChatSettings;
107
+ readonly defaultObjectGenerationMode: undefined;
108
+ readonly modelId: OpenRouterCompletionModelId;
109
+ readonly settings: OpenRouterCompletionSettings;
115
110
  private readonly config;
116
- constructor(modelId: OpenRouterChatModelId, settings: OpenRouterChatSettings, config: OpenRouterChatConfig);
111
+ constructor(modelId: OpenRouterCompletionModelId, settings: OpenRouterCompletionSettings, config: OpenRouterCompletionConfig);
117
112
  get provider(): string;
118
113
  private getArgs;
119
114
  doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
120
115
  doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
121
116
  }
122
117
 
123
- type OpenRouterCompletionModelId = string;
124
- type OpenRouterCompletionSettings = {
118
+ type OpenRouterChatModelId = string;
119
+ type OpenRouterChatSettings = {
125
120
  /**
126
121
  Modify the likelihood of specified tokens appearing in the completion.
127
122
 
@@ -135,7 +130,7 @@ type OpenRouterCompletionSettings = {
135
130
 
136
131
  As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
137
132
  token from being generated.
138
- */
133
+ */
139
134
  logitBias?: Record<number, number>;
140
135
  /**
141
136
  Return the log probabilities of the tokens. Including logprobs will increase
@@ -147,15 +142,20 @@ type OpenRouterCompletionSettings = {
147
142
 
148
143
  Setting to a number will return the log probabilities of the top n
149
144
  tokens that were generated.
150
- */
145
+ */
151
146
  logprobs?: boolean | number;
152
147
  /**
153
- The suffix that comes after a completion of inserted text.
148
+ Whether to enable parallel function calling during tool use. Default to true.
154
149
  */
155
- suffix?: string;
150
+ parallelToolCalls?: boolean;
151
+ /**
152
+ A unique identifier representing your end-user, which can help OpenRouter to
153
+ monitor and detect abuse. Learn more.
154
+ */
155
+ user?: string;
156
156
  } & OpenRouterSharedSettings;
157
157
 
158
- type OpenRouterCompletionConfig = {
158
+ type OpenRouterChatConfig = {
159
159
  provider: string;
160
160
  compatibility: 'strict' | 'compatible';
161
161
  headers: () => Record<string, string | undefined>;
@@ -166,17 +166,19 @@ type OpenRouterCompletionConfig = {
166
166
  fetch?: typeof fetch;
167
167
  extraBody?: Record<string, unknown>;
168
168
  };
169
- declare class OpenRouterCompletionLanguageModel implements LanguageModelV1 {
169
+ type DoGenerateOutput = Awaited<ReturnType<LanguageModelV1['doGenerate']>>;
170
+ type DoStreamOutput = Awaited<ReturnType<LanguageModelV1['doStream']>>;
171
+ declare class OpenRouterChatLanguageModel implements LanguageModelV1 {
170
172
  readonly specificationVersion = "v1";
171
- readonly defaultObjectGenerationMode: undefined;
172
- readonly modelId: OpenRouterCompletionModelId;
173
- readonly settings: OpenRouterCompletionSettings;
173
+ readonly defaultObjectGenerationMode = "tool";
174
+ readonly modelId: OpenRouterChatModelId;
175
+ readonly settings: OpenRouterChatSettings;
174
176
  private readonly config;
175
- constructor(modelId: OpenRouterCompletionModelId, settings: OpenRouterCompletionSettings, config: OpenRouterCompletionConfig);
177
+ constructor(modelId: OpenRouterChatModelId, settings: OpenRouterChatSettings, config: OpenRouterChatConfig);
176
178
  get provider(): string;
177
179
  private getArgs;
178
- doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
179
- doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
180
+ doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<DoGenerateOutput>;
181
+ doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<DoStreamOutput>;
180
182
  }
181
183
 
182
184
  export { OpenRouterChatLanguageModel, type OpenRouterChatModelId, type OpenRouterChatSettings, OpenRouterCompletionLanguageModel, type OpenRouterCompletionModelId, type OpenRouterCompletionSettings, type OpenRouterLanguageModel, type OpenRouterProviderOptions, type OpenRouterSharedSettings, type OpenRouterUsageAccounting };
@@ -54,10 +54,36 @@ __export(index_exports, {
54
54
  });
55
55
  module.exports = __toCommonJS(index_exports);
56
56
 
57
+ // src/schemas/reasoning-details.ts
58
+ var import_zod = require("zod");
59
+ var ReasoningDetailSummarySchema = import_zod.z.object({
60
+ type: import_zod.z.literal("reasoning.summary" /* Summary */),
61
+ summary: import_zod.z.string()
62
+ });
63
+ var ReasoningDetailEncryptedSchema = import_zod.z.object({
64
+ type: import_zod.z.literal("reasoning.encrypted" /* Encrypted */),
65
+ data: import_zod.z.string()
66
+ });
67
+ var ReasoningDetailTextSchema = import_zod.z.object({
68
+ type: import_zod.z.literal("reasoning.text" /* Text */),
69
+ text: import_zod.z.string().nullish(),
70
+ signature: import_zod.z.string().nullish()
71
+ });
72
+ var ReasoningDetailUnionSchema = import_zod.z.union([
73
+ ReasoningDetailSummarySchema,
74
+ ReasoningDetailEncryptedSchema,
75
+ ReasoningDetailTextSchema
76
+ ]);
77
+ var ReasoningDetailsWithUnknownSchema = import_zod.z.union([
78
+ ReasoningDetailUnionSchema,
79
+ import_zod.z.unknown().transform(() => null)
80
+ ]);
81
+ var ReasoningDetailArraySchema = import_zod.z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
82
+
57
83
  // src/openrouter-chat-language-model.ts
58
84
  var import_provider = require("@ai-sdk/provider");
59
85
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
60
- var import_zod2 = require("zod");
86
+ var import_zod3 = require("zod");
61
87
 
62
88
  // src/convert-to-openrouter-chat-messages.ts
63
89
  var import_provider_utils = require("@ai-sdk/provider-utils");
@@ -92,14 +118,15 @@ function convertToOpenRouterChatMessages(prompt) {
92
118
  const messageCacheControl = getCacheControl(providerMetadata);
93
119
  const contentParts = content.map(
94
120
  (part) => {
95
- var _a2, _b2, _c2, _d, _e, _f;
121
+ var _a2, _b2, _c2, _d;
122
+ const cacheControl = (_a2 = getCacheControl(part.providerMetadata)) != null ? _a2 : messageCacheControl;
96
123
  switch (part.type) {
97
124
  case "text":
98
125
  return {
99
126
  type: "text",
100
127
  text: part.text,
101
128
  // For text parts, only use part-specific cache control
102
- cache_control: (_a2 = getCacheControl(part.providerMetadata)) != null ? _a2 : messageCacheControl
129
+ cache_control: cacheControl
103
130
  };
104
131
  case "image":
105
132
  return {
@@ -110,18 +137,18 @@ function convertToOpenRouterChatMessages(prompt) {
110
137
  )}`
111
138
  },
112
139
  // For image parts, use part-specific or message-level cache control
113
- cache_control: (_c2 = getCacheControl(part.providerMetadata)) != null ? _c2 : messageCacheControl
140
+ cache_control: cacheControl
114
141
  };
115
142
  case "file":
116
143
  return {
117
144
  type: "file",
118
145
  file: {
119
146
  filename: String(
120
- (_e = (_d = part.providerMetadata) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.filename
147
+ (_d = (_c2 = part.providerMetadata) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d.filename
121
148
  ),
122
149
  file_data: part.data instanceof Uint8Array ? `data:${part.mimeType};base64,${(0, import_provider_utils.convertUint8ArrayToBase64)(part.data)}` : `data:${part.mimeType};base64,${part.data}`
123
150
  },
124
- cache_control: (_f = getCacheControl(part.providerMetadata)) != null ? _f : messageCacheControl
151
+ cache_control: cacheControl
125
152
  };
126
153
  default: {
127
154
  const _exhaustiveCheck = part;
@@ -140,6 +167,8 @@ function convertToOpenRouterChatMessages(prompt) {
140
167
  }
141
168
  case "assistant": {
142
169
  let text = "";
170
+ let reasoning = "";
171
+ const reasoningDetails = [];
143
172
  const toolCalls = [];
144
173
  for (const part of content) {
145
174
  switch (part.type) {
@@ -158,9 +187,23 @@ function convertToOpenRouterChatMessages(prompt) {
158
187
  });
159
188
  break;
160
189
  }
161
- // TODO: Handle reasoning and redacted-reasoning
162
- case "reasoning":
163
- case "redacted-reasoning":
190
+ case "reasoning": {
191
+ reasoning += part.text;
192
+ reasoningDetails.push({
193
+ type: "reasoning.text" /* Text */,
194
+ text: part.text,
195
+ signature: part.signature
196
+ });
197
+ break;
198
+ }
199
+ case "redacted-reasoning": {
200
+ reasoningDetails.push({
201
+ type: "reasoning.encrypted" /* Encrypted */,
202
+ data: part.data
203
+ });
204
+ break;
205
+ }
206
+ case "file":
164
207
  break;
165
208
  default: {
166
209
  const _exhaustiveCheck = part;
@@ -172,6 +215,8 @@ function convertToOpenRouterChatMessages(prompt) {
172
215
  role: "assistant",
173
216
  content: text,
174
217
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
218
+ reasoning: reasoning || void 0,
219
+ reasoning_details: reasoningDetails.length > 0 ? reasoningDetails : void 0,
175
220
  cache_control: getCacheControl(providerMetadata)
176
221
  });
177
222
  break;
@@ -228,13 +273,13 @@ function mapOpenRouterFinishReason(finishReason) {
228
273
 
229
274
  // src/openrouter-error.ts
230
275
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
231
- var import_zod = require("zod");
232
- var OpenRouterErrorResponseSchema = import_zod.z.object({
233
- error: import_zod.z.object({
234
- message: import_zod.z.string(),
235
- type: import_zod.z.string(),
236
- param: import_zod.z.any().nullable(),
237
- code: import_zod.z.string().nullable()
276
+ var import_zod2 = require("zod");
277
+ var OpenRouterErrorResponseSchema = import_zod2.z.object({
278
+ error: import_zod2.z.object({
279
+ message: import_zod2.z.string(),
280
+ type: import_zod2.z.string(),
281
+ param: import_zod2.z.any().nullable(),
282
+ code: import_zod2.z.string().nullable()
238
283
  })
239
284
  });
240
285
  var openrouterFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
@@ -381,13 +426,56 @@ var OpenRouterChatLanguageModel = class {
381
426
  };
382
427
  }
383
428
  const hasProviderMetadata = Object.keys(providerMetadata).length > 0;
429
+ const reasoningDetails = (_h = choice.message.reasoning_details) != null ? _h : [];
430
+ const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
431
+ var _a2;
432
+ switch (detail.type) {
433
+ case "reasoning.text" /* Text */: {
434
+ if (detail.text) {
435
+ return {
436
+ type: "text",
437
+ text: detail.text,
438
+ signature: (_a2 = detail.signature) != null ? _a2 : void 0
439
+ };
440
+ }
441
+ break;
442
+ }
443
+ case "reasoning.summary" /* Summary */: {
444
+ if (detail.summary) {
445
+ return {
446
+ type: "text",
447
+ text: detail.summary
448
+ };
449
+ }
450
+ break;
451
+ }
452
+ case "reasoning.encrypted" /* Encrypted */: {
453
+ if (detail.data) {
454
+ return {
455
+ type: "redacted",
456
+ data: detail.data
457
+ };
458
+ }
459
+ break;
460
+ }
461
+ default: {
462
+ detail;
463
+ }
464
+ }
465
+ return null;
466
+ }).filter((p) => p !== null) : choice.message.reasoning ? [
467
+ {
468
+ type: "text",
469
+ text: choice.message.reasoning
470
+ }
471
+ ] : [];
384
472
  return __spreadValues({
385
473
  response: {
386
474
  id: response.id,
387
475
  modelId: response.model
388
476
  },
389
- text: (_h = choice.message.content) != null ? _h : void 0,
390
- reasoning: (_i = choice.message.reasoning) != null ? _i : void 0,
477
+ text: (_i = choice.message.content) != null ? _i : void 0,
478
+ reasoning,
391
479
  toolCalls: (_j = choice.message.tool_calls) == null ? void 0 : _j.map((toolCall) => {
392
480
  var _a2;
393
481
  return {
@@ -506,11 +594,56 @@ var OpenRouterChatLanguageModel = class {
506
594
  textDelta: delta.reasoning
507
595
  });
508
596
  }
597
+ if (delta.reasoning_details && delta.reasoning_details.length > 0) {
598
+ for (const detail of delta.reasoning_details) {
599
+ switch (detail.type) {
600
+ case "reasoning.text" /* Text */: {
601
+ if (detail.text) {
602
+ controller.enqueue({
603
+ type: "reasoning",
604
+ textDelta: detail.text
605
+ });
606
+ }
607
+ if (detail.signature) {
608
+ controller.enqueue({
609
+ type: "reasoning-signature",
610
+ signature: detail.signature
611
+ });
612
+ }
613
+ break;
614
+ }
615
+ case "reasoning.encrypted" /* Encrypted */: {
616
+ if (detail.data) {
617
+ controller.enqueue({
618
+ type: "redacted-reasoning",
619
+ data: detail.data
620
+ });
621
+ }
622
+ break;
623
+ }
624
+ case "reasoning.summary" /* Summary */: {
625
+ if (detail.summary) {
626
+ controller.enqueue({
627
+ type: "reasoning",
628
+ textDelta: detail.summary
629
+ });
630
+ }
631
+ break;
632
+ }
633
+ default: {
634
+ detail;
635
+ break;
636
+ }
637
+ }
638
+ }
639
+ }
509
640
  const mappedLogprobs = mapOpenRouterChatLogProbsOutput(
510
641
  choice == null ? void 0 : choice.logprobs
511
642
  );
512
643
  if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
513
- if (logprobs === void 0) logprobs = [];
644
+ if (logprobs === void 0) {
645
+ logprobs = [];
646
+ }
514
647
  logprobs.push(...mappedLogprobs);
515
648
  }
516
649
  if (delta.tool_calls != null) {
@@ -633,95 +766,97 @@ var OpenRouterChatLanguageModel = class {
633
766
  };
634
767
  }
635
768
  };
636
- var OpenRouterChatCompletionBaseResponseSchema = import_zod2.z.object({
637
- id: import_zod2.z.string().optional(),
638
- model: import_zod2.z.string().optional(),
639
- usage: import_zod2.z.object({
640
- prompt_tokens: import_zod2.z.number(),
641
- prompt_tokens_details: import_zod2.z.object({
642
- cached_tokens: import_zod2.z.number()
769
+ var OpenRouterChatCompletionBaseResponseSchema = import_zod3.z.object({
770
+ id: import_zod3.z.string().optional(),
771
+ model: import_zod3.z.string().optional(),
772
+ usage: import_zod3.z.object({
773
+ prompt_tokens: import_zod3.z.number(),
774
+ prompt_tokens_details: import_zod3.z.object({
775
+ cached_tokens: import_zod3.z.number()
643
776
  }).optional(),
644
- completion_tokens: import_zod2.z.number(),
645
- completion_tokens_details: import_zod2.z.object({
646
- reasoning_tokens: import_zod2.z.number()
777
+ completion_tokens: import_zod3.z.number(),
778
+ completion_tokens_details: import_zod3.z.object({
779
+ reasoning_tokens: import_zod3.z.number()
647
780
  }).optional(),
648
- total_tokens: import_zod2.z.number(),
649
- cost: import_zod2.z.number().optional()
781
+ total_tokens: import_zod3.z.number(),
782
+ cost: import_zod3.z.number().optional()
650
783
  }).nullish()
651
784
  });
652
785
  var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
653
- choices: import_zod2.z.array(
654
- import_zod2.z.object({
655
- message: import_zod2.z.object({
656
- role: import_zod2.z.literal("assistant"),
657
- content: import_zod2.z.string().nullable().optional(),
658
- reasoning: import_zod2.z.string().nullable().optional(),
659
- tool_calls: import_zod2.z.array(
660
- import_zod2.z.object({
661
- id: import_zod2.z.string().optional().nullable(),
662
- type: import_zod2.z.literal("function"),
663
- function: import_zod2.z.object({
664
- name: import_zod2.z.string(),
665
- arguments: import_zod2.z.string()
786
+ choices: import_zod3.z.array(
787
+ import_zod3.z.object({
788
+ message: import_zod3.z.object({
789
+ role: import_zod3.z.literal("assistant"),
790
+ content: import_zod3.z.string().nullable().optional(),
791
+ reasoning: import_zod3.z.string().nullable().optional(),
792
+ reasoning_details: ReasoningDetailArraySchema.nullish(),
793
+ tool_calls: import_zod3.z.array(
794
+ import_zod3.z.object({
795
+ id: import_zod3.z.string().optional().nullable(),
796
+ type: import_zod3.z.literal("function"),
797
+ function: import_zod3.z.object({
798
+ name: import_zod3.z.string(),
799
+ arguments: import_zod3.z.string()
666
800
  })
667
801
  })
668
802
  ).optional()
669
803
  }),
670
- index: import_zod2.z.number(),
671
- logprobs: import_zod2.z.object({
672
- content: import_zod2.z.array(
673
- import_zod2.z.object({
674
- token: import_zod2.z.string(),
675
- logprob: import_zod2.z.number(),
676
- top_logprobs: import_zod2.z.array(
677
- import_zod2.z.object({
678
- token: import_zod2.z.string(),
679
- logprob: import_zod2.z.number()
804
+ index: import_zod3.z.number(),
805
+ logprobs: import_zod3.z.object({
806
+ content: import_zod3.z.array(
807
+ import_zod3.z.object({
808
+ token: import_zod3.z.string(),
809
+ logprob: import_zod3.z.number(),
810
+ top_logprobs: import_zod3.z.array(
811
+ import_zod3.z.object({
812
+ token: import_zod3.z.string(),
813
+ logprob: import_zod3.z.number()
680
814
  })
681
815
  )
682
816
  })
683
817
  ).nullable()
684
818
  }).nullable().optional(),
685
- finish_reason: import_zod2.z.string().optional().nullable()
819
+ finish_reason: import_zod3.z.string().optional().nullable()
686
820
  })
687
821
  )
688
822
  });
689
- var OpenRouterStreamChatCompletionChunkSchema = import_zod2.z.union([
823
+ var OpenRouterStreamChatCompletionChunkSchema = import_zod3.z.union([
690
824
  OpenRouterChatCompletionBaseResponseSchema.extend({
691
- choices: import_zod2.z.array(
692
- import_zod2.z.object({
693
- delta: import_zod2.z.object({
694
- role: import_zod2.z.enum(["assistant"]).optional(),
695
- content: import_zod2.z.string().nullish(),
696
- reasoning: import_zod2.z.string().nullish().optional(),
697
- tool_calls: import_zod2.z.array(
698
- import_zod2.z.object({
699
- index: import_zod2.z.number(),
700
- id: import_zod2.z.string().nullish(),
701
- type: import_zod2.z.literal("function").optional(),
702
- function: import_zod2.z.object({
703
- name: import_zod2.z.string().nullish(),
704
- arguments: import_zod2.z.string().nullish()
825
+ choices: import_zod3.z.array(
826
+ import_zod3.z.object({
827
+ delta: import_zod3.z.object({
828
+ role: import_zod3.z.enum(["assistant"]).optional(),
829
+ content: import_zod3.z.string().nullish(),
830
+ reasoning: import_zod3.z.string().nullish().optional(),
831
+ reasoning_details: ReasoningDetailArraySchema.nullish(),
832
+ tool_calls: import_zod3.z.array(
833
+ import_zod3.z.object({
834
+ index: import_zod3.z.number(),
835
+ id: import_zod3.z.string().nullish(),
836
+ type: import_zod3.z.literal("function").optional(),
837
+ function: import_zod3.z.object({
838
+ name: import_zod3.z.string().nullish(),
839
+ arguments: import_zod3.z.string().nullish()
705
840
  })
706
841
  })
707
842
  ).nullish()
708
843
  }).nullish(),
709
- logprobs: import_zod2.z.object({
710
- content: import_zod2.z.array(
711
- import_zod2.z.object({
712
- token: import_zod2.z.string(),
713
- logprob: import_zod2.z.number(),
714
- top_logprobs: import_zod2.z.array(
715
- import_zod2.z.object({
716
- token: import_zod2.z.string(),
717
- logprob: import_zod2.z.number()
844
+ logprobs: import_zod3.z.object({
845
+ content: import_zod3.z.array(
846
+ import_zod3.z.object({
847
+ token: import_zod3.z.string(),
848
+ logprob: import_zod3.z.number(),
849
+ top_logprobs: import_zod3.z.array(
850
+ import_zod3.z.object({
851
+ token: import_zod3.z.string(),
852
+ logprob: import_zod3.z.number()
718
853
  })
719
854
  )
720
855
  })
721
856
  ).nullable()
722
857
  }).nullish(),
723
- finish_reason: import_zod2.z.string().nullable().optional(),
724
- index: import_zod2.z.number()
858
+ finish_reason: import_zod3.z.string().nullable().optional(),
859
+ index: import_zod3.z.number()
725
860
  })
726
861
  )
727
862
  }),
@@ -781,7 +916,7 @@ function prepareToolsAndToolChoice(mode) {
781
916
  // src/openrouter-completion-language-model.ts
782
917
  var import_provider3 = require("@ai-sdk/provider");
783
918
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
784
- var import_zod3 = require("zod");
919
+ var import_zod4 = require("zod");
785
920
 
786
921
  // src/convert-to-openrouter-completion-prompt.ts
787
922
  var import_provider2 = require("@ai-sdk/provider");
@@ -860,6 +995,11 @@ ${userMessage}
860
995
  functionality: "redacted reasoning messages"
861
996
  });
862
997
  }
998
+ case "file": {
999
+ throw new import_provider2.UnsupportedFunctionalityError({
1000
+ functionality: "file attachments"
1001
+ });
1002
+ }
863
1003
  default: {
864
1004
  const _exhaustiveCheck = part;
865
1005
  throw new Error(
@@ -1106,7 +1246,9 @@ var OpenRouterCompletionLanguageModel = class {
1106
1246
  choice == null ? void 0 : choice.logprobs
1107
1247
  );
1108
1248
  if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
1109
- if (logprobs === void 0) logprobs = [];
1249
+ if (logprobs === void 0) {
1250
+ logprobs = [];
1251
+ }
1110
1252
  logprobs.push(...mappedLogprobs);
1111
1253
  }
1112
1254
  },
@@ -1126,26 +1268,27 @@ var OpenRouterCompletionLanguageModel = class {
1126
1268
  };
1127
1269
  }
1128
1270
  };
1129
- var OpenRouterCompletionChunkSchema = import_zod3.z.union([
1130
- import_zod3.z.object({
1131
- id: import_zod3.z.string().optional(),
1132
- model: import_zod3.z.string().optional(),
1133
- choices: import_zod3.z.array(
1134
- import_zod3.z.object({
1135
- text: import_zod3.z.string(),
1136
- reasoning: import_zod3.z.string().nullish().optional(),
1137
- finish_reason: import_zod3.z.string().nullish(),
1138
- index: import_zod3.z.number(),
1139
- logprobs: import_zod3.z.object({
1140
- tokens: import_zod3.z.array(import_zod3.z.string()),
1141
- token_logprobs: import_zod3.z.array(import_zod3.z.number()),
1142
- top_logprobs: import_zod3.z.array(import_zod3.z.record(import_zod3.z.string(), import_zod3.z.number())).nullable()
1271
+ var OpenRouterCompletionChunkSchema = import_zod4.z.union([
1272
+ import_zod4.z.object({
1273
+ id: import_zod4.z.string().optional(),
1274
+ model: import_zod4.z.string().optional(),
1275
+ choices: import_zod4.z.array(
1276
+ import_zod4.z.object({
1277
+ text: import_zod4.z.string(),
1278
+ reasoning: import_zod4.z.string().nullish().optional(),
1279
+ reasoning_details: ReasoningDetailArraySchema.nullish(),
1280
+ finish_reason: import_zod4.z.string().nullish(),
1281
+ index: import_zod4.z.number(),
1282
+ logprobs: import_zod4.z.object({
1283
+ tokens: import_zod4.z.array(import_zod4.z.string()),
1284
+ token_logprobs: import_zod4.z.array(import_zod4.z.number()),
1285
+ top_logprobs: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number())).nullable()
1143
1286
  }).nullable().optional()
1144
1287
  })
1145
1288
  ),
1146
- usage: import_zod3.z.object({
1147
- prompt_tokens: import_zod3.z.number(),
1148
- completion_tokens: import_zod3.z.number()
1289
+ usage: import_zod4.z.object({
1290
+ prompt_tokens: import_zod4.z.number(),
1291
+ completion_tokens: import_zod4.z.number()
1149
1292
  }).optional().nullable()
1150
1293
  }),
1151
1294
  OpenRouterErrorResponseSchema