mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
Replace assertions with simple if conditions. assertions raise an exception which are not great for performance (specifically repeated throws). Logic remains the same and the tests are still passing
This commit is contained in:
parent
30885467ff
commit
d58f657fa2
1 changed files with 10 additions and 8 deletions
|
|
@ -1115,9 +1115,7 @@ async def _user_api_key_auth_builder( # noqa: PLR0915
|
|||
is_master_key_valid = False
|
||||
|
||||
## VALIDATE MASTER KEY ##
|
||||
try:
|
||||
assert isinstance(master_key, str)
|
||||
except Exception:
|
||||
if not isinstance(master_key, str):
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail={
|
||||
|
|
@ -1183,11 +1181,15 @@ async def _user_api_key_auth_builder( # noqa: PLR0915
|
|||
if len(api_key) > 8
|
||||
else "****"
|
||||
)
|
||||
assert api_key.startswith(
|
||||
"sk-"
|
||||
), "LiteLLM Virtual Key expected. Received={}, expected to start with 'sk-'.".format(
|
||||
_masked_key
|
||||
) # prevent token hashes from being used
|
||||
if not api_key.startswith("sk-"):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail=(
|
||||
"LiteLLM Virtual Key expected. Received={}, expected to start with 'sk-'.".format(
|
||||
_masked_key
|
||||
)
|
||||
),
|
||||
) # prevent token hashes from being used
|
||||
else:
|
||||
verbose_logger.warning(
|
||||
"litellm.proxy.proxy_server.user_api_key_auth(): Warning - Key is not a string. Got type={}".format(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue