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
allow hashed token_id in /key/update endpoint (#24969)
Joe Reynaee3e848deddd
diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.pyindex c140de98191..e105d9b8586 100644--- a/litellm/proxy/management_endpoints/key_management_endpoints.py+++ b/litellm/proxy/management_endpoints/key_management_endpoints.py@@ -942,9 +942,9 @@ async def _check_team_key_limits(where={"team_id": team_table.team_id},)# Exclude the key being updated to avoid double-counting its limits.- # key.token is the SHA-256 hash stored in DB; data.key is the raw key string.+ # data.key may be a raw key (sk-...) or a pre-hashed token_id.if isinstance(data, UpdateKeyRequest):- hashed_key = hash_token(data.key)+ hashed_key = _hash_token_if_needed(data.key)keys = [key for key in keys if key.token != hashed_key]check_team_key_model_specific_limits(keys=keys,@@ -1101,9 +1101,9 @@ async def _check_org_key_limits(where={"organization_id": org_table.organization_id},)# Exclude the key being updated to avoid double-counting its limits.- # key.token is the SHA-256 hash stored in DB; data.key is the raw key string.+ # data.key may be a raw key (sk-...) or a pre-hashed token_id.if isinstance(data, UpdateKeyRequest):- hashed_key = hash_token(data.key)+ hashed_key = _hash_token_if_needed(data.key)keys = [key for key in keys if key.token != hashed_key]check_org_key_model_specific_limits(keys=keys,@@ -2157,7 +2157,7 @@ async def update_key_fn(# Delete - key from cache, since it's been updated!# key updated - a new model could have been added to this key. it should not block requests after this is doneawait _delete_cache_key_object(- hashed_token=hash_token(key),+ hashed_token=_hash_token_if_needed(key),user_api_key_cache=user_api_key_cache,proxy_logging_obj=proxy_logging_obj,)