@ai-sdk/openai-compatible 1.0.0-canary.5 → 1.0.0-canary.7

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.js CHANGED
@@ -31,7 +31,7 @@ module.exports = __toCommonJS(src_exports);
31
31
  // src/openai-compatible-chat-language-model.ts
32
32
  var import_provider3 = require("@ai-sdk/provider");
33
33
  var import_provider_utils = require("@ai-sdk/provider-utils");
34
- var import_zod2 = require("zod");
34
+ var import_zod3 = require("zod");
35
35
 
36
36
  // src/convert-to-openai-compatible-chat-messages.ts
37
37
  var import_provider = require("@ai-sdk/provider");
@@ -170,17 +170,27 @@ function mapOpenAICompatibleFinishReason(finishReason) {
170
170
  }
171
171
  }
172
172
 
173
- // src/openai-compatible-error.ts
173
+ // src/openai-compatible-chat-options.ts
174
174
  var import_zod = require("zod");
175
- var openaiCompatibleErrorDataSchema = import_zod.z.object({
176
- error: import_zod.z.object({
177
- message: import_zod.z.string(),
175
+ var openaiCompatibleProviderOptions = import_zod.z.object({
176
+ /**
177
+ * A unique identifier representing your end-user, which can help the provider to
178
+ * monitor and detect abuse.
179
+ */
180
+ user: import_zod.z.string().optional()
181
+ });
182
+
183
+ // src/openai-compatible-error.ts
184
+ var import_zod2 = require("zod");
185
+ var openaiCompatibleErrorDataSchema = import_zod2.z.object({
186
+ error: import_zod2.z.object({
187
+ message: import_zod2.z.string(),
178
188
  // The additional information below is handled loosely to support
179
189
  // OpenAI-compatible providers that have slightly different error
180
190
  // responses:
181
- type: import_zod.z.string().nullish(),
182
- param: import_zod.z.any().nullish(),
183
- code: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]).nullish()
191
+ type: import_zod2.z.string().nullish(),
192
+ param: import_zod2.z.any().nullish(),
193
+ code: import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number()]).nullish()
184
194
  })
185
195
  });
186
196
  var defaultOpenAICompatibleErrorStructure = {
@@ -244,11 +254,10 @@ function prepareTools({
244
254
  // src/openai-compatible-chat-language-model.ts
245
255
  var OpenAICompatibleChatLanguageModel = class {
246
256
  // type inferred via constructor
247
- constructor(modelId, settings, config) {
257
+ constructor(modelId, config) {
248
258
  this.specificationVersion = "v2";
249
259
  var _a, _b;
250
260
  this.modelId = modelId;
251
- this.settings = settings;
252
261
  this.config = config;
253
262
  const errorStructure = (_a = config.errorStructure) != null ? _a : defaultOpenAICompatibleErrorStructure;
254
263
  this.chunkSchema = createOpenAICompatibleChatChunkSchema(
@@ -268,7 +277,7 @@ var OpenAICompatibleChatLanguageModel = class {
268
277
  }
269
278
  getArgs({
270
279
  prompt,
271
- maxTokens,
280
+ maxOutputTokens,
272
281
  temperature,
273
282
  topP,
274
283
  topK,
@@ -281,8 +290,20 @@ var OpenAICompatibleChatLanguageModel = class {
281
290
  toolChoice,
282
291
  tools
283
292
  }) {
284
- var _a;
293
+ var _a, _b, _c;
285
294
  const warnings = [];
295
+ const compatibleOptions = Object.assign(
296
+ (_a = (0, import_provider_utils.parseProviderOptions)({
297
+ provider: "openai-compatible",
298
+ providerOptions,
299
+ schema: openaiCompatibleProviderOptions
300
+ })) != null ? _a : {},
301
+ (_b = (0, import_provider_utils.parseProviderOptions)({
302
+ provider: this.providerOptionsName,
303
+ providerOptions,
304
+ schema: openaiCompatibleProviderOptions
305
+ })) != null ? _b : {}
306
+ );
286
307
  if (topK != null) {
287
308
  warnings.push({ type: "unsupported-setting", setting: "topK" });
288
309
  }
@@ -306,9 +327,9 @@ var OpenAICompatibleChatLanguageModel = class {
306
327
  // model id:
307
328
  model: this.modelId,
308
329
  // model specific settings:
309
- user: this.settings.user,
330
+ user: compatibleOptions.user,
310
331
  // standardized settings:
311
- max_tokens: maxTokens,
332
+ max_tokens: maxOutputTokens,
312
333
  temperature,
313
334
  top_p: topP,
314
335
  frequency_penalty: frequencyPenalty,
@@ -317,7 +338,7 @@ var OpenAICompatibleChatLanguageModel = class {
317
338
  type: "json_schema",
318
339
  json_schema: {
319
340
  schema: responseFormat.schema,
320
- name: (_a = responseFormat.name) != null ? _a : "response",
341
+ name: (_c = responseFormat.name) != null ? _c : "response",
321
342
  description: responseFormat.description
322
343
  }
323
344
  } : { type: "json_object" } : void 0,
@@ -334,7 +355,7 @@ var OpenAICompatibleChatLanguageModel = class {
334
355
  };
335
356
  }
336
357
  async doGenerate(options) {
337
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
358
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
338
359
  const { args, warnings } = this.getArgs({ ...options });
339
360
  const body = JSON.stringify(args);
340
361
  const {
@@ -378,11 +399,18 @@ var OpenAICompatibleChatLanguageModel = class {
378
399
  providerMetadata[this.providerOptionsName].cachedPromptTokens = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens;
379
400
  }
380
401
  return {
381
- text: (_e = choice.message.content) != null ? _e : void 0,
382
- reasoning: (_f = choice.message.reasoning_content) != null ? _f : void 0,
383
- toolCalls: (_g = choice.message.tool_calls) == null ? void 0 : _g.map((toolCall) => {
402
+ text: choice.message.content != null ? { type: "text", text: choice.message.content } : void 0,
403
+ reasoning: choice.message.reasoning_content ? [
404
+ {
405
+ type: "reasoning",
406
+ reasoningType: "text",
407
+ text: choice.message.reasoning_content
408
+ }
409
+ ] : void 0,
410
+ toolCalls: (_e = choice.message.tool_calls) == null ? void 0 : _e.map((toolCall) => {
384
411
  var _a2;
385
412
  return {
413
+ type: "tool-call",
386
414
  toolCallType: "function",
387
415
  toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils.generateId)(),
388
416
  toolName: toolCall.function.name,
@@ -391,8 +419,8 @@ var OpenAICompatibleChatLanguageModel = class {
391
419
  }),
392
420
  finishReason: mapOpenAICompatibleFinishReason(choice.finish_reason),
393
421
  usage: {
394
- promptTokens: (_i = (_h = responseBody.usage) == null ? void 0 : _h.prompt_tokens) != null ? _i : NaN,
395
- completionTokens: (_k = (_j = responseBody.usage) == null ? void 0 : _j.completion_tokens) != null ? _k : NaN
422
+ inputTokens: (_g = (_f = responseBody.usage) == null ? void 0 : _f.prompt_tokens) != null ? _g : void 0,
423
+ outputTokens: (_i = (_h = responseBody.usage) == null ? void 0 : _h.completion_tokens) != null ? _i : void 0
396
424
  },
397
425
  providerMetadata,
398
426
  request: { body },
@@ -406,59 +434,6 @@ var OpenAICompatibleChatLanguageModel = class {
406
434
  }
407
435
  async doStream(options) {
408
436
  var _a;
409
- if (this.settings.simulateStreaming) {
410
- const result = await this.doGenerate(options);
411
- const simulatedStream = new ReadableStream({
412
- start(controller) {
413
- controller.enqueue({ type: "response-metadata", ...result.response });
414
- if (result.reasoning) {
415
- if (Array.isArray(result.reasoning)) {
416
- for (const part of result.reasoning) {
417
- if (part.type === "text") {
418
- controller.enqueue({
419
- type: "reasoning",
420
- textDelta: part.text
421
- });
422
- }
423
- }
424
- } else {
425
- controller.enqueue({
426
- type: "reasoning",
427
- textDelta: result.reasoning
428
- });
429
- }
430
- }
431
- if (result.text) {
432
- controller.enqueue({
433
- type: "text-delta",
434
- textDelta: result.text
435
- });
436
- }
437
- if (result.toolCalls) {
438
- for (const toolCall of result.toolCalls) {
439
- controller.enqueue({
440
- type: "tool-call",
441
- ...toolCall
442
- });
443
- }
444
- }
445
- controller.enqueue({
446
- type: "finish",
447
- finishReason: result.finishReason,
448
- usage: result.usage,
449
- logprobs: result.logprobs,
450
- providerMetadata: result.providerMetadata
451
- });
452
- controller.close();
453
- }
454
- });
455
- return {
456
- stream: simulatedStream,
457
- request: result.request,
458
- response: result.response,
459
- warnings: result.warnings
460
- };
461
- }
462
437
  const { args, warnings } = this.getArgs({ ...options });
463
438
  const body = JSON.stringify({ ...args, stream: true });
464
439
  const metadataExtractor = (_a = this.config.metadataExtractor) == null ? void 0 : _a.createStreamExtractor();
@@ -479,7 +454,6 @@ var OpenAICompatibleChatLanguageModel = class {
479
454
  abortSignal: options.abortSignal,
480
455
  fetch: this.config.fetch
481
456
  });
482
- const { messages: rawPrompt, ...rawSettings } = args;
483
457
  const toolCalls = [];
484
458
  let finishReason = "unknown";
485
459
  let usage = {
@@ -556,13 +530,14 @@ var OpenAICompatibleChatLanguageModel = class {
556
530
  if (delta.reasoning_content != null) {
557
531
  controller.enqueue({
558
532
  type: "reasoning",
559
- textDelta: delta.reasoning_content
533
+ reasoningType: "text",
534
+ text: delta.reasoning_content
560
535
  });
561
536
  }
562
537
  if (delta.content != null) {
563
538
  controller.enqueue({
564
- type: "text-delta",
565
- textDelta: delta.content
539
+ type: "text",
540
+ text: delta.content
566
541
  });
567
542
  }
568
543
  if (delta.tool_calls != null) {
@@ -669,8 +644,8 @@ var OpenAICompatibleChatLanguageModel = class {
669
644
  type: "finish",
670
645
  finishReason,
671
646
  usage: {
672
- promptTokens: (_a2 = usage.promptTokens) != null ? _a2 : NaN,
673
- completionTokens: (_b = usage.completionTokens) != null ? _b : NaN
647
+ inputTokens: (_a2 = usage.promptTokens) != null ? _a2 : void 0,
648
+ outputTokens: (_b = usage.completionTokens) != null ? _b : void 0
674
649
  },
675
650
  providerMetadata
676
651
  });
@@ -683,68 +658,68 @@ var OpenAICompatibleChatLanguageModel = class {
683
658
  };
684
659
  }
685
660
  };
686
- var openaiCompatibleTokenUsageSchema = import_zod2.z.object({
687
- prompt_tokens: import_zod2.z.number().nullish(),
688
- completion_tokens: import_zod2.z.number().nullish(),
689
- prompt_tokens_details: import_zod2.z.object({
690
- cached_tokens: import_zod2.z.number().nullish()
661
+ var openaiCompatibleTokenUsageSchema = import_zod3.z.object({
662
+ prompt_tokens: import_zod3.z.number().nullish(),
663
+ completion_tokens: import_zod3.z.number().nullish(),
664
+ prompt_tokens_details: import_zod3.z.object({
665
+ cached_tokens: import_zod3.z.number().nullish()
691
666
  }).nullish(),
692
- completion_tokens_details: import_zod2.z.object({
693
- reasoning_tokens: import_zod2.z.number().nullish(),
694
- accepted_prediction_tokens: import_zod2.z.number().nullish(),
695
- rejected_prediction_tokens: import_zod2.z.number().nullish()
667
+ completion_tokens_details: import_zod3.z.object({
668
+ reasoning_tokens: import_zod3.z.number().nullish(),
669
+ accepted_prediction_tokens: import_zod3.z.number().nullish(),
670
+ rejected_prediction_tokens: import_zod3.z.number().nullish()
696
671
  }).nullish()
697
672
  }).nullish();
698
- var OpenAICompatibleChatResponseSchema = import_zod2.z.object({
699
- id: import_zod2.z.string().nullish(),
700
- created: import_zod2.z.number().nullish(),
701
- model: import_zod2.z.string().nullish(),
702
- choices: import_zod2.z.array(
703
- import_zod2.z.object({
704
- message: import_zod2.z.object({
705
- role: import_zod2.z.literal("assistant").nullish(),
706
- content: import_zod2.z.string().nullish(),
707
- reasoning_content: import_zod2.z.string().nullish(),
708
- tool_calls: import_zod2.z.array(
709
- import_zod2.z.object({
710
- id: import_zod2.z.string().nullish(),
711
- type: import_zod2.z.literal("function"),
712
- function: import_zod2.z.object({
713
- name: import_zod2.z.string(),
714
- arguments: import_zod2.z.string()
673
+ var OpenAICompatibleChatResponseSchema = import_zod3.z.object({
674
+ id: import_zod3.z.string().nullish(),
675
+ created: import_zod3.z.number().nullish(),
676
+ model: import_zod3.z.string().nullish(),
677
+ choices: import_zod3.z.array(
678
+ import_zod3.z.object({
679
+ message: import_zod3.z.object({
680
+ role: import_zod3.z.literal("assistant").nullish(),
681
+ content: import_zod3.z.string().nullish(),
682
+ reasoning_content: import_zod3.z.string().nullish(),
683
+ tool_calls: import_zod3.z.array(
684
+ import_zod3.z.object({
685
+ id: import_zod3.z.string().nullish(),
686
+ type: import_zod3.z.literal("function"),
687
+ function: import_zod3.z.object({
688
+ name: import_zod3.z.string(),
689
+ arguments: import_zod3.z.string()
715
690
  })
716
691
  })
717
692
  ).nullish()
718
693
  }),
719
- finish_reason: import_zod2.z.string().nullish()
694
+ finish_reason: import_zod3.z.string().nullish()
720
695
  })
721
696
  ),
722
697
  usage: openaiCompatibleTokenUsageSchema
723
698
  });
724
- var createOpenAICompatibleChatChunkSchema = (errorSchema) => import_zod2.z.union([
725
- import_zod2.z.object({
726
- id: import_zod2.z.string().nullish(),
727
- created: import_zod2.z.number().nullish(),
728
- model: import_zod2.z.string().nullish(),
729
- choices: import_zod2.z.array(
730
- import_zod2.z.object({
731
- delta: import_zod2.z.object({
732
- role: import_zod2.z.enum(["assistant"]).nullish(),
733
- content: import_zod2.z.string().nullish(),
734
- reasoning_content: import_zod2.z.string().nullish(),
735
- tool_calls: import_zod2.z.array(
736
- import_zod2.z.object({
737
- index: import_zod2.z.number(),
738
- id: import_zod2.z.string().nullish(),
739
- type: import_zod2.z.literal("function").optional(),
740
- function: import_zod2.z.object({
741
- name: import_zod2.z.string().nullish(),
742
- arguments: import_zod2.z.string().nullish()
699
+ var createOpenAICompatibleChatChunkSchema = (errorSchema) => import_zod3.z.union([
700
+ import_zod3.z.object({
701
+ id: import_zod3.z.string().nullish(),
702
+ created: import_zod3.z.number().nullish(),
703
+ model: import_zod3.z.string().nullish(),
704
+ choices: import_zod3.z.array(
705
+ import_zod3.z.object({
706
+ delta: import_zod3.z.object({
707
+ role: import_zod3.z.enum(["assistant"]).nullish(),
708
+ content: import_zod3.z.string().nullish(),
709
+ reasoning_content: import_zod3.z.string().nullish(),
710
+ tool_calls: import_zod3.z.array(
711
+ import_zod3.z.object({
712
+ index: import_zod3.z.number(),
713
+ id: import_zod3.z.string().nullish(),
714
+ type: import_zod3.z.literal("function").optional(),
715
+ function: import_zod3.z.object({
716
+ name: import_zod3.z.string().nullish(),
717
+ arguments: import_zod3.z.string().nullish()
743
718
  })
744
719
  })
745
720
  ).nullish()
746
721
  }).nullish(),
747
- finish_reason: import_zod2.z.string().nullish()
722
+ finish_reason: import_zod3.z.string().nullish()
748
723
  })
749
724
  ),
750
725
  usage: openaiCompatibleTokenUsageSchema
@@ -754,7 +729,7 @@ var createOpenAICompatibleChatChunkSchema = (errorSchema) => import_zod2.z.union
754
729
 
755
730
  // src/openai-compatible-completion-language-model.ts
756
731
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
757
- var import_zod3 = require("zod");
732
+ var import_zod5 = require("zod");
758
733
 
759
734
  // src/convert-to-openai-compatible-completion-prompt.ts
760
735
  var import_provider4 = require("@ai-sdk/provider");
@@ -835,15 +810,39 @@ ${user}:`]
835
810
  };
836
811
  }
837
812
 
813
+ // src/openai-compatible-completion-options.ts
814
+ var import_zod4 = require("zod");
815
+ var openaiCompatibleCompletionProviderOptions = import_zod4.z.object({
816
+ /**
817
+ * Echo back the prompt in addition to the completion.
818
+ */
819
+ echo: import_zod4.z.boolean().optional(),
820
+ /**
821
+ * Modify the likelihood of specified tokens appearing in the completion.
822
+ *
823
+ * Accepts a JSON object that maps tokens (specified by their token ID in
824
+ * the GPT tokenizer) to an associated bias value from -100 to 100.
825
+ */
826
+ logitBias: import_zod4.z.record(import_zod4.z.number(), import_zod4.z.number()).optional(),
827
+ /**
828
+ * The suffix that comes after a completion of inserted text.
829
+ */
830
+ suffix: import_zod4.z.string().optional(),
831
+ /**
832
+ * A unique identifier representing your end-user, which can help providers to
833
+ * monitor and detect abuse.
834
+ */
835
+ user: import_zod4.z.string().optional()
836
+ });
837
+
838
838
  // src/openai-compatible-completion-language-model.ts
839
839
  var OpenAICompatibleCompletionLanguageModel = class {
840
840
  // type inferred via constructor
841
- constructor(modelId, settings, config) {
841
+ constructor(modelId, config) {
842
842
  this.specificationVersion = "v2";
843
843
  this.defaultObjectGenerationMode = void 0;
844
844
  var _a;
845
845
  this.modelId = modelId;
846
- this.settings = settings;
847
846
  this.config = config;
848
847
  const errorStructure = (_a = config.errorStructure) != null ? _a : defaultOpenAICompatibleErrorStructure;
849
848
  this.chunkSchema = createOpenAICompatibleCompletionChunkSchema(
@@ -860,7 +859,7 @@ var OpenAICompatibleCompletionLanguageModel = class {
860
859
  getArgs({
861
860
  inputFormat,
862
861
  prompt,
863
- maxTokens,
862
+ maxOutputTokens,
864
863
  temperature,
865
864
  topP,
866
865
  topK,
@@ -873,7 +872,13 @@ var OpenAICompatibleCompletionLanguageModel = class {
873
872
  tools,
874
873
  toolChoice
875
874
  }) {
875
+ var _a;
876
876
  const warnings = [];
877
+ const completionOptions = (_a = (0, import_provider_utils2.parseProviderOptions)({
878
+ provider: this.providerOptionsName,
879
+ providerOptions,
880
+ schema: openaiCompatibleCompletionProviderOptions
881
+ })) != null ? _a : {};
877
882
  if (topK != null) {
878
883
  warnings.push({ type: "unsupported-setting", setting: "topK" });
879
884
  }
@@ -897,12 +902,12 @@ var OpenAICompatibleCompletionLanguageModel = class {
897
902
  // model id:
898
903
  model: this.modelId,
899
904
  // model specific settings:
900
- echo: this.settings.echo,
901
- logit_bias: this.settings.logitBias,
902
- suffix: this.settings.suffix,
903
- user: this.settings.user,
905
+ echo: completionOptions.echo,
906
+ logit_bias: completionOptions.logitBias,
907
+ suffix: completionOptions.suffix,
908
+ user: completionOptions.user,
904
909
  // standardized settings:
905
- max_tokens: maxTokens,
910
+ max_tokens: maxOutputTokens,
906
911
  temperature,
907
912
  top_p: topP,
908
913
  frequency_penalty: frequencyPenalty,
@@ -940,10 +945,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
940
945
  });
941
946
  const choice = response.choices[0];
942
947
  return {
943
- text: choice.text,
948
+ text: { type: "text", text: choice.text },
944
949
  usage: {
945
- promptTokens: (_b = (_a = response.usage) == null ? void 0 : _a.prompt_tokens) != null ? _b : NaN,
946
- completionTokens: (_d = (_c = response.usage) == null ? void 0 : _c.completion_tokens) != null ? _d : NaN
950
+ inputTokens: (_b = (_a = response.usage) == null ? void 0 : _a.prompt_tokens) != null ? _b : void 0,
951
+ outputTokens: (_d = (_c = response.usage) == null ? void 0 : _c.completion_tokens) != null ? _d : void 0
947
952
  },
948
953
  finishReason: mapOpenAICompatibleFinishReason(choice.finish_reason),
949
954
  request: { body: args },
@@ -976,15 +981,16 @@ var OpenAICompatibleCompletionLanguageModel = class {
976
981
  fetch: this.config.fetch
977
982
  });
978
983
  let finishReason = "unknown";
979
- let usage = {
980
- promptTokens: Number.NaN,
981
- completionTokens: Number.NaN
984
+ const usage = {
985
+ inputTokens: void 0,
986
+ outputTokens: void 0
982
987
  };
983
988
  let isFirstChunk = true;
984
989
  return {
985
990
  stream: response.pipeThrough(
986
991
  new TransformStream({
987
992
  transform(chunk, controller) {
993
+ var _a, _b;
988
994
  if (!chunk.success) {
989
995
  finishReason = "error";
990
996
  controller.enqueue({ type: "error", error: chunk.error });
@@ -1004,10 +1010,8 @@ var OpenAICompatibleCompletionLanguageModel = class {
1004
1010
  });
1005
1011
  }
1006
1012
  if (value.usage != null) {
1007
- usage = {
1008
- promptTokens: value.usage.prompt_tokens,
1009
- completionTokens: value.usage.completion_tokens
1010
- };
1013
+ usage.inputTokens = (_a = value.usage.prompt_tokens) != null ? _a : void 0;
1014
+ usage.outputTokens = (_b = value.usage.completion_tokens) != null ? _b : void 0;
1011
1015
  }
1012
1016
  const choice = value.choices[0];
1013
1017
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
@@ -1017,8 +1021,8 @@ var OpenAICompatibleCompletionLanguageModel = class {
1017
1021
  }
1018
1022
  if ((choice == null ? void 0 : choice.text) != null) {
1019
1023
  controller.enqueue({
1020
- type: "text-delta",
1021
- textDelta: choice.text
1024
+ type: "text",
1025
+ text: choice.text
1022
1026
  });
1023
1027
  }
1024
1028
  },
@@ -1037,36 +1041,36 @@ var OpenAICompatibleCompletionLanguageModel = class {
1037
1041
  };
1038
1042
  }
1039
1043
  };
1040
- var openaiCompatibleCompletionResponseSchema = import_zod3.z.object({
1041
- id: import_zod3.z.string().nullish(),
1042
- created: import_zod3.z.number().nullish(),
1043
- model: import_zod3.z.string().nullish(),
1044
- choices: import_zod3.z.array(
1045
- import_zod3.z.object({
1046
- text: import_zod3.z.string(),
1047
- finish_reason: import_zod3.z.string()
1044
+ var openaiCompatibleCompletionResponseSchema = import_zod5.z.object({
1045
+ id: import_zod5.z.string().nullish(),
1046
+ created: import_zod5.z.number().nullish(),
1047
+ model: import_zod5.z.string().nullish(),
1048
+ choices: import_zod5.z.array(
1049
+ import_zod5.z.object({
1050
+ text: import_zod5.z.string(),
1051
+ finish_reason: import_zod5.z.string()
1048
1052
  })
1049
1053
  ),
1050
- usage: import_zod3.z.object({
1051
- prompt_tokens: import_zod3.z.number(),
1052
- completion_tokens: import_zod3.z.number()
1054
+ usage: import_zod5.z.object({
1055
+ prompt_tokens: import_zod5.z.number(),
1056
+ completion_tokens: import_zod5.z.number()
1053
1057
  }).nullish()
1054
1058
  });
1055
- var createOpenAICompatibleCompletionChunkSchema = (errorSchema) => import_zod3.z.union([
1056
- import_zod3.z.object({
1057
- id: import_zod3.z.string().nullish(),
1058
- created: import_zod3.z.number().nullish(),
1059
- model: import_zod3.z.string().nullish(),
1060
- choices: import_zod3.z.array(
1061
- import_zod3.z.object({
1062
- text: import_zod3.z.string(),
1063
- finish_reason: import_zod3.z.string().nullish(),
1064
- index: import_zod3.z.number()
1059
+ var createOpenAICompatibleCompletionChunkSchema = (errorSchema) => import_zod5.z.union([
1060
+ import_zod5.z.object({
1061
+ id: import_zod5.z.string().nullish(),
1062
+ created: import_zod5.z.number().nullish(),
1063
+ model: import_zod5.z.string().nullish(),
1064
+ choices: import_zod5.z.array(
1065
+ import_zod5.z.object({
1066
+ text: import_zod5.z.string(),
1067
+ finish_reason: import_zod5.z.string().nullish(),
1068
+ index: import_zod5.z.number()
1065
1069
  })
1066
1070
  ),
1067
- usage: import_zod3.z.object({
1068
- prompt_tokens: import_zod3.z.number(),
1069
- completion_tokens: import_zod3.z.number()
1071
+ usage: import_zod5.z.object({
1072
+ prompt_tokens: import_zod5.z.number(),
1073
+ completion_tokens: import_zod5.z.number()
1070
1074
  }).nullish()
1071
1075
  }),
1072
1076
  errorSchema
@@ -1075,12 +1079,28 @@ var createOpenAICompatibleCompletionChunkSchema = (errorSchema) => import_zod3.z
1075
1079
  // src/openai-compatible-embedding-model.ts
1076
1080
  var import_provider5 = require("@ai-sdk/provider");
1077
1081
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
1078
- var import_zod4 = require("zod");
1082
+ var import_zod7 = require("zod");
1083
+
1084
+ // src/openai-compatible-embedding-options.ts
1085
+ var import_zod6 = require("zod");
1086
+ var openaiCompatibleEmbeddingProviderOptions = import_zod6.z.object({
1087
+ /**
1088
+ * The number of dimensions the resulting output embeddings should have.
1089
+ * Only supported in text-embedding-3 and later models.
1090
+ */
1091
+ dimensions: import_zod6.z.number().optional(),
1092
+ /**
1093
+ * A unique identifier representing your end-user, which can help providers to
1094
+ * monitor and detect abuse.
1095
+ */
1096
+ user: import_zod6.z.string().optional()
1097
+ });
1098
+
1099
+ // src/openai-compatible-embedding-model.ts
1079
1100
  var OpenAICompatibleEmbeddingModel = class {
1080
- constructor(modelId, settings, config) {
1081
- this.specificationVersion = "v1";
1101
+ constructor(modelId, config) {
1102
+ this.specificationVersion = "v2";
1082
1103
  this.modelId = modelId;
1083
- this.settings = settings;
1084
1104
  this.config = config;
1085
1105
  }
1086
1106
  get provider() {
@@ -1094,12 +1114,28 @@ var OpenAICompatibleEmbeddingModel = class {
1094
1114
  var _a;
1095
1115
  return (_a = this.config.supportsParallelCalls) != null ? _a : true;
1096
1116
  }
1117
+ get providerOptionsName() {
1118
+ return this.config.provider.split(".")[0].trim();
1119
+ }
1097
1120
  async doEmbed({
1098
1121
  values,
1099
1122
  headers,
1100
- abortSignal
1123
+ abortSignal,
1124
+ providerOptions
1101
1125
  }) {
1102
- var _a;
1126
+ var _a, _b, _c;
1127
+ const compatibleOptions = Object.assign(
1128
+ (_a = (0, import_provider_utils3.parseProviderOptions)({
1129
+ provider: "openai-compatible",
1130
+ providerOptions,
1131
+ schema: openaiCompatibleEmbeddingProviderOptions
1132
+ })) != null ? _a : {},
1133
+ (_b = (0, import_provider_utils3.parseProviderOptions)({
1134
+ provider: this.providerOptionsName,
1135
+ providerOptions,
1136
+ schema: openaiCompatibleEmbeddingProviderOptions
1137
+ })) != null ? _b : {}
1138
+ );
1103
1139
  if (values.length > this.maxEmbeddingsPerCall) {
1104
1140
  throw new import_provider5.TooManyEmbeddingValuesForCallError({
1105
1141
  provider: this.provider,
@@ -1108,7 +1144,11 @@ var OpenAICompatibleEmbeddingModel = class {
1108
1144
  values
1109
1145
  });
1110
1146
  }
1111
- const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
1147
+ const {
1148
+ responseHeaders,
1149
+ value: response,
1150
+ rawValue
1151
+ } = await (0, import_provider_utils3.postJsonToApi)({
1112
1152
  url: this.config.url({
1113
1153
  path: "/embeddings",
1114
1154
  modelId: this.modelId
@@ -1118,11 +1158,11 @@ var OpenAICompatibleEmbeddingModel = class {
1118
1158
  model: this.modelId,
1119
1159
  input: values,
1120
1160
  encoding_format: "float",
1121
- dimensions: this.settings.dimensions,
1122
- user: this.settings.user
1161
+ dimensions: compatibleOptions.dimensions,
1162
+ user: compatibleOptions.user
1123
1163
  },
1124
1164
  failedResponseHandler: (0, import_provider_utils3.createJsonErrorResponseHandler)(
1125
- (_a = this.config.errorStructure) != null ? _a : defaultOpenAICompatibleErrorStructure
1165
+ (_c = this.config.errorStructure) != null ? _c : defaultOpenAICompatibleErrorStructure
1126
1166
  ),
1127
1167
  successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
1128
1168
  openaiTextEmbeddingResponseSchema
@@ -1133,18 +1173,18 @@ var OpenAICompatibleEmbeddingModel = class {
1133
1173
  return {
1134
1174
  embeddings: response.data.map((item) => item.embedding),
1135
1175
  usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
1136
- rawResponse: { headers: responseHeaders }
1176
+ response: { headers: responseHeaders, body: rawValue }
1137
1177
  };
1138
1178
  }
1139
1179
  };
1140
- var openaiTextEmbeddingResponseSchema = import_zod4.z.object({
1141
- data: import_zod4.z.array(import_zod4.z.object({ embedding: import_zod4.z.array(import_zod4.z.number()) })),
1142
- usage: import_zod4.z.object({ prompt_tokens: import_zod4.z.number() }).nullish()
1180
+ var openaiTextEmbeddingResponseSchema = import_zod7.z.object({
1181
+ data: import_zod7.z.array(import_zod7.z.object({ embedding: import_zod7.z.array(import_zod7.z.number()) })),
1182
+ usage: import_zod7.z.object({ prompt_tokens: import_zod7.z.number() }).nullish()
1143
1183
  });
1144
1184
 
1145
1185
  // src/openai-compatible-image-model.ts
1146
1186
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
1147
- var import_zod5 = require("zod");
1187
+ var import_zod8 = require("zod");
1148
1188
  var OpenAICompatibleImageModel = class {
1149
1189
  constructor(modelId, settings, config) {
1150
1190
  this.modelId = modelId;
@@ -1217,8 +1257,8 @@ var OpenAICompatibleImageModel = class {
1217
1257
  };
1218
1258
  }
1219
1259
  };
1220
- var openaiCompatibleImageResponseSchema = import_zod5.z.object({
1221
- data: import_zod5.z.array(import_zod5.z.object({ b64_json: import_zod5.z.string() }))
1260
+ var openaiCompatibleImageResponseSchema = import_zod8.z.object({
1261
+ data: import_zod8.z.array(import_zod8.z.object({ b64_json: import_zod8.z.string() }))
1222
1262
  });
1223
1263
 
1224
1264
  // src/openai-compatible-provider.ts
@@ -1242,27 +1282,24 @@ function createOpenAICompatible(options) {
1242
1282
  headers: getHeaders,
1243
1283
  fetch: options.fetch
1244
1284
  });
1245
- const createLanguageModel = (modelId, settings = {}) => createChatModel(modelId, settings);
1246
- const createChatModel = (modelId, settings = {}) => new OpenAICompatibleChatLanguageModel(modelId, settings, {
1285
+ const createLanguageModel = (modelId) => createChatModel(modelId);
1286
+ const createChatModel = (modelId) => new OpenAICompatibleChatLanguageModel(modelId, {
1247
1287
  ...getCommonModelConfig("chat"),
1248
1288
  defaultObjectGenerationMode: "tool"
1249
1289
  });
1250
- const createCompletionModel = (modelId, settings = {}) => new OpenAICompatibleCompletionLanguageModel(
1290
+ const createCompletionModel = (modelId) => new OpenAICompatibleCompletionLanguageModel(
1251
1291
  modelId,
1252
- settings,
1253
1292
  getCommonModelConfig("completion")
1254
1293
  );
1255
- const createEmbeddingModel = (modelId, settings = {}) => new OpenAICompatibleEmbeddingModel(
1256
- modelId,
1257
- settings,
1258
- getCommonModelConfig("embedding")
1259
- );
1294
+ const createEmbeddingModel = (modelId) => new OpenAICompatibleEmbeddingModel(modelId, {
1295
+ ...getCommonModelConfig("embedding")
1296
+ });
1260
1297
  const createImageModel = (modelId, settings = {}) => new OpenAICompatibleImageModel(
1261
1298
  modelId,
1262
1299
  settings,
1263
1300
  getCommonModelConfig("image")
1264
1301
  );
1265
- const provider = (modelId, settings) => createLanguageModel(modelId, settings);
1302
+ const provider = (modelId) => createLanguageModel(modelId);
1266
1303
  provider.languageModel = createLanguageModel;
1267
1304
  provider.chatModel = createChatModel;
1268
1305
  provider.completionModel = createCompletionModel;