From f949f1735b0654ded233a71b888f7c9bbddce9bd Mon Sep 17 00:00:00 2001 From: Srivatsa03 <180591884+Srivatsa03@users.noreply.github.com> Date: Sun, 11 Oct 2026 22:48:36 -0500 Subject: [PATCH] fix(proxy): read total_tokens with .get default, not an in-check ternary The membership-guarded index tripped SIM401 (prefer dict.get), but a plain .get on the SpendLogsPayload TypedDict trips basedpyright's unknown-member rule. Use .get with a 0 default (tolerant and SIM401-clean) and suppress just the one overload-unknown diagnostic with a reason. --- litellm/proxy/db/db_spend_update_writer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/db/db_spend_update_writer.py b/litellm/proxy/db/db_spend_update_writer.py index a1838c3d4d1..a1769946680 100644 --- a/litellm/proxy/db/db_spend_update_writer.py +++ b/litellm/proxy/db/db_spend_update_writer.py @@ -1060,13 +1060,16 @@ class DBSpendUpdateWriter: traceback.format_exc(), ) + team_tokens: Final = payload.get( # pyright: ignore[reportUnknownMemberType] # SpendLogsPayload.get overload is partially unknown; total_tokens is a required int + "total_tokens", 0 + ) try: await self._update_team_db( response_cost=response_cost, team_id=team_id, user_id=user_id, prisma_client=prisma_client, - tokens=payload["total_tokens"] if "total_tokens" in payload else 0, + tokens=team_tokens, ) except Exception: verbose_proxy_logger.debug(