Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from litellm._uuid import uuid
from litellm.proxy._types import *
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
from litellm.proxy.common_utils.exception_logging import log_proxy_exception
from litellm.proxy.management_endpoints.common_utils import _set_object_metadata_field
from litellm.proxy.management_helpers.utils import (
management_endpoint_wrapper,
Expand Down Expand Up @@ -468,11 +469,7 @@ async def new_project(

return response
except Exception as e:
verbose_proxy_logger.exception(
"litellm.proxy.management_endpoints.project_endpoints.new_project(): Exception occured - {}".format(
str(e)
)
)
log_proxy_exception(verbose_proxy_logger, "/project/new", e)
raise handle_exception_on_proxy(e)


Expand Down Expand Up @@ -706,11 +703,7 @@ async def update_project( # noqa: PLR0915

return updated_project
except Exception as e:
verbose_proxy_logger.exception(
"litellm.proxy.management_endpoints.project_endpoints.update_project(): Exception occured - {}".format(
str(e)
)
)
log_proxy_exception(verbose_proxy_logger, "/project/update", e)
raise handle_exception_on_proxy(e)


Expand Down Expand Up @@ -814,11 +807,7 @@ async def delete_project(

return deleted_projects
except Exception as e:
verbose_proxy_logger.exception(
"litellm.proxy.management_endpoints.project_endpoints.delete_project(): Exception occured - {}".format(
str(e)
)
)
log_proxy_exception(verbose_proxy_logger, "/project/delete", e)
raise handle_exception_on_proxy(e)


Expand Down Expand Up @@ -895,11 +884,7 @@ async def project_info(

return project
except Exception as e:
verbose_proxy_logger.exception(
"litellm.proxy.management_endpoints.project_endpoints.project_info(): Exception occured - {}".format(
str(e)
)
)
log_proxy_exception(verbose_proxy_logger, "/project/info", e)
raise handle_exception_on_proxy(e)


Expand Down Expand Up @@ -955,9 +940,5 @@ async def list_projects(

return projects
except Exception as e:
verbose_proxy_logger.exception(
"litellm.proxy.management_endpoints.project_endpoints.list_projects(): Exception occured - {}".format(
str(e)
)
)
log_proxy_exception(verbose_proxy_logger, "/project/list", e)
raise handle_exception_on_proxy(e)
39 changes: 38 additions & 1 deletion litellm/proxy/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3760,7 +3760,44 @@ class ProxyErrorTypes(str, enum.Enum):

auth_error = "auth_error"
"""
General authentication error
General authentication error. Use only when the failure does not fit
one of the more specific auth_* types below — UI clients (litellm
dashboard) fall back to a heuristic redirect decision when they see
this type, so prefer a precise type whenever the cause is known.
"""

auth_session_expired = "auth_session_expired"
"""
The caller's session/token was once valid but is no longer (expired,
revoked, deleted, key rotated). UI clients should clear local auth
state and redirect to the login page. Distinguish from
`auth_invalid_credentials` — that one means the credential format was
bad from the start (never authenticated).
"""

auth_invalid_credentials = "auth_invalid_credentials"
"""
The supplied credential is malformed, never existed, or does not
parse — e.g. missing Authorization header, garbled bearer token, key
not found in DB. UI clients should treat this the same as
`auth_session_expired` (clear state + login) because there is no
valid session to recover.
"""

auth_permission_denied = "auth_permission_denied"
"""
The caller is authenticated but lacks the role / scope / model
access needed for this specific endpoint or resource (admin-only,
team_id mismatch, model not in allowed list). UI clients must NOT
redirect to login — the session is still valid, only this one
operation is forbidden. Surface as a toast.

Note: `key_model_access_denied`, `team_model_access_denied`,
`team_member_permission_error`, and the other granular
*_access_denied / *_permission_error types are already specific
enough; this catch-all is for the cases where the cause is "you're
not allowed" but doesn't fit those buckets (e.g. master-key-required
on a non-master-key request).
"""

internal_server_error = "internal_server_error"
Expand Down
34 changes: 23 additions & 11 deletions litellm/proxy/auth/auth_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
UserAPIKeyAuth,
)
from litellm.proxy.auth.route_checks import RouteChecks
from litellm.proxy.common_utils.exception_logging import log_proxy_exception
from litellm.proxy.common_utils.http_parsing_utils import (
_safe_get_request_headers,
_safe_get_request_query_params,
Expand Down Expand Up @@ -1467,11 +1468,12 @@ async def get_team_membership(
)

return _response
except Exception:
verbose_proxy_logger.exception(
"Error getting team membership for user_id: %s, team_id: %s",
user_id,
team_id,
except Exception as e:
log_proxy_exception(
verbose_proxy_logger,
"get_team_membership",
e,
extra={"user_id": user_id, "team_id": team_id},
)
return None

Expand Down Expand Up @@ -2099,9 +2101,11 @@ async def get_access_object(
except HTTPException:
raise
except Exception as e:
verbose_proxy_logger.exception(
"Error getting access group for access_group_id: %s",
access_group_id,
log_proxy_exception(
verbose_proxy_logger,
"access_group_lookup",
e,
extra={"access_group_id": access_group_id},
)
raise HTTPException(
status_code=404,
Expand Down Expand Up @@ -2214,7 +2218,12 @@ async def get_team_object_by_alias(
except HTTPException:
raise
except Exception as e:
verbose_proxy_logger.exception("Error looking up team by alias: %s", team_alias)
log_proxy_exception(
verbose_proxy_logger,
"team_alias_lookup",
e,
extra={"team_alias": team_alias},
)
raise HTTPException(
status_code=500,
detail={
Expand Down Expand Up @@ -2306,8 +2315,11 @@ async def get_org_object_by_alias(
except HTTPException:
raise
except Exception as e:
verbose_proxy_logger.exception(
"Error looking up organization by alias: %s", org_alias
log_proxy_exception(
verbose_proxy_logger,
"organization_alias_lookup",
e,
extra={"org_alias": org_alias},
)
raise HTTPException(
status_code=500,
Expand Down
Loading