@ai-sdk/openai 2.0.90 → 2.0.92

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,17 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.92
4
+
5
+ ### Patch Changes
6
+
7
+ - c680a01: fix(openai): add changeset and tests for per-image usage metadata
8
+
9
+ ## 2.0.91
10
+
11
+ ### Patch Changes
12
+
13
+ - 6a0adb7: feat: differentiate text vs image input tokens
14
+
3
15
  ## 2.0.90
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1745,19 +1745,52 @@ var OpenAIImageModel = class {
1745
1745
  },
1746
1746
  providerMetadata: {
1747
1747
  openai: {
1748
- images: response.data.map((item) => ({
1748
+ images: response.data.map((item, index) => ({
1749
1749
  ...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
1750
1750
  ...response.created != null ? { created: response.created } : {},
1751
1751
  ...response.size != null ? { size: response.size } : {},
1752
1752
  ...response.quality != null ? { quality: response.quality } : {},
1753
1753
  ...response.background != null ? { background: response.background } : {},
1754
- ...response.output_format != null ? { outputFormat: response.output_format } : {}
1754
+ ...response.output_format != null ? { outputFormat: response.output_format } : {},
1755
+ ...distributeTokenDetails(
1756
+ response.usage,
1757
+ index,
1758
+ response.data.length
1759
+ )
1755
1760
  }))
1756
1761
  }
1757
1762
  }
1758
1763
  };
1759
1764
  }
1760
1765
  };
1766
+ function distributeTokenDetails(usage, index, total) {
1767
+ if (usage == null) {
1768
+ return {};
1769
+ }
1770
+ const result = {};
1771
+ const details = usage.input_tokens_details;
1772
+ if ((details == null ? void 0 : details.image_tokens) != null) {
1773
+ const base = Math.floor(details.image_tokens / total);
1774
+ const remainder = details.image_tokens - base * (total - 1);
1775
+ result.imageTokens = index === total - 1 ? remainder : base;
1776
+ }
1777
+ if ((details == null ? void 0 : details.text_tokens) != null) {
1778
+ const base = Math.floor(details.text_tokens / total);
1779
+ const remainder = details.text_tokens - base * (total - 1);
1780
+ result.textTokens = index === total - 1 ? remainder : base;
1781
+ }
1782
+ if (usage.input_tokens != null) {
1783
+ const base = Math.floor(usage.input_tokens / total);
1784
+ const remainder = usage.input_tokens - base * (total - 1);
1785
+ result.inputTokens = index === total - 1 ? remainder : base;
1786
+ }
1787
+ if (usage.output_tokens != null) {
1788
+ const base = Math.floor(usage.output_tokens / total);
1789
+ const remainder = usage.output_tokens - base * (total - 1);
1790
+ result.outputTokens = index === total - 1 ? remainder : base;
1791
+ }
1792
+ return result;
1793
+ }
1761
1794
 
1762
1795
  // src/tool/code-interpreter.ts
1763
1796
  var import_provider_utils14 = require("@ai-sdk/provider-utils");
@@ -4565,7 +4598,7 @@ var OpenAITranscriptionModel = class {
4565
4598
  };
4566
4599
 
4567
4600
  // src/version.ts
4568
- var VERSION = true ? "2.0.90" : "0.0.0-test";
4601
+ var VERSION = true ? "2.0.92" : "0.0.0-test";
4569
4602
 
4570
4603
  // src/openai-provider.ts
4571
4604
  function createOpenAI(options = {}) {