Coverage for src / harnessutils / models / usage.py: 100%
20 statements
« prev ^ index » next coverage.py v7.13.2, created at 2026-02-12 22:40 -0600
« prev ^ index » next coverage.py v7.13.2, created at 2026-02-12 22:40 -0600
1"""Token usage and cost tracking."""
3from dataclasses import dataclass, field
6@dataclass
7class CacheUsage:
8 """Cache token usage information."""
10 read: int = 0 # Cached input tokens (discounted)
11 write: int = 0 # Cache creation tokens (premium)
14@dataclass
15class Usage:
16 """Token usage information for a turn."""
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)
23 @property
24 def total_input(self) -> int:
25 """Total input tokens including cache reads."""
26 return self.input + self.cache.read
28 @property
29 def total_output(self) -> int:
30 """Total output tokens including reasoning."""
31 return self.output + self.reasoning
33 @property
34 def total(self) -> int:
35 """Total tokens across all categories."""
36 return self.total_input + self.total_output