From 9e2e2eb6dc6e32ef2e6725469f99182b53a5a564 Mon Sep 17 00:00:00 2001 From: Mrinal Chanshetty Date: Mon, 19 Oct 2026 15:38:23 -0700 Subject: [PATCH] fix(proxy): satisfy type gates for team-attributed tag spend DailyTagSpendTransaction.team_id is ReadOnly (LIT012), since nothing writes it after the transaction is built. The two payload.get("team_id") reads keep .get rather than indexing and carry the file's existing reportUnknownMemberType suppression for TypedDict.get. The caller swallows exceptions at debug level, so indexing would silently drop a request's tag spend whenever a payload lacked team_id, instead of recording it as unattributed. LIT-8516 --- litellm/proxy/_types.py | 2 +- litellm/proxy/db/db_spend_update_writer.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index 5d09280dc85..11ef5d67a4b 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -5162,7 +5162,7 @@ class DailyTagSpendTransaction(BaseDailySpendTransaction): # "" when the request had no team. Not required: entries queued by a pod running the # previous release, or replayed from the Redis buffer across an upgrade, carry no such key, # and the upsert reads a missing value as "". - team_id: NotRequired[str] + team_id: ReadOnly[NotRequired[str]] class DailyAgentSpendTransaction(BaseDailySpendTransaction): diff --git a/litellm/proxy/db/db_spend_update_writer.py b/litellm/proxy/db/db_spend_update_writer.py index 70106ab6ba7..614870ad133 100644 --- a/litellm/proxy/db/db_spend_update_writer.py +++ b/litellm/proxy/db/db_spend_update_writer.py @@ -918,7 +918,7 @@ class DBSpendUpdateWriter: model_group=base.get("model_group"), endpoint=base.get("endpoint"), mcp_namespaced_tool_name=base.get("mcp_namespaced_tool_name"), - team_id=payload.get("team_id") or "", + team_id=payload.get("team_id") or "", # pyright: ignore[reportUnknownMemberType] # TypedDict.get overloads carry Any defaults targets=tuple( DailyBaselineTarget(entity=entity, entity_id=identity) for entity, values in bases @@ -3035,7 +3035,9 @@ class DBSpendUpdateWriter: return request_tags: Final = daily_spend_entity_ids(payload, "tag") - team_id: Final = payload.get("team_id") or "" + # .get, not indexing: the caller swallows exceptions at debug level, so a payload without + # team_id must still record its tag spend (as unattributed) rather than drop it silently. + team_id: Final = payload.get("team_id") or "" # pyright: ignore[reportUnknownMemberType] # TypedDict.get overloads carry Any defaults for tag in request_tags: if tag is None: continue