@openrouter/ai-sdk-provider 0.6.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");
@@ -141,6 +167,8 @@ function convertToOpenRouterChatMessages(prompt) {
141
167
  }
142
168
  case "assistant": {
143
169
  let text = "";
170
+ let reasoning = "";
171
+ const reasoningDetails = [];
144
172
  const toolCalls = [];
145
173
  for (const part of content) {
146
174
  switch (part.type) {
@@ -159,10 +187,23 @@ function convertToOpenRouterChatMessages(prompt) {
159
187
  });
160
188
  break;
161
189
  }
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
+ }
162
206
  case "file":
163
- // TODO: Handle reasoning and redacted-reasoning
164
- case "reasoning":
165
- case "redacted-reasoning":
166
207
  break;
167
208
  default: {
168
209
  const _exhaustiveCheck = part;
@@ -174,6 +215,8 @@ function convertToOpenRouterChatMessages(prompt) {
174
215
  role: "assistant",
175
216
  content: text,
176
217
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
218
+ reasoning: reasoning || void 0,
219
+ reasoning_details: reasoningDetails.length > 0 ? reasoningDetails : void 0,
177
220
  cache_control: getCacheControl(providerMetadata)
178
221
  });
179
222
  break;
@@ -230,13 +273,13 @@ function mapOpenRouterFinishReason(finishReason) {
230
273
 
231
274
  // src/openrouter-error.ts
232
275
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
233
- var import_zod = require("zod");
234
- var OpenRouterErrorResponseSchema = import_zod.z.object({
235
- error: import_zod.z.object({
236
- message: import_zod.z.string(),
237
- type: import_zod.z.string(),
238
- param: import_zod.z.any().nullable(),
239
- 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()
240
283
  })
241
284
  });
242
285
  var openrouterFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
@@ -383,13 +426,56 @@ var OpenRouterChatLanguageModel = class {
383
426
  };
384
427
  }
385
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
+ ] : [];
386
472
  return __spreadValues({
387
473
  response: {
388
474
  id: response.id,
389
475
  modelId: response.model
390
476
  },
391
- text: (_h = choice.message.content) != null ? _h : void 0,
392
- reasoning: (_i = choice.message.reasoning) != null ? _i : void 0,
477
+ text: (_i = choice.message.content) != null ? _i : void 0,
478
+ reasoning,
393
479
  toolCalls: (_j = choice.message.tool_calls) == null ? void 0 : _j.map((toolCall) => {
394
480
  var _a2;
395
481
  return {
@@ -508,11 +594,56 @@ var OpenRouterChatLanguageModel = class {
508
594
  textDelta: delta.reasoning
509
595
  });
510
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
+ }
511
640
  const mappedLogprobs = mapOpenRouterChatLogProbsOutput(
512
641
  choice == null ? void 0 : choice.logprobs
513
642
  );
514
643
  if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
515
- if (logprobs === void 0) logprobs = [];
644
+ if (logprobs === void 0) {
645
+ logprobs = [];
646
+ }
516
647
  logprobs.push(...mappedLogprobs);
517
648
  }
518
649
  if (delta.tool_calls != null) {
@@ -635,95 +766,97 @@ var OpenRouterChatLanguageModel = class {
635
766
  };
636
767
  }
637
768
  };
638
- var OpenRouterChatCompletionBaseResponseSchema = import_zod2.z.object({
639
- id: import_zod2.z.string().optional(),
640
- model: import_zod2.z.string().optional(),
641
- usage: import_zod2.z.object({
642
- prompt_tokens: import_zod2.z.number(),
643
- prompt_tokens_details: import_zod2.z.object({
644
- 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()
645
776
  }).optional(),
646
- completion_tokens: import_zod2.z.number(),
647
- completion_tokens_details: import_zod2.z.object({
648
- 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()
649
780
  }).optional(),
650
- total_tokens: import_zod2.z.number(),
651
- cost: import_zod2.z.number().optional()
781
+ total_tokens: import_zod3.z.number(),
782
+ cost: import_zod3.z.number().optional()
652
783
  }).nullish()
653
784
  });
654
785
  var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
655
- choices: import_zod2.z.array(
656
- import_zod2.z.object({
657
- message: import_zod2.z.object({
658
- role: import_zod2.z.literal("assistant"),
659
- content: import_zod2.z.string().nullable().optional(),
660
- reasoning: import_zod2.z.string().nullable().optional(),
661
- tool_calls: import_zod2.z.array(
662
- import_zod2.z.object({
663
- id: import_zod2.z.string().optional().nullable(),
664
- type: import_zod2.z.literal("function"),
665
- function: import_zod2.z.object({
666
- name: import_zod2.z.string(),
667
- 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()
668
800
  })
669
801
  })
670
802
  ).optional()
671
803
  }),
672
- index: import_zod2.z.number(),
673
- logprobs: import_zod2.z.object({
674
- content: import_zod2.z.array(
675
- import_zod2.z.object({
676
- token: import_zod2.z.string(),
677
- logprob: import_zod2.z.number(),
678
- top_logprobs: import_zod2.z.array(
679
- import_zod2.z.object({
680
- token: import_zod2.z.string(),
681
- 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()
682
814
  })
683
815
  )
684
816
  })
685
817
  ).nullable()
686
818
  }).nullable().optional(),
687
- finish_reason: import_zod2.z.string().optional().nullable()
819
+ finish_reason: import_zod3.z.string().optional().nullable()
688
820
  })
689
821
  )
690
822
  });
691
- var OpenRouterStreamChatCompletionChunkSchema = import_zod2.z.union([
823
+ var OpenRouterStreamChatCompletionChunkSchema = import_zod3.z.union([
692
824
  OpenRouterChatCompletionBaseResponseSchema.extend({
693
- choices: import_zod2.z.array(
694
- import_zod2.z.object({
695
- delta: import_zod2.z.object({
696
- role: import_zod2.z.enum(["assistant"]).optional(),
697
- content: import_zod2.z.string().nullish(),
698
- reasoning: import_zod2.z.string().nullish().optional(),
699
- tool_calls: import_zod2.z.array(
700
- import_zod2.z.object({
701
- index: import_zod2.z.number(),
702
- id: import_zod2.z.string().nullish(),
703
- type: import_zod2.z.literal("function").optional(),
704
- function: import_zod2.z.object({
705
- name: import_zod2.z.string().nullish(),
706
- 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()
707
840
  })
708
841
  })
709
842
  ).nullish()
710
843
  }).nullish(),
711
- logprobs: import_zod2.z.object({
712
- content: import_zod2.z.array(
713
- import_zod2.z.object({
714
- token: import_zod2.z.string(),
715
- logprob: import_zod2.z.number(),
716
- top_logprobs: import_zod2.z.array(
717
- import_zod2.z.object({
718
- token: import_zod2.z.string(),
719
- 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()
720
853
  })
721
854
  )
722
855
  })
723
856
  ).nullable()
724
857
  }).nullish(),
725
- finish_reason: import_zod2.z.string().nullable().optional(),
726
- index: import_zod2.z.number()
858
+ finish_reason: import_zod3.z.string().nullable().optional(),
859
+ index: import_zod3.z.number()
727
860
  })
728
861
  )
729
862
  }),
@@ -783,7 +916,7 @@ function prepareToolsAndToolChoice(mode) {
783
916
  // src/openrouter-completion-language-model.ts
784
917
  var import_provider3 = require("@ai-sdk/provider");
785
918
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
786
- var import_zod3 = require("zod");
919
+ var import_zod4 = require("zod");
787
920
 
788
921
  // src/convert-to-openrouter-completion-prompt.ts
789
922
  var import_provider2 = require("@ai-sdk/provider");
@@ -1113,7 +1246,9 @@ var OpenRouterCompletionLanguageModel = class {
1113
1246
  choice == null ? void 0 : choice.logprobs
1114
1247
  );
1115
1248
  if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
1116
- if (logprobs === void 0) logprobs = [];
1249
+ if (logprobs === void 0) {
1250
+ logprobs = [];
1251
+ }
1117
1252
  logprobs.push(...mappedLogprobs);
1118
1253
  }
1119
1254
  },
@@ -1133,26 +1268,27 @@ var OpenRouterCompletionLanguageModel = class {
1133
1268
  };
1134
1269
  }
1135
1270
  };
1136
- var OpenRouterCompletionChunkSchema = import_zod3.z.union([
1137
- import_zod3.z.object({
1138
- id: import_zod3.z.string().optional(),
1139
- model: import_zod3.z.string().optional(),
1140
- choices: import_zod3.z.array(
1141
- import_zod3.z.object({
1142
- text: import_zod3.z.string(),
1143
- reasoning: import_zod3.z.string().nullish().optional(),
1144
- finish_reason: import_zod3.z.string().nullish(),
1145
- index: import_zod3.z.number(),
1146
- logprobs: import_zod3.z.object({
1147
- tokens: import_zod3.z.array(import_zod3.z.string()),
1148
- token_logprobs: import_zod3.z.array(import_zod3.z.number()),
1149
- 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()
1150
1286
  }).nullable().optional()
1151
1287
  })
1152
1288
  ),
1153
- usage: import_zod3.z.object({
1154
- prompt_tokens: import_zod3.z.number(),
1155
- 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()
1156
1292
  }).optional().nullable()
1157
1293
  }),
1158
1294
  OpenRouterErrorResponseSchema