@ai-sdk/openai 2.0.90 → 2.0.91

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,11 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.91
4
+
5
+ ### Patch Changes
6
+
7
+ - 6a0adb7: feat: differentiate text vs image input tokens
8
+
3
9
  ## 2.0.90
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1745,19 +1745,44 @@ var OpenAIImageModel = class {
1745
1745
  },
1746
1746
  providerMetadata: {
1747
1747
  openai: {
1748
- images: response.data.map((item) => ({
1749
- ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1750
- ...response.created != null ? { created: response.created } : {},
1751
- ...response.size != null ? { size: response.size } : {},
1752
- ...response.quality != null ? { quality: response.quality } : {},
1753
- ...response.background != null ? { background: response.background } : {},
1754
- ...response.output_format != null ? { outputFormat: response.output_format } : {}
1755
- }))
1748
+ images: response.data.map((item, index) => {
1749
+ var _a2;
1750
+ return {
1751
+ ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1752
+ ...response.created != null ? { created: response.created } : {},
1753
+ ...response.size != null ? { size: response.size } : {},
1754
+ ...response.quality != null ? { quality: response.quality } : {},
1755
+ ...response.background != null ? { background: response.background } : {},
1756
+ ...response.output_format != null ? { outputFormat: response.output_format } : {},
1757
+ ...distributeTokenDetails(
1758
+ (_a2 = response.usage) == null ? void 0 : _a2.input_tokens_details,
1759
+ index,
1760
+ response.data.length
1761
+ )
1762
+ };
1763
+ })
1756
1764
  }
1757
1765
  }
1758
1766
  };
1759
1767
  }
1760
1768
  };
1769
+ function distributeTokenDetails(details, index, total) {
1770
+ if (details == null) {
1771
+ return {};
1772
+ }
1773
+ const result = {};
1774
+ if (details.image_tokens != null) {
1775
+ const base = Math.floor(details.image_tokens / total);
1776
+ const remainder = details.image_tokens - base * (total - 1);
1777
+ result.imageTokens = index === total - 1 ? remainder : base;
1778
+ }
1779
+ if (details.text_tokens != null) {
1780
+ const base = Math.floor(details.text_tokens / total);
1781
+ const remainder = details.text_tokens - base * (total - 1);
1782
+ result.textTokens = index === total - 1 ? remainder : base;
1783
+ }
1784
+ return result;
1785
+ }
1761
1786
 
1762
1787
  // src/tool/code-interpreter.ts
1763
1788
  var import_provider_utils14 = require("@ai-sdk/provider-utils");
@@ -4565,7 +4590,7 @@ var OpenAITranscriptionModel = class {
4565
4590
  };
4566
4591
 
4567
4592
  // src/version.ts
4568
- var VERSION = true ? "2.0.90" : "0.0.0-test";
4593
+ var VERSION = true ? "2.0.91" : "0.0.0-test";
4569
4594
 
4570
4595
  // src/openai-provider.ts
4571
4596
  function createOpenAI(options = {}) {