BerriAI/litellm · error · HTTPException
Database not connected
Error message
Database not connected
What it means
POST /user/bulk_update requires a database; with prisma_client None it returns HTTP 500 {'error': 'Database not connected'} before touching any user. The endpoint otherwise applies user_updates (optionally across all_users) and enforces admin-only role changes with the same 'Only proxy admins can modify user roles.' error.
Source
Thrown at litellm/proxy/management_endpoints/internal_user_endpoints.py:1735
Example request for all users:
```bash
curl --location 'http://0.0.0.0:4000/user/bulk_update' \
--header 'Authorization: Bearer sk-1234' \
--header 'Content-Type: application/json' \
--data '{
"all_users": true,
"user_updates": {
"user_role": "internal_user",
"max_budget": 50.0
}
}'
```
"""
from litellm.proxy.proxy_server import litellm_proxy_admin_name, prisma_client
if prisma_client is None:
raise HTTPException(
status_code=500,
detail={"error": "Database not connected"},
)
# Only proxy admins can modify user_role in bulk updates
_bulk_role = getattr(data.user_updates, "user_role", None) if data.user_updates else None
if _bulk_role is None and data.users:
_bulk_role = next((u.user_role for u in data.users if u.user_role is not None), None)
if _bulk_role is not None and user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN.value:
raise HTTPException(
status_code=403,
detail="Only proxy admins can modify user roles.",
)
# Determine the list of users to update
users_to_update: list[UpdateUserRequest] | list[UpdateUserRequestNoUserIDorEmail] = []
if data.all_users and data.user_updates:View on GitHub (pinned to 77b7c6c40c)
Solutions
- Set general_settings.database_url (postgresql://...) or DATABASE_URL and restart the proxy
- Confirm the DB is reachable via GET /health/liveliness or GET /user/list
- Re-run the bulk job after the health check shows the database connected
Example fix
# before
POST /user/bulk_update -d '{"all_users": true, "user_updates": {"max_budget": 50}}'
# 500 Database not connected
# after: config.yaml
general_settings:
database_url: postgresql://user:pass@host:5432/litellm
# restart proxy, retry -> 200 Defensive patterns
Strategy: validation
Validate before calling
import requests
def db_ready(base_url: str, admin_key: str) -> bool:
r = requests.get(f"{base_url}/health/liveliness",
headers={"Authorization": f"Bearer {admin_key}"}, timeout=10)
return r.ok and r.json().get("litellm_database", "") != "" Try / catch
except requests.HTTPError as e:
body = e.response.text if e.response is not None else ""
if e.response is not None and e.response.status_code == 500 and "Database not connected" in body:
raise ConfigError("bulk user updates need DATABASE_URL configured") from e
raise Prevention
- Run bulk jobs only after a /health/liveliness DB check passes
- Inject DATABASE_URL explicitly in cron/container environments
- Prefer DB-backed deployments for any user-management automation
When it happens
Trigger: POST /user/bulk_update (including the all_users: true form shown in its docstring) on a proxy started without general_settings.database_url / DATABASE_URL, or whose Prisma connection failed.
Common situations: Bulk onboarding scripts pointed at a proxy instance without Postgres config; the DATABASE_URL env var missing in the cron job's or container's environment; config.yaml only containing model_list.
Related errors
- Database not connected. Connect a database to your proxy - h
- str(e)
- DB not connected. This endpoint needs a database; set DATABA
- DB not connected. This endpoint needs a database; set DATABA
- Database not connected. Connect a database to your proxy - h
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/2c6ceca64a038fed.
Report an issue: GitHub.