posthog 7.4.2__py3-none-any.whl → 7.4.3__py3-none-any.whl

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.
@@ -773,9 +773,11 @@ def _parse_usage_model(
773
773
  for mapped_key, dataclass_key in field_mapping.items()
774
774
  },
775
775
  )
776
- # For Anthropic providers, LangChain reports input_tokens as the sum of input and cache read tokens.
776
+ # For Anthropic providers, LangChain reports input_tokens as the sum of all input tokens.
777
777
  # Our cost calculation expects them to be separate for Anthropic, so we subtract cache tokens.
778
- # For other providers (OpenAI, etc.), input_tokens already includes cache tokens as expected.
778
+ # Both cache_read and cache_write tokens should be subtracted since Anthropic's raw API
779
+ # reports input_tokens as tokens NOT read from or used to create a cache.
780
+ # For other providers (OpenAI, etc.), input_tokens already excludes cache tokens as expected.
779
781
  # Match logic consistent with plugin-server: exact match on provider OR substring match on model
780
782
  is_anthropic = False
781
783
  if provider and provider.lower() == "anthropic":
@@ -783,14 +785,14 @@ def _parse_usage_model(
783
785
  elif model and "anthropic" in model.lower():
784
786
  is_anthropic = True
785
787
 
786
- if (
787
- is_anthropic
788
- and normalized_usage.input_tokens
789
- and normalized_usage.cache_read_tokens
790
- ):
791
- normalized_usage.input_tokens = max(
792
- normalized_usage.input_tokens - normalized_usage.cache_read_tokens, 0
788
+ if is_anthropic and normalized_usage.input_tokens:
789
+ cache_tokens = (normalized_usage.cache_read_tokens or 0) + (
790
+ normalized_usage.cache_write_tokens or 0
793
791
  )
792
+ if cache_tokens > 0:
793
+ normalized_usage.input_tokens = max(
794
+ normalized_usage.input_tokens - cache_tokens, 0
795
+ )
794
796
  return normalized_usage
795
797
 
796
798
 
posthog/version.py CHANGED
@@ -1,4 +1,4 @@
1
- VERSION = "7.4.2"
1
+ VERSION = "7.4.3"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  print(VERSION, end="") # noqa: T201
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: posthog
3
- Version: 7.4.2
3
+ Version: 7.4.3
4
4
  Summary: Integrate PostHog into any python application.
5
5
  Home-page: https://github.com/posthog/posthog-python
6
6
  Author: Posthog
@@ -12,7 +12,7 @@ posthog/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  posthog/request.py,sha256=_WdffuI4BgRL9UvbEEi-4uxpFW3P4h7PRDpYM0lawVU,11817
13
13
  posthog/types.py,sha256=OxGHSmmhVYwA7ecmJXUznDCZ1c4gAGtERzSLSYlyQFM,11540
14
14
  posthog/utils.py,sha256=-0w-OLcCaoldkbBebPzQyBzLJSo9G9yBOg8NDVz7La8,16088
15
- posthog/version.py,sha256=wILBgX01Wb9Up8odCV0B-Lbipc7D9kykzm0x0Tku6Sw,87
15
+ posthog/version.py,sha256=vihsF6dgxiEGLdqc-3-Px5vakdaHbsft_z_qZYnNwQ8,87
16
16
  posthog/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  posthog/ai/sanitization.py,sha256=Dpx_5gKZfDS38KjmK1C0lvvjm9N8Pp_oIxusac888-g,6057
18
18
  posthog/ai/types.py,sha256=arX98hR1PIPeJ3vFikxTlACIh1xPp6aEUw1gBLcKoB0,3273
@@ -27,7 +27,7 @@ posthog/ai/gemini/gemini.py,sha256=RmmHriUoc2APrZtQiw63hJzBka0H-B3jYH29clxpciw,1
27
27
  posthog/ai/gemini/gemini_async.py,sha256=0UFk6ZHuG_F7dkw028BTyGybTpPvIKSNfw0yI_LciOM,15108
28
28
  posthog/ai/gemini/gemini_converter.py,sha256=JptTOV98s3V0jPKKHVRktze1i0RaSbkkOT0GLxkt2Gk,21801
29
29
  posthog/ai/langchain/__init__.py,sha256=9CqAwLynTGj3ASAR80C3PmdTdrYGmu99tz0JL-HPFgI,70
30
- posthog/ai/langchain/callbacks.py,sha256=EhjXTok2M2w5k5x9XFycl-bUMA1gdZx6FxHAY-HZ6bo,31367
30
+ posthog/ai/langchain/callbacks.py,sha256=ybSGvopspa9Ourk3CJxIioof_qTpTREiVkcaif4HMt4,31606
31
31
  posthog/ai/openai/__init__.py,sha256=u4OuUT7k1NgFj0TrxjuyegOg7a_UA8nAU6a-Hszr0OM,490
32
32
  posthog/ai/openai/openai.py,sha256=HWqd-uL0cRqwXVE06enRjqnxvIIxc-b_JLI41aimX6A,21324
33
33
  posthog/ai/openai/openai_async.py,sha256=b-65PQkIvYaA-AMOBorENL_wa3vh5c5pdSGPG29Nn2s,23655
@@ -50,8 +50,8 @@ posthog/test/test_request.py,sha256=vrZSayStAAcTr05h2ci3Y8qmKDIV2umBdiJqhr3NPp0,
50
50
  posthog/test/test_size_limited_dict.py,sha256=Wom7BkzpHmusHilZy0SV3PNzhw7ucuQgqrx86jf8euo,765
51
51
  posthog/test/test_types.py,sha256=csLuBiz6RMV36cpg9LVIor4Khq6MfjjGxYXodx5VttY,7586
52
52
  posthog/test/test_utils.py,sha256=YqAnXaMHxzEV_D3AHhs-RXnZYzdEN7kdIlpOT6Ti6t0,9714
53
- posthog-7.4.2.dist-info/licenses/LICENSE,sha256=wGf9JBotDkSygFj43m49oiKlFnpMnn97keiZKF-40vE,2450
54
- posthog-7.4.2.dist-info/METADATA,sha256=6UTUCuRCLrq3iS0kgqGtYDfClHPcctg_JnBEMKEDtzw,6010
55
- posthog-7.4.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
56
- posthog-7.4.2.dist-info/top_level.txt,sha256=7FBLsRjIUHVKQsXIhozuI3k-mun1tapp8iZO9EmUPEw,8
57
- posthog-7.4.2.dist-info/RECORD,,
53
+ posthog-7.4.3.dist-info/licenses/LICENSE,sha256=wGf9JBotDkSygFj43m49oiKlFnpMnn97keiZKF-40vE,2450
54
+ posthog-7.4.3.dist-info/METADATA,sha256=r43oVzca9cIo2QbKMGgHdd7OBSZaNMo5eeAd5KBVRp8,6010
55
+ posthog-7.4.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
56
+ posthog-7.4.3.dist-info/top_level.txt,sha256=7FBLsRjIUHVKQsXIhozuI3k-mun1tapp8iZO9EmUPEw,8
57
+ posthog-7.4.3.dist-info/RECORD,,