From 02134a07bb7f6664c5b88c4af09b103b394be974 Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Tue, 24 Feb 2026 19:43:55 -0800 Subject: [PATCH] Allow DB fallback for failure metadata enrichment lookups Accurate logging is more important than avoiding the rare DB lookup on the async failure path. Remove check_cache_only=True so lookups fall back to DB when the key/team is not in cache. Co-Authored-By: Claude Opus 4.6 --- litellm/proxy/hooks/proxy_track_cost_callback.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/litellm/proxy/hooks/proxy_track_cost_callback.py b/litellm/proxy/hooks/proxy_track_cost_callback.py index 214c92b6470..0734756d8ed 100644 --- a/litellm/proxy/hooks/proxy_track_cost_callback.py +++ b/litellm/proxy/hooks/proxy_track_cost_callback.py @@ -263,7 +263,7 @@ class _ProxyDBLogger(CustomLogger): async def _enrich_failure_metadata_with_key_info(metadata: dict) -> dict: """ Enriches failure spend log metadata by looking up the key object (and team object) - from cache when key fields are missing. + from cache/DB when key fields are missing. This handles two scenarios: 1. Auth errors (401): UserAPIKeyAuth is created with only api_key set, all other @@ -291,7 +291,6 @@ class _ProxyDBLogger(CustomLogger): prisma_client=prisma_client, user_api_key_cache=user_api_key_cache, proxy_logging_obj=proxy_logging_obj, - check_cache_only=True, ) if metadata.get("user_api_key_alias") is None: metadata["user_api_key_alias"] = key_obj.key_alias @@ -316,7 +315,6 @@ class _ProxyDBLogger(CustomLogger): prisma_client=prisma_client, user_api_key_cache=user_api_key_cache, proxy_logging_obj=proxy_logging_obj, - check_cache_only=True, ) if team_obj.team_alias is not None: metadata["user_api_key_team_alias"] = team_obj.team_alias