BerriAI/litellm · error · HTTPException
Database not connected
Error message
Database not connected
What it means
Raised by the GET endpoint for email event settings in LiteLLM Enterprise. The handler imports prisma_client from litellm.proxy.proxy_server and, when it is None (no Prisma database was initialized at proxy startup), returns HTTP 500 with 'Database not connected'. Email event settings are persisted in the database, so the endpoint cannot function without one.
Source
Thrown at enterprise/litellm_enterprise/enterprise_callbacks/send_emails/endpoints.py:124
)
@router.get(
"/email/event_settings",
response_model=EmailEventSettingsResponse,
tags=["email management"],
dependencies=[Depends(user_api_key_auth)],
)
async def get_email_event_settings(
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
):
"""
Get all email event settings
"""
from litellm.proxy.proxy_server import prisma_client
if prisma_client is None:
raise HTTPException(status_code=500, detail="Database not connected")
try:
# Get existing settings
settings_dict = await _get_email_settings(prisma_client)
# Create a response with all events (enabled or disabled)
response_settings = []
for event in EmailEvent:
enabled = settings_dict.get(event.value, False)
response_settings.append(EmailEventSettings(event=event, enabled=enabled))
return EmailEventSettingsResponse(settings=response_settings)
except Exception as e:
verbose_proxy_logger.exception(f"Error getting email settings: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
@router.patch(View on GitHub (pinned to 6c2dcb801b)
Solutions
- Set DATABASE_URL (or database_url in the proxy config YAML) to a valid PostgreSQL connection string and restart the proxy so Prisma connects
- Verify the DB is up: check /health/liveliness or /health/readiness and prisma migration status before calling the endpoint
- If you do not need email event settings, avoid the email management endpoints in DB-less deployments
Example fix
# before (config.yaml with no database) general_settings: master_key: sk-123 # after general_settings: master_key: sk-123 litellm_settings: database_url: postgresql://user:pass@host:5432/litellm
Defensive patterns
Strategy: validation
Validate before calling
import httpx
resp = httpx.get(f'{PROXY_URL}/health/readiness', headers=headers)
if resp.status_code != 200:
raise RuntimeError('Proxy/DB not ready; skip email settings call') Try / catch
try:
r = httpx.get(f'{PROXY_URL}/email/settings-endpoint', headers=headers)
r.raise_for_status()
except httpx.HTTPStatusError as e:
if e.response.status_code == 500 and 'Database not connected' in e.response.text:
# DB missing on proxy: fix config, do not retry
raise Prevention
- Configure DATABASE_URL before deploying any proxy that will serve admin UI endpoints
- Add a startup smoke test that calls /health/readiness before routing traffic
- Keep DB-less deployments away from email management endpoints via routing rules
When it happens
Trigger: Calling GET on the email event settings endpoint (tagged 'email management', requires user_api_key_auth) on a proxy instance started without DATABASE_URL / a valid Prisma connection. Any deployment where prisma_client never got set (e.g. config missing database_url) hits this on every call.
Common situations: Running the proxy in DB-less mode (config-only, no virtual keys) but hitting admin/UI email settings endpoints; DATABASE_URL points at an unreachable PostgreSQL so Prisma init failed silently at startup; testing locally without a database.
Related errors
- DB not connected. This endpoint needs a database; set DATABA
- Error saving email settings to general_settings: {str(e)}
- DB not connected. This endpoint needs a database; set DATABA
- Setting tag based guardrail modes is only available in litel
- You must be a LiteLLM Enterprise user to use this feature. I
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/e835c6951c3d9423.
Report an issue: GitHub.