@ai-sdk/openai 2.0.91 → 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,11 @@
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
+
3
9
  ## 2.0.91
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1745,42 +1745,50 @@ var OpenAIImageModel = class {
1745
1745
  },
1746
1746
  providerMetadata: {
1747
1747
  openai: {
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
- })
1748
+ images: response.data.map((item, index) => ({
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
+ ...distributeTokenDetails(
1756
+ response.usage,
1757
+ index,
1758
+ response.data.length
1759
+ )
1760
+ }))
1764
1761
  }
1765
1762
  }
1766
1763
  };
1767
1764
  }
1768
1765
  };
1769
- function distributeTokenDetails(details, index, total) {
1770
- if (details == null) {
1766
+ function distributeTokenDetails(usage, index, total) {
1767
+ if (usage == null) {
1771
1768
  return {};
1772
1769
  }
1773
1770
  const result = {};
1774
- if (details.image_tokens != null) {
1771
+ const details = usage.input_tokens_details;
1772
+ if ((details == null ? void 0 : details.image_tokens) != null) {
1775
1773
  const base = Math.floor(details.image_tokens / total);
1776
1774
  const remainder = details.image_tokens - base * (total - 1);
1777
1775
  result.imageTokens = index === total - 1 ? remainder : base;
1778
1776
  }
1779
- if (details.text_tokens != null) {
1777
+ if ((details == null ? void 0 : details.text_tokens) != null) {
1780
1778
  const base = Math.floor(details.text_tokens / total);
1781
1779
  const remainder = details.text_tokens - base * (total - 1);
1782
1780
  result.textTokens = index === total - 1 ? remainder : base;
1783
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
+ }
1784
1792
  return result;
1785
1793
  }
1786
1794
 
@@ -4590,7 +4598,7 @@ var OpenAITranscriptionModel = class {
4590
4598
  };
4591
4599
 
4592
4600
  // src/version.ts
4593
- var VERSION = true ? "2.0.91" : "0.0.0-test";
4601
+ var VERSION = true ? "2.0.92" : "0.0.0-test";
4594
4602
 
4595
4603
  // src/openai-provider.ts
4596
4604
  function createOpenAI(options = {}) {