{"record":{"id":"baa92c45e7b3b8a8","repo":"BerriAI/litellm","slug":"db-not-connected-this-endpoint-needs-a-database","errorCode":null,"errorMessage":"DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.litellm.ai/docs/proxy/virtual_keys","messagePattern":"DB not connected\\. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string \\(postgresql://\\.\\.\\.\\) to enable it\\. See https://docs\\.litellm\\.ai/docs/proxy/virtual_keys","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"enterprise/litellm_enterprise/proxy/audit_logging_endpoints.py","lineNumber":99,"sourceCode":"    # Sorting parameters\n    sort_by: Optional[str] = Query(\n        None,\n        description=\"Column to sort by (e.g. 'updated_at', 'action', 'table_name')\",\n    ),\n    sort_order: str = Query(\"desc\", description=\"Sort order ('asc' or 'desc')\"),\n):\n    \"\"\"\n    Get all audit logs with filtering and pagination.\n\n    Returns a paginated response of audit logs matching the specified filters.\n\n    Note: object_team_id and object_key_hash use Prisma JSON path filtering,\n    which requires PostgreSQL.\n    \"\"\"\n    from litellm.proxy.proxy_server import prisma_client\n\n    if prisma_client is None:\n        raise HTTPException(\n            status_code=500,\n            detail={\"message\": CommonProxyErrors.db_not_connected_error.value},\n        )\n\n    # Build filter conditions\n    where_conditions: Dict[str, Any] = {}\n    if changed_by:\n        where_conditions[\"changed_by\"] = changed_by\n    if changed_by_api_key:\n        where_conditions[\"changed_by_api_key\"] = changed_by_api_key\n    if action:\n        where_conditions[\"action\"] = action\n    if table_name:\n        where_conditions[\"table_name\"] = table_name\n    if object_id:\n        where_conditions[\"object_id\"] = object_id\n    if start_date or end_date:\n        date_filter: Dict[str, Any] = {}","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/litellm_enterprise/proxy/audit_logging_endpoints.py#L81-L117","documentation":"Raised by the enterprise audit-log listing endpoint. It performs Prisma JSON path filtering on object_team_id / object_key_hash (PostgreSQL-only) and returns HTTP 500 with CommonProxyErrors.db_not_connected_error when prisma_client is None. The message explicitly tells you to set DATABASE_URL to a PostgreSQL connection string.","triggerScenarios":"GET on /audit/logs (with optional filters like changed_by, action, date range) against a proxy without a database. The guard fires before any filter is built, so even an unfiltered list call triggers it.","commonSituations":"Exploring audit endpoints on a config-only proxy; DATABASE_URL omitted because the deployer assumed audit logs were optional; DB credentials rotated and the proxy restarted without the new URL.","solutions":["Set DATABASE_URL (PostgreSQL) in env or config and restart the proxy","Run prisma migrations (litellm --config config.yaml --diagnose or the documented migration flow) so litellm_auditlog exists, then retry","Do not call audit endpoints on DB-less instances; monitor them separately"],"exampleFix":"# before\nexport MASTER_KEY=sk-123\nlitellm --config config.yaml\n# GET /audit/logs -> 500\n\n# after\nexport DATABASE_URL=postgresql://user:pass@host:5432/litellm\nlitellm --config config.yaml","handlingStrategy":"validation","validationCode":"ready = httpx.get(f'{PROXY_URL}/health/readiness', headers=admin_headers)\nif ready.status_code != 200:\n    raise RuntimeError('Cannot list audit logs: proxy DB not ready')","typeGuard":null,"tryCatchPattern":"try:\n    logs = httpx.get(f'{PROXY_URL}/audit/logs', params=p, headers=admin_headers)\nexcept httpx.HTTPStatusError as e:\n    if 'db_not_connected' in e.response.text or 'DATABASE_URL' in e.response.text:\n        raise InfrastructureError('proxy missing DATABASE_URL') from e\n    raise","preventionTips":["Provision PostgreSQL as a hard dependency for deployments using audit logs","Add DB readiness gates to dashboards that call /audit/logs","Use IaC so DATABASE_URL is always set on audit-enabled environments"],"tags":["database","prisma","litellm-enterprise","audit-logging","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}