Skip to content

Commit 8aa26e0

Browse files
committed
fix: things can be None
1 parent 7413f88 commit 8aa26e0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

posthog/ai/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ def call_llm_and_track_usage(
186186
if tool_calls:
187187
event_properties["$ai_tools"] = with_privacy_mode(ph_client, posthog_privacy_mode, tool_calls)
188188

189-
if usage.get("cache_read_input_tokens", 0) > 0:
189+
if usage.get("cache_read_input_tokens") is not None and usage.get("cache_read_input_tokens", 0) > 0:
190190
event_properties["$ai_cache_read_input_tokens"] = usage.get("cache_read_input_tokens", 0)
191191

192-
if usage.get("cache_creation_input_tokens", 0) > 0:
192+
if usage.get("cache_creation_input_tokens") is not None and usage.get("cache_creation_input_tokens", 0) > 0:
193193
event_properties["$ai_cache_creation_input_tokens"] = usage.get("cache_creation_input_tokens", 0)
194194

195195
if posthog_distinct_id is None:
@@ -272,10 +272,10 @@ async def call_llm_and_track_usage_async(
272272
if tool_calls:
273273
event_properties["$ai_tools"] = with_privacy_mode(ph_client, posthog_privacy_mode, tool_calls)
274274

275-
if usage.get("cache_read_input_tokens", 0) > 0:
275+
if usage.get("cache_read_input_tokens") is not None and usage.get("cache_read_input_tokens", 0) > 0:
276276
event_properties["$ai_cache_read_input_tokens"] = usage.get("cache_read_input_tokens", 0)
277277

278-
if usage.get("cache_creation_input_tokens", 0) > 0:
278+
if usage.get("cache_creation_input_tokens") is not None and usage.get("cache_creation_input_tokens", 0) > 0:
279279
event_properties["$ai_cache_creation_input_tokens"] = usage.get("cache_creation_input_tokens", 0)
280280

281281
if posthog_distinct_id is None:

0 commit comments

Comments
 (0)