From 4eeb70009abc5077495a1b2fa9535143588bdf22 Mon Sep 17 00:00:00 2001 From: Srivatsa03 <180591884+Srivatsa03@users.noreply.github.com> Date: Sun, 11 Oct 2026 22:40:10 -0500 Subject: [PATCH] fix(proxy): tolerate a SpendLogsPayload without total_tokens Reading payload["total_tokens"] unconditionally aborted _batch_database_updates with a KeyError when a (test or partial) payload omits the key, dropping the rest of the batch. Guard the typed index with a membership check so a missing count falls back to 0, staying tolerant like the old .get while keeping the read type-clean. --- litellm/proxy/db/db_spend_update_writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/proxy/db/db_spend_update_writer.py b/litellm/proxy/db/db_spend_update_writer.py index 98c788b6fc4..a1838c3d4d1 100644 --- a/litellm/proxy/db/db_spend_update_writer.py +++ b/litellm/proxy/db/db_spend_update_writer.py @@ -1066,7 +1066,7 @@ class DBSpendUpdateWriter: team_id=team_id, user_id=user_id, prisma_client=prisma_client, - tokens=payload["total_tokens"], + tokens=payload["total_tokens"] if "total_tokens" in payload else 0, ) except Exception: verbose_proxy_logger.debug(