{"record":{"id":"01750e80708ba412","repo":"BerriAI/litellm","slug":"db-not-connected-this-endpoint-needs-a-database-01750e","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/management_endpoints/internal_user_endpoints.py","lineNumber":35,"sourceCode":"    dependencies=[Depends(user_api_key_auth)],\n)\nasync def available_enterprise_users(\n    user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),\n):\n    \"\"\"\n    For keys with `max_users` set, return the list of users that are allowed to use the key.\n    \"\"\"\n    from litellm.proxy._types import CommonProxyErrors, EnterpriseLicenseData\n    from litellm.proxy.proxy_server import (\n        premium_user,\n        premium_user_data,\n        prisma_client,\n    )\n    from litellm.repositories.team_repository import TeamRepository\n    from litellm.repositories.user_repository import UserRepository\n\n    if prisma_client is None:\n        raise HTTPException(\n            status_code=500,\n            detail={\"error\": CommonProxyErrors.db_not_connected_error.value},\n        )\n\n    if not premium_user:\n        # check if SSO is enabled - show 5 user limit\n        from litellm.proxy.auth.auth_utils import _has_user_setup_sso\n\n        if _has_user_setup_sso():\n            premium_user_data = EnterpriseLicenseData(\n                max_users=5,\n            )\n\n    user_count = await UserRepository(prisma_client).count_billable_users()\n    team_count = await TeamRepository(prisma_client).count()\n\n    if (\n        not premium_user_data","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/enterprise/litellm_enterprise/proxy/management_endpoints/internal_user_endpoints.py#L17-L53","documentation":"/user/available_users (enterprise internal user management) requires Prisma/PostgreSQL. The handler imports prisma_client from proxy_server and immediately raises HTTP 500 with CommonProxyErrors.db_not_connected_error when it is None — i.e. the proxy started without DATABASE_URL so no database client was ever constructed.","triggerScenarios":"GET /user/available_users on a proxy whose config lacks database_url / DATABASE_URL, so prisma_client is None at request time.","commonSituations":"Config written for stateless single-instance operation and then user-management endpoints called; docker run without passing DATABASE_URL into the container; a typo'd DB URL that silently prevented Prisma connect.","solutions":["Set DATABASE_URL (or database_url in config.yaml) to a postgresql:// connection string and restart — LiteLLM connects and migrates on startup","Use the documented docker-compose setup with a postgres container for user/team management features","Confirm the DB is attached via /health/liveliness before calling user endpoints"],"exampleFix":"# before\ndocker run -p 4000:4000 ghcr.io/berriai/litellm --config /app/config.yaml  # no DATABASE_URL\n\n# after\ndocker run -p 4000:4000 -e DATABASE_URL=postgresql://user:pass@host:5432/litellm ghcr.io/berriai/litellm --config /app/config.yaml","handlingStrategy":"validation","validationCode":"import os\n\nDB_REQUIRED = True\nif DB_REQUIRED and not os.environ.get(\"DATABASE_URL\", \"\").startswith(\"postgresql://\"):\n    raise SystemExit(\"DATABASE_URL must be a postgresql:// string for user management endpoints\")","typeGuard":null,"tryCatchPattern":"try:\n    users = await client.get(\"/user/available_users\")\nexcept HTTPStatusError as e:\n    if e.response.status_code == 500 and \"db_not_connected\" in e.response.text:\n        # config error, not transient: fix DATABASE_URL and restart proxy\n        raise RuntimeError(\"proxy needs DATABASE_URL set\")\n    raise","preventionTips":["Set DATABASE_URL in every environment that uses user/team/project management","Use the stock docker-compose with postgres instead of hand-rolled stateless setups","Health-check DB connectivity after deploys before smoke-testing management endpoints"],"tags":["litellm","litellm-proxy","database","prisma","configuration"],"backgroundTag":"database-not-connected","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T10:36:37.832Z"}