| 205 | return CheckResult(allowed=True) |
| 206 | |
| 207 | def record(self, amount: float, model: str | None = None, action: str | None = None) -> None: |
| 208 | if amount < 0: |
| 209 | raise ValueError("Amount must be non-negative") |
| 210 | self._history.append(SpendRecord( |
| 211 | timestamp=self._now(), amount=amount, model=model, action=action, |
| 212 | )) |
| 213 | self._session_spent += amount |
| 214 | self._session_calls += 1 |
| 215 | self._cleanup() |
| 216 | self._save() |
| 217 | |
| 218 | def get_spending(self, window: Literal["hourly", "daily", "session"]) -> float: |
| 219 | now = self._now() |