Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

resolved greptile issue related to regeneration persistence and exception handling

shivamfa9585371890
diff --git a/litellm/proxy/management_endpoints/common_daily_activity.py b/litellm/proxy/management_endpoints/common_daily_activity.py
index 79d80abf272..e5df2f82f69 100644
--- a/litellm/proxy/management_endpoints/common_daily_activity.py
+++ b/litellm/proxy/management_endpoints/common_daily_activity.py
@@ -357,9 +357,11 @@ async def get_api_key_metadata(
"key_alias": k.key_alias,
"team_id": k.team_id,
}
- except Exception:
- verbose_proxy_logger.debug(
- "Failed to fetch deleted key metadata for missing keys"
+ except Exception as e:
+ verbose_proxy_logger.warning(
+ "Failed to fetch deleted key metadata for %d missing keys: %s",
+ len(missing_keys),
+ e,
)
return result
diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py
index 264dff5aa54..48e0c32880b 100644
--- a/litellm/proxy/management_endpoints/key_management_endpoints.py
+++ b/litellm/proxy/management_endpoints/key_management_endpoints.py
@@ -3313,19 +3313,16 @@ async def regenerate_key_fn(
verbose_proxy_logger.debug("key_in_db: %s", _key_in_db)
- # Save the old key record to deleted table before regeneration
- # This preserves key_alias and team_id metadata for historical spend records
- try:
- await _persist_deleted_verification_tokens(
- keys=[_key_in_db],
- prisma_client=prisma_client,
- user_api_key_dict=user_api_key_dict,
- litellm_changed_by=litellm_changed_by,
- )
- except Exception:
- verbose_proxy_logger.debug(
- "Failed to persist old key record to deleted table during regeneration"
- )
+ # Save the old key record to deleted table before regeneration.
+ # This preserves key_alias and team_id metadata for historical spend records.
+ # If this fails, abort the regeneration to avoid permanently losing the
+ # old hash→metadata mapping.
+ await _persist_deleted_verification_tokens(
+ keys=[_key_in_db],
+ prisma_client=prisma_client,
+ user_api_key_dict=user_api_key_dict,
+ litellm_changed_by=litellm_changed_by,
+ )
new_token = get_new_token(data=data)