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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge remote-tracking branch 'origin/main' into litellm_unified_key_policy_hook
mateo-berri1f2d050386fa
diff --cc litellm/proxy/management_endpoints/key_management_endpoints.pyindex 8aaaba09e22,339933807f1..e5450785117--- a/litellm/proxy/management_endpoints/key_management_endpoints.py+++ b/litellm/proxy/management_endpoints/key_management_endpoints.py@@@ -2737,18 -2599,10 +2761,20 @@@ async def _process_single_key_update)# Prepare update data- non_default_values = await prepare_key_update_data(data=update_key_request, existing_key_row=existing_key_row)+ non_default_values = await prepare_key_update_data(+ data=update_key_request, existing_key_row=existing_key_row, prisma_client=prisma_client, llm_router=llm_router+ )+ await _enforce_custom_key_policy(+ hook=user_custom_key_policy,+ build_policy_request=lambda: _update_policy_request(+ operation="update",+ existing_key_row=existing_key_row,+ non_default_values=non_default_values,+ request=update_key_request,+ ),+ )+# Update key in databaseif prisma_client is None:raise HTTPException(@@@ -5312,12 -5165,11 +5350,14 @@@ async def _execute_virtual_key_regeneranon_default_values = {}if data is not None:+ update_request: Final = _regenerate_request_as_update_request(key=hashed_api_key, data=data)+ if update_request is not None:+ await _enforce_custom_key_update_policy(hook=_custom_key_update_hook(proxy_server), data=update_request)# Enforce upperbound key params on regenerate (don't fill defaults)_enforce_upperbound_key_params(data, fill_defaults=False)- non_default_values = await prepare_key_update_data(data=data, existing_key_row=key_in_db)+ non_default_values = await prepare_key_update_data(+ data=data, existing_key_row=key_in_db, prisma_client=prisma_client, llm_router=llm_router+ )# Only validate key_alias format if it's actually being changednew_key_alias: Final = non_default_values.get("key_alias")if new_key_alias != key_in_db.key_alias:@@@ -5652,8 -5484,20 +5693,9 @@@ async def regenerate_key_fnif litellm_changed_by is not None and not isinstance(litellm_changed_by, str):litellm_changed_by = None- # 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,- )-return await _execute_virtual_key_regeneration(prisma_client=prisma_client,+ llm_router=llm_router,key_in_db=_key_in_db,hashed_api_key=hashed_api_key,key=key,diff --cc tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.pyindex df58424095f,43cbd77ed0c..c590a24203c--- a/tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py+++ b/tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py@@@ -1,6 -1,5 +1,7 @@@+from collections.abc import Mapping+from contextlib import ExitStackfrom typing import Final+ from types import SimpleNamespaceimport jsonfrom datetime import datetime, timedelta, timezone@@@ -19,9 -18,9 +20,10 @@@ from litellm.proxy._types importGenerateKeyRequest,NewUserRequest,LiteLLM_BudgetTable,+ LiteLLM_ObjectPermissionBase,LiteLLM_OrganizationTable,LiteLLM_ProjectTableCachedObj,+ LiteLLM_TeamTable,LiteLLM_TeamTableCachedObj,LiteLLM_UserTable,LiteLLM_VerificationToken,