@crewdle/mist-connector-openai 1.0.23 → 1.0.24

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.
@@ -246,11 +246,19 @@ Only output the missing remainder. Do not restart or re-open tags already emitte
246
246
  /**
247
247
  * OpenAI reports cached prompt tokens inside the input token total; split
248
248
  * them out so billing can rate the cached share via the model's tokenRates.
249
+ * Image models (gpt-image) also detail text vs image input tokens — bucket
250
+ * the text share so docs whose base input SKU is the image price can rate
251
+ * it (e.g. gpt-image-2 `text: 0.625`). Unrated buckets bill at base, so
252
+ * this is a no-op for plain text models. cached can overlap the modality
253
+ * details, hence the clamp.
249
254
  */
250
255
  usageBuckets(usage) {
251
256
  const total = usage?.input_tokens ?? 0;
252
- const cached = usage?.input_tokens_details?.cached_tokens ?? 0;
253
- return { input: { base: total - cached, cached }, output: { base: usage?.output_tokens ?? 0 } };
257
+ const details = usage?.input_tokens_details ?? {};
258
+ const cached = details.cached_tokens ?? 0;
259
+ const text = details.text_tokens ?? 0;
260
+ const audio = details.audio_tokens ?? 0;
261
+ return { input: { base: Math.max(0, total - cached - text - audio), cached, text, audio }, output: { base: usage?.output_tokens ?? 0 } };
254
262
  }
255
263
  /**
256
264
  * whisper-1 reports no token usage; verbose_json carries the audio duration
@@ -11,6 +11,11 @@ export declare class OpenAIGenerativeAIWorkerConnector implements IGenerativeAIW
11
11
  /**
12
12
  * OpenAI reports cached prompt tokens inside the input token total; split
13
13
  * them out so billing can rate the cached share via the model's tokenRates.
14
+ * Image models (gpt-image) also detail text vs image input tokens — bucket
15
+ * the text share so docs whose base input SKU is the image price can rate
16
+ * it (e.g. gpt-image-2 `text: 0.625`). Unrated buckets bill at base, so
17
+ * this is a no-op for plain text models. cached can overlap the modality
18
+ * details, hence the clamp.
14
19
  */
15
20
  private usageBuckets;
16
21
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewdle/mist-connector-openai",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",