@posthog/ai 7.9.2 → 7.9.3

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/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { uuidv7 } from '@posthog/core';
5
5
  import AnthropicOriginal from '@anthropic-ai/sdk';
6
6
  import { GoogleGenAI } from '@google/genai';
7
7
 
8
- var version = "7.9.2";
8
+ var version = "7.9.3";
9
9
 
10
10
  // Type guards for safer type checking
11
11
  const isString = value => {
@@ -224,6 +224,13 @@ const sanitizeLangChain = data => {
224
224
  return processMessages(data, sanitizeLangChainImage);
225
225
  };
226
226
 
227
+ const TOKEN_PROPERTY_KEYS = new Set(['$ai_input_tokens', '$ai_output_tokens', '$ai_cache_read_input_tokens', '$ai_cache_creation_input_tokens', '$ai_total_tokens', '$ai_reasoning_tokens']);
228
+ function getTokensSource(posthogProperties) {
229
+ if (posthogProperties && Object.keys(posthogProperties).some(key => TOKEN_PROPERTY_KEYS.has(key))) {
230
+ return 'passthrough';
231
+ }
232
+ return 'sdk';
233
+ }
227
234
  // limit large outputs by truncating to 200kb (approx 200k bytes)
228
235
  const MAX_OUTPUT_SIZE = 200000;
229
236
  const STRING_FORMAT = 'utf8';
@@ -803,6 +810,7 @@ const sendEventToPosthog = async ({
803
810
  $ai_trace_id: traceId,
804
811
  $ai_base_url: baseURL,
805
812
  ...params.posthogProperties,
813
+ $ai_tokens_source: getTokensSource(params.posthogProperties),
806
814
  ...(distinctId ? {} : {
807
815
  $process_person_profile: false
808
816
  }),