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