@ai-sdk/openai 3.0.27 → 3.0.29

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 3.0.29
4
+
5
+ ### Patch Changes
6
+
7
+ - e2ee705: feat: differentiate text vs image input tokens
8
+
9
+ ## 3.0.28
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [4024a3a]
14
+ - @ai-sdk/provider-utils@4.0.15
15
+
3
16
  ## 3.0.27
4
17
 
5
18
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1852,15 +1852,20 @@ var OpenAIImageModel = class {
1852
1852
  },
1853
1853
  providerMetadata: {
1854
1854
  openai: {
1855
- images: response2.data.map((item) => {
1856
- var _a2, _b2, _c2, _d2, _e2;
1855
+ images: response2.data.map((item, index) => {
1856
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1857
1857
  return {
1858
1858
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1859
1859
  created: (_a2 = response2.created) != null ? _a2 : void 0,
1860
1860
  size: (_b2 = response2.size) != null ? _b2 : void 0,
1861
1861
  quality: (_c2 = response2.quality) != null ? _c2 : void 0,
1862
1862
  background: (_d2 = response2.background) != null ? _d2 : void 0,
1863
- outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0
1863
+ outputFormat: (_e2 = response2.output_format) != null ? _e2 : void 0,
1864
+ ...distributeTokenDetails(
1865
+ (_f2 = response2.usage) == null ? void 0 : _f2.input_tokens_details,
1866
+ index,
1867
+ response2.data.length
1868
+ )
1864
1869
  };
1865
1870
  })
1866
1871
  }
@@ -1903,15 +1908,20 @@ var OpenAIImageModel = class {
1903
1908
  },
1904
1909
  providerMetadata: {
1905
1910
  openai: {
1906
- images: response.data.map((item) => {
1907
- var _a2, _b2, _c2, _d2, _e2;
1911
+ images: response.data.map((item, index) => {
1912
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1908
1913
  return {
1909
1914
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1910
1915
  created: (_a2 = response.created) != null ? _a2 : void 0,
1911
1916
  size: (_b2 = response.size) != null ? _b2 : void 0,
1912
1917
  quality: (_c2 = response.quality) != null ? _c2 : void 0,
1913
1918
  background: (_d2 = response.background) != null ? _d2 : void 0,
1914
- outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0
1919
+ outputFormat: (_e2 = response.output_format) != null ? _e2 : void 0,
1920
+ ...distributeTokenDetails(
1921
+ (_f2 = response.usage) == null ? void 0 : _f2.input_tokens_details,
1922
+ index,
1923
+ response.data.length
1924
+ )
1915
1925
  };
1916
1926
  })
1917
1927
  }
@@ -1919,6 +1929,23 @@ var OpenAIImageModel = class {
1919
1929
  };
1920
1930
  }
1921
1931
  };
1932
+ function distributeTokenDetails(details, index, total) {
1933
+ if (details == null) {
1934
+ return {};
1935
+ }
1936
+ const result = {};
1937
+ if (details.image_tokens != null) {
1938
+ const base = Math.floor(details.image_tokens / total);
1939
+ const remainder = details.image_tokens - base * (total - 1);
1940
+ result.imageTokens = index === total - 1 ? remainder : base;
1941
+ }
1942
+ if (details.text_tokens != null) {
1943
+ const base = Math.floor(details.text_tokens / total);
1944
+ const remainder = details.text_tokens - base * (total - 1);
1945
+ result.textTokens = index === total - 1 ? remainder : base;
1946
+ }
1947
+ return result;
1948
+ }
1922
1949
  async function fileToBlob(file) {
1923
1950
  if (!file) return void 0;
1924
1951
  if (file.type === "url") {
@@ -5786,7 +5813,7 @@ var OpenAITranscriptionModel = class {
5786
5813
  };
5787
5814
 
5788
5815
  // src/version.ts
5789
- var VERSION = true ? "3.0.27" : "0.0.0-test";
5816
+ var VERSION = true ? "3.0.29" : "0.0.0-test";
5790
5817
 
5791
5818
  // src/openai-provider.ts
5792
5819
  function createOpenAI(options = {}) {