Coverage for src / harness_utils / models / usage.py: 85%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.2, created at 2026-01-31 13:47 -0600

1"""Token usage and cost tracking.""" 

2 

3from dataclasses import dataclass, field 

4 

5 

6@dataclass 

7class CacheUsage: 

8 """Cache token usage information.""" 

9 

10 read: int = 0 # Cached input tokens (discounted) 

11 write: int = 0 # Cache creation tokens (premium) 

12 

13 

14@dataclass 

15class Usage: 

16 """Token usage information for a turn.""" 

17 

18 input: int = 0 # Input tokens consumed 

19 output: int = 0 # Output tokens generated 

20 reasoning: int = 0 # Extended thinking tokens 

21 cache: CacheUsage = field(default_factory=CacheUsage) 

22 

23 @property 

24 def total_input(self) -> int: 

25 """Total input tokens including cache reads.""" 

26 return self.input + self.cache.read 

27 

28 @property 

29 def total_output(self) -> int: 

30 """Total output tokens including reasoning.""" 

31 return self.output + self.reasoning 

32 

33 @property 

34 def total(self) -> int: 

35 """Total tokens across all categories.""" 

36 return self.total_input + self.total_output