BerriAI/litellm · error · UnauthorizedError
{e}
Error message
{e} What it means
Raised by ModelGroupsManagementClient.info() when GET {base_url}/model_group/info returns HTTP 401, mapped to UnauthorizedError (redacted message; original HTTPError on .orig_exception; any other non-2xx re-raises as plain requests HTTPError). On success the method returns response.json()["data"], so authentication is the only failure mode it translates into a library-specific exception.
Source
Thrown at litellm/proxy/client/model_groups.py:61
Raises:
UnauthorizedError: If the request fails with a 401 status code
requests.exceptions.RequestException: If the request fails with any other error
"""
url: Final = f"{self._base_url}/model_group/info"
request: Final = requests.Request("GET", url, headers=self._get_headers())
if return_request:
return request
# Prepare and send the request
session: Final = requests.Session()
try:
response: Final = session.send(request.prepare())
response.raise_for_status()
return response.json()["data"]
except requests.exceptions.HTTPError as e:
if e.response.status_code == 401:
raise UnauthorizedError(e)
raise
View on GitHub (pinned to 77b7c6c40c)
Solutions
- Provide the admin key: ModelGroupsManagementClient(base_url, api_key=os.environ["LITELLM_MASTER_KEY"]).info()
- Validate the key with curl -H "Authorization: Bearer $KEY" $BASE_URL/model_group/info
- Refresh credentials after rotation and confirm base_url points at the right proxy
Example fix
# before
mg = ModelGroupsManagementClient("http://localhost:4000")
mg.info() # UnauthorizedError
# after
import os
mg = ModelGroupsManagementClient("http://localhost:4000", api_key=os.environ["LITELLM_MASTER_KEY"])
mg.info() Defensive patterns
Strategy: try-catch
Validate before calling
import requests
def model_groups_readable(base_url: str, api_key: str | None) -> bool:
if not api_key:
return False
r = requests.get(
f"{base_url.rstrip('/')}/model_group/info",
headers={"Authorization": f"Bearer {api_key}"},
timeout=10,
)
return r.status_code != 401 Try / catch
from litellm.proxy.client.exceptions import UnauthorizedError
import requests
try:
groups = model_groups.info()
except UnauthorizedError:
rotate_admin_key() # 401 — credentials rejected
except requests.exceptions.HTTPError as e:
log_and_surface(e.response) # any other non-2xx Prevention
- Management endpoints need management credentials — keep a dedicated admin key for dashboards
- Validate credentials once at startup instead of per scrape
- Alert on 401 rates so silent key rotation is caught early
When it happens
Trigger: Calling model_groups.info() with no api_key on an auth-enforcing proxy; using a virtual/end-user key for what is a management endpoint; a rotated or revoked admin key.
Common situations: Monitoring tools scraping model-group spend/tps data with stale credentials; proxy upgraded and master key changed; script moved between environments without updating the key.
Related errors
- {e}
- {e}
- {e}
- Authentication failed. Check your Arize Phoenix API key and
- Authentication failed. Check your BitBucket access token and
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/cab13ca9c4c4cf28.
Report an issue: GitHub.