mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
(fix) proxy - improve invalid models exception msg
This commit is contained in:
parent
7d9c953dee
commit
c15adf4fe4
1 changed files with 5 additions and 6 deletions
|
@ -297,10 +297,7 @@ async def user_api_key_auth(
|
||||||
# Token exists, now check expiration.
|
# Token exists, now check expiration.
|
||||||
if valid_token.expires is not None:
|
if valid_token.expires is not None:
|
||||||
expiry_time = datetime.fromisoformat(valid_token.expires)
|
expiry_time = datetime.fromisoformat(valid_token.expires)
|
||||||
if expiry_time >= datetime.utcnow():
|
if expiry_time < datetime.utcnow():
|
||||||
# Token exists and is not expired.
|
|
||||||
return response
|
|
||||||
else:
|
|
||||||
# Token exists but is expired.
|
# Token exists but is expired.
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
|
@ -332,7 +329,9 @@ async def user_api_key_auth(
|
||||||
if model in litellm.model_alias_map:
|
if model in litellm.model_alias_map:
|
||||||
model = litellm.model_alias_map[model]
|
model = litellm.model_alias_map[model]
|
||||||
if model and model not in valid_token.models:
|
if model and model not in valid_token.models:
|
||||||
raise Exception(f"Token not allowed to access model")
|
raise ValueError(
|
||||||
|
f"API Key not allowed to access model. This token can only access models={valid_token.models}. Tried to access {model}"
|
||||||
|
)
|
||||||
api_key = valid_token.token
|
api_key = valid_token.token
|
||||||
valid_token_dict = _get_pydantic_json_dict(valid_token)
|
valid_token_dict = _get_pydantic_json_dict(valid_token)
|
||||||
valid_token_dict.pop("token", None)
|
valid_token_dict.pop("token", None)
|
||||||
|
@ -368,7 +367,7 @@ async def user_api_key_auth(
|
||||||
else:
|
else:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="invalid user key",
|
detail=f"Invalid user key, {str(e)}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue