From 177c1a87dda588bd91c792c35a24a7660715e760 Mon Sep 17 00:00:00 2001 From: Roberto Date: Tue, 12 May 2026 07:30:33 +0200 Subject: [PATCH] feat(api): MonthlyTokenUsage model + AgentRunLog.tokens_used Co-Authored-By: Claude Sonnet 4.6 --- app/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/models.py b/app/models.py index b00cec9..a2031d8 100644 --- a/app/models.py +++ b/app/models.py @@ -243,6 +243,7 @@ class AgentRunLog(Base): status: Mapped[str] = mapped_column(AgentStatusEnum, nullable=False, default="running") items_processed: Mapped[int] = mapped_column(Integer, nullable=False, default=0) items_created: Mapped[int] = mapped_column(Integer, nullable=False, default=0) + tokens_used: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default="0") errors: Mapped[list | None] = mapped_column(JSON, nullable=True) started_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False, server_default=func.now() @@ -263,6 +264,17 @@ class AgentRunLog(Base): ) +class MonthlyTokenUsage(Base): + __tablename__ = "monthly_token_usage" + + user_id: Mapped[str] = mapped_column( + Uuid(as_uuid=False), ForeignKey("users.id", ondelete="CASCADE"), primary_key=True + ) + year_month: Mapped[str] = mapped_column(String(7), primary_key=True) # 'YYYY-MM' + feature: Mapped[str] = mapped_column(String(64), primary_key=True) + tokens_used: Mapped[int] = mapped_column(Integer, nullable=False, default=0, server_default="0") + + # ── Memory models ─────────────────────────────────────────────────────────────