@@ -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