@ai-sdk/openai 3.0.0-beta.102 → 3.0.0-beta.105

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.mjs CHANGED
@@ -43,7 +43,7 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
43
43
  function getOpenAILanguageModelCapabilities(modelId) {
44
44
  const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
45
45
  const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
46
- const isReasoningModel = !(modelId.startsWith("gpt-3") || modelId.startsWith("gpt-4") || modelId.startsWith("chatgpt-4o") || modelId.startsWith("gpt-5-chat"));
46
+ const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("codex-mini") || modelId.startsWith("computer-use-preview") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
47
47
  const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2");
48
48
  const systemMessageMode = isReasoningModel ? "developer" : "system";
49
49
  return {
@@ -545,7 +545,26 @@ var openaiChatLanguageModelOptions = lazySchema2(
545
545
  * username or email address, in order to avoid sending us any identifying
546
546
  * information.
547
547
  */
548
- safetyIdentifier: z3.string().optional()
548
+ safetyIdentifier: z3.string().optional(),
549
+ /**
550
+ * Override the system message mode for this model.
551
+ * - 'system': Use the 'system' role for system messages (default for most models)
552
+ * - 'developer': Use the 'developer' role for system messages (used by reasoning models)
553
+ * - 'remove': Remove system messages entirely
554
+ *
555
+ * If not specified, the mode is automatically determined based on the model.
556
+ */
557
+ systemMessageMode: z3.enum(["system", "developer", "remove"]).optional(),
558
+ /**
559
+ * Force treating this model as a reasoning model.
560
+ *
561
+ * This is useful for "stealth" reasoning models (e.g. via a custom baseURL)
562
+ * where the model ID is not recognized by the SDK's allowlist.
563
+ *
564
+ * When enabled, the SDK applies reasoning-model parameter compatibility rules
565
+ * and defaults `systemMessageMode` to `developer` unless overridden.
566
+ */
567
+ forceReasoning: z3.boolean().optional()
549
568
  })
550
569
  )
551
570
  );
@@ -642,7 +661,7 @@ var OpenAIChatLanguageModel = class {
642
661
  toolChoice,
643
662
  providerOptions
644
663
  }) {
645
- var _a, _b, _c;
664
+ var _a, _b, _c, _d, _e;
646
665
  const warnings = [];
647
666
  const openaiOptions = (_a = await parseProviderOptions({
648
667
  provider: "openai",
@@ -650,17 +669,18 @@ var OpenAIChatLanguageModel = class {
650
669
  schema: openaiChatLanguageModelOptions
651
670
  })) != null ? _a : {};
652
671
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
672
+ const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
653
673
  if (topK != null) {
654
674
  warnings.push({ type: "unsupported", feature: "topK" });
655
675
  }
656
676
  const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
657
677
  {
658
678
  prompt,
659
- systemMessageMode: modelCapabilities.systemMessageMode
679
+ systemMessageMode: (_c = openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
660
680
  }
661
681
  );
662
682
  warnings.push(...messageWarnings);
663
- const strictJsonSchema = (_b = openaiOptions.strictJsonSchema) != null ? _b : true;
683
+ const strictJsonSchema = (_d = openaiOptions.strictJsonSchema) != null ? _d : true;
664
684
  const baseArgs = {
665
685
  // model id:
666
686
  model: this.modelId,
@@ -681,7 +701,7 @@ var OpenAIChatLanguageModel = class {
681
701
  json_schema: {
682
702
  schema: responseFormat.schema,
683
703
  strict: strictJsonSchema,
684
- name: (_c = responseFormat.name) != null ? _c : "response",
704
+ name: (_e = responseFormat.name) != null ? _e : "response",
685
705
  description: responseFormat.description
686
706
  }
687
707
  } : { type: "json_object" } : void 0,
@@ -702,7 +722,7 @@ var OpenAIChatLanguageModel = class {
702
722
  // messages:
703
723
  messages
704
724
  };
705
- if (modelCapabilities.isReasoningModel) {
725
+ if (isReasoningModel) {
706
726
  if (openaiOptions.reasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
707
727
  if (baseArgs.temperature != null) {
708
728
  baseArgs.temperature = void 0;
@@ -1678,7 +1698,11 @@ var OpenAIEmbeddingModel = class {
1678
1698
  // src/image/openai-image-model.ts
1679
1699
  import {
1680
1700
  combineHeaders as combineHeaders4,
1701
+ convertBase64ToUint8Array,
1702
+ convertToFormData,
1681
1703
  createJsonResponseHandler as createJsonResponseHandler4,
1704
+ downloadBlob,
1705
+ postFormDataToApi,
1682
1706
  postJsonToApi as postJsonToApi4
1683
1707
  } from "@ai-sdk/provider-utils";
1684
1708
 
@@ -1717,11 +1741,13 @@ var modelMaxImagesPerCall = {
1717
1741
  "dall-e-3": 1,
1718
1742
  "dall-e-2": 10,
1719
1743
  "gpt-image-1": 10,
1720
- "gpt-image-1-mini": 10
1744
+ "gpt-image-1-mini": 10,
1745
+ "gpt-image-1.5": 10
1721
1746
  };
1722
1747
  var hasDefaultResponseFormat = /* @__PURE__ */ new Set([
1723
1748
  "gpt-image-1",
1724
- "gpt-image-1-mini"
1749
+ "gpt-image-1-mini",
1750
+ "gpt-image-1.5"
1725
1751
  ]);
1726
1752
 
1727
1753
  // src/image/openai-image-model.ts
@@ -1740,6 +1766,8 @@ var OpenAIImageModel = class {
1740
1766
  }
1741
1767
  async doGenerate({
1742
1768
  prompt,
1769
+ files,
1770
+ mask,
1743
1771
  n,
1744
1772
  size,
1745
1773
  aspectRatio,
@@ -1748,7 +1776,7 @@ var OpenAIImageModel = class {
1748
1776
  headers,
1749
1777
  abortSignal
1750
1778
  }) {
1751
- var _a, _b, _c, _d, _e, _f, _g;
1779
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1752
1780
  const warnings = [];
1753
1781
  if (aspectRatio != null) {
1754
1782
  warnings.push({
@@ -1761,6 +1789,72 @@ var OpenAIImageModel = class {
1761
1789
  warnings.push({ type: "unsupported", feature: "seed" });
1762
1790
  }
1763
1791
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1792
+ if (files != null) {
1793
+ const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi({
1794
+ url: this.config.url({
1795
+ path: "/images/edits",
1796
+ modelId: this.modelId
1797
+ }),
1798
+ headers: combineHeaders4(this.config.headers(), headers),
1799
+ formData: convertToFormData({
1800
+ model: this.modelId,
1801
+ prompt,
1802
+ image: await Promise.all(
1803
+ files.map(
1804
+ (file) => file.type === "file" ? new Blob(
1805
+ [
1806
+ file.data instanceof Uint8Array ? new Blob([file.data], {
1807
+ type: file.mediaType
1808
+ }) : new Blob([convertBase64ToUint8Array(file.data)], {
1809
+ type: file.mediaType
1810
+ })
1811
+ ],
1812
+ { type: file.mediaType }
1813
+ ) : downloadBlob(file.url)
1814
+ )
1815
+ ),
1816
+ mask: mask != null ? await fileToBlob(mask) : void 0,
1817
+ n,
1818
+ size,
1819
+ ...(_d = providerOptions.openai) != null ? _d : {}
1820
+ }),
1821
+ failedResponseHandler: openaiFailedResponseHandler,
1822
+ successfulResponseHandler: createJsonResponseHandler4(
1823
+ openaiImageResponseSchema
1824
+ ),
1825
+ abortSignal,
1826
+ fetch: this.config.fetch
1827
+ });
1828
+ return {
1829
+ images: response2.data.map((item) => item.b64_json),
1830
+ warnings,
1831
+ usage: response2.usage != null ? {
1832
+ inputTokens: (_e = response2.usage.input_tokens) != null ? _e : void 0,
1833
+ outputTokens: (_f = response2.usage.output_tokens) != null ? _f : void 0,
1834
+ totalTokens: (_g = response2.usage.total_tokens) != null ? _g : void 0
1835
+ } : void 0,
1836
+ response: {
1837
+ timestamp: currentDate,
1838
+ modelId: this.modelId,
1839
+ headers: responseHeaders2
1840
+ },
1841
+ providerMetadata: {
1842
+ openai: {
1843
+ images: response2.data.map((item) => {
1844
+ var _a2, _b2, _c2, _d2, _e2;
1845
+ return {
1846
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1847
+ created: (_a2 = response2.created) != null ? _a2 : void 0,
1848
+ size: (_b2 = response2.size) != null ? _b2 : void 0,
1849
+ quality: (_c2 = response2.quality) != null ? _c2 : void 0,
1850
+ background: (_d2 = response2.background) != null ? _d2 : void 0,
1851
+ outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0
1852
+ };
1853
+ })
1854
+ }
1855
+ }
1856
+ };
1857
+ }
1764
1858
  const { value: response, responseHeaders } = await postJsonToApi4({
1765
1859
  url: this.config.url({
1766
1860
  path: "/images/generations",
@@ -1772,7 +1866,7 @@ var OpenAIImageModel = class {
1772
1866
  prompt,
1773
1867
  n,
1774
1868
  size,
1775
- ...(_d = providerOptions.openai) != null ? _d : {},
1869
+ ...(_h = providerOptions.openai) != null ? _h : {},
1776
1870
  ...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
1777
1871
  },
1778
1872
  failedResponseHandler: openaiFailedResponseHandler,
@@ -1786,9 +1880,9 @@ var OpenAIImageModel = class {
1786
1880
  images: response.data.map((item) => item.b64_json),
1787
1881
  warnings,
1788
1882
  usage: response.usage != null ? {
1789
- inputTokens: (_e = response.usage.input_tokens) != null ? _e : void 0,
1790
- outputTokens: (_f = response.usage.output_tokens) != null ? _f : void 0,
1791
- totalTokens: (_g = response.usage.total_tokens) != null ? _g : void 0
1883
+ inputTokens: (_i = response.usage.input_tokens) != null ? _i : void 0,
1884
+ outputTokens: (_j = response.usage.output_tokens) != null ? _j : void 0,
1885
+ totalTokens: (_k = response.usage.total_tokens) != null ? _k : void 0
1792
1886
  } : void 0,
1793
1887
  response: {
1794
1888
  timestamp: currentDate,
@@ -1813,6 +1907,14 @@ var OpenAIImageModel = class {
1813
1907
  };
1814
1908
  }
1815
1909
  };
1910
+ async function fileToBlob(file) {
1911
+ if (!file) return void 0;
1912
+ if (file.type === "url") {
1913
+ return downloadBlob(file.url);
1914
+ }
1915
+ const data = file.data instanceof Uint8Array ? file.data : convertBase64ToUint8Array(file.data);
1916
+ return new Blob([data], { type: file.mediaType });
1917
+ }
1816
1918
 
1817
1919
  // src/tool/apply-patch.ts
1818
1920
  import {
@@ -3675,7 +3777,26 @@ var openaiResponsesProviderOptionsSchema = lazySchema18(
3675
3777
  * Defaults to `undefined`.
3676
3778
  * @see https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids
3677
3779
  */
3678
- user: z20.string().nullish()
3780
+ user: z20.string().nullish(),
3781
+ /**
3782
+ * Override the system message mode for this model.
3783
+ * - 'system': Use the 'system' role for system messages (default for most models)
3784
+ * - 'developer': Use the 'developer' role for system messages (used by reasoning models)
3785
+ * - 'remove': Remove system messages entirely
3786
+ *
3787
+ * If not specified, the mode is automatically determined based on the model.
3788
+ */
3789
+ systemMessageMode: z20.enum(["system", "developer", "remove"]).optional(),
3790
+ /**
3791
+ * Force treating this model as a reasoning model.
3792
+ *
3793
+ * This is useful for "stealth" reasoning models (e.g. via a custom baseURL)
3794
+ * where the model ID is not recognized by the SDK's allowlist.
3795
+ *
3796
+ * When enabled, the SDK applies reasoning-model parameter compatibility rules
3797
+ * and defaults `systemMessageMode` to `developer` unless overridden.
3798
+ */
3799
+ forceReasoning: z20.boolean().optional()
3679
3800
  })
3680
3801
  )
3681
3802
  );
@@ -3888,7 +4009,7 @@ var OpenAIResponsesLanguageModel = class {
3888
4009
  toolChoice,
3889
4010
  responseFormat
3890
4011
  }) {
3891
- var _a, _b, _c, _d;
4012
+ var _a, _b, _c, _d, _e, _f;
3892
4013
  const warnings = [];
3893
4014
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
3894
4015
  if (topK != null) {
@@ -3911,6 +4032,7 @@ var OpenAIResponsesLanguageModel = class {
3911
4032
  providerOptions,
3912
4033
  schema: openaiResponsesProviderOptionsSchema
3913
4034
  });
4035
+ const isReasoningModel = (_a = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a : modelCapabilities.isReasoningModel;
3914
4036
  if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
3915
4037
  warnings.push({
3916
4038
  type: "unsupported",
@@ -3935,15 +4057,15 @@ var OpenAIResponsesLanguageModel = class {
3935
4057
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3936
4058
  prompt,
3937
4059
  toolNameMapping,
3938
- systemMessageMode: modelCapabilities.systemMessageMode,
4060
+ systemMessageMode: (_b = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _b : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
3939
4061
  fileIdPrefixes: this.config.fileIdPrefixes,
3940
- store: (_a = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a : true,
4062
+ store: (_c = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _c : true,
3941
4063
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
3942
4064
  hasShellTool: hasOpenAITool("openai.shell"),
3943
4065
  hasApplyPatchTool: hasOpenAITool("openai.apply_patch")
3944
4066
  });
3945
4067
  warnings.push(...inputWarnings);
3946
- const strictJsonSchema = (_b = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _b : true;
4068
+ const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
3947
4069
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
3948
4070
  function addInclude(key) {
3949
4071
  if (include == null) {
@@ -3959,9 +4081,9 @@ var OpenAIResponsesLanguageModel = class {
3959
4081
  if (topLogprobs) {
3960
4082
  addInclude("message.output_text.logprobs");
3961
4083
  }
3962
- const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
4084
+ const webSearchToolName = (_e = tools == null ? void 0 : tools.find(
3963
4085
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
3964
- )) == null ? void 0 : _c.name;
4086
+ )) == null ? void 0 : _e.name;
3965
4087
  if (webSearchToolName) {
3966
4088
  addInclude("web_search_call.action.sources");
3967
4089
  }
@@ -3969,7 +4091,7 @@ var OpenAIResponsesLanguageModel = class {
3969
4091
  addInclude("code_interpreter_call.outputs");
3970
4092
  }
3971
4093
  const store = openaiOptions == null ? void 0 : openaiOptions.store;
3972
- if (store === false && modelCapabilities.isReasoningModel) {
4094
+ if (store === false && isReasoningModel) {
3973
4095
  addInclude("reasoning.encrypted_content");
3974
4096
  }
3975
4097
  const baseArgs = {
@@ -3984,7 +4106,7 @@ var OpenAIResponsesLanguageModel = class {
3984
4106
  format: responseFormat.schema != null ? {
3985
4107
  type: "json_schema",
3986
4108
  strict: strictJsonSchema,
3987
- name: (_d = responseFormat.name) != null ? _d : "response",
4109
+ name: (_f = responseFormat.name) != null ? _f : "response",
3988
4110
  description: responseFormat.description,
3989
4111
  schema: responseFormat.schema
3990
4112
  } : { type: "json_object" }
@@ -4011,7 +4133,7 @@ var OpenAIResponsesLanguageModel = class {
4011
4133
  top_logprobs: topLogprobs,
4012
4134
  truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
4013
4135
  // model-specific settings:
4014
- ...modelCapabilities.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
4136
+ ...isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
4015
4137
  reasoning: {
4016
4138
  ...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
4017
4139
  effort: openaiOptions.reasoningEffort
@@ -4022,7 +4144,7 @@ var OpenAIResponsesLanguageModel = class {
4022
4144
  }
4023
4145
  }
4024
4146
  };
4025
- if (modelCapabilities.isReasoningModel) {
4147
+ if (isReasoningModel) {
4026
4148
  if (!((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) === "none" && modelCapabilities.supportsNonReasoningParameters)) {
4027
4149
  if (baseArgs.temperature != null) {
4028
4150
  baseArgs.temperature = void 0;
@@ -5330,11 +5452,11 @@ var OpenAISpeechModel = class {
5330
5452
  // src/transcription/openai-transcription-model.ts
5331
5453
  import {
5332
5454
  combineHeaders as combineHeaders7,
5333
- convertBase64ToUint8Array,
5455
+ convertBase64ToUint8Array as convertBase64ToUint8Array2,
5334
5456
  createJsonResponseHandler as createJsonResponseHandler6,
5335
5457
  mediaTypeToExtension,
5336
5458
  parseProviderOptions as parseProviderOptions7,
5337
- postFormDataToApi
5459
+ postFormDataToApi as postFormDataToApi2
5338
5460
  } from "@ai-sdk/provider-utils";
5339
5461
 
5340
5462
  // src/transcription/openai-transcription-api.ts
@@ -5484,7 +5606,7 @@ var OpenAITranscriptionModel = class {
5484
5606
  schema: openAITranscriptionProviderOptions
5485
5607
  });
5486
5608
  const formData = new FormData();
5487
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
5609
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array2(audio)]);
5488
5610
  formData.append("model", this.modelId);
5489
5611
  const fileExtension = mediaTypeToExtension(mediaType);
5490
5612
  formData.append(
@@ -5531,7 +5653,7 @@ var OpenAITranscriptionModel = class {
5531
5653
  value: response,
5532
5654
  responseHeaders,
5533
5655
  rawValue: rawResponse
5534
- } = await postFormDataToApi({
5656
+ } = await postFormDataToApi2({
5535
5657
  url: this.config.url({
5536
5658
  path: "/audio/transcriptions",
5537
5659
  modelId: this.modelId
@@ -5571,7 +5693,7 @@ var OpenAITranscriptionModel = class {
5571
5693
  };
5572
5694
 
5573
5695
  // src/version.ts
5574
- var VERSION = true ? "3.0.0-beta.102" : "0.0.0-test";
5696
+ var VERSION = true ? "3.0.0-beta.105" : "0.0.0-test";
5575
5697
 
5576
5698
  // src/openai-provider.ts
5577
5699
  function createOpenAI(options = {}) {
@@ -5659,6 +5781,8 @@ function createOpenAI(options = {}) {
5659
5781
  provider.responses = createResponsesModel;
5660
5782
  provider.embedding = createEmbeddingModel;
5661
5783
  provider.embeddingModel = createEmbeddingModel;
5784
+ provider.textEmbedding = createEmbeddingModel;
5785
+ provider.textEmbeddingModel = createEmbeddingModel;
5662
5786
  provider.image = createImageModel;
5663
5787
  provider.imageModel = createImageModel;
5664
5788
  provider.transcription = createTranscriptionModel;