{"record":{"id":"c6cf4602df86379f","repo":"BerriAI/litellm","slug":"db-not-connected-this-endpoint-needs-a-database-c6cf46","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":"litellm/proxy/management_endpoints/customer_endpoints.py","lineNumber":406,"sourceCode":"    \"\"\"\n    Validation:\n        - check if default model exists \n        - create budget object if not already created\n    \n    - Add user to end user table \n\n    Return \n    - end-user object\n    - currently allowed models \n    \"\"\"\n    from litellm.proxy.proxy_server import (\n        litellm_proxy_admin_name,\n        llm_router,\n        prisma_client,\n    )\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    try:\n        ## VALIDATION ##\n        if data.default_model is not None:\n            if llm_router is None:\n                raise HTTPException(\n                    status_code=422,\n                    detail={\"error\": CommonProxyErrors.no_llm_router.value},\n                )\n            elif data.default_model not in llm_router.get_model_names():\n                raise HTTPException(\n                    status_code=422,\n                    detail={\n                        \"error\": f\"Default Model not on proxy. Configure via `/model/new` or config.yaml. Default_model={data.default_model}, proxy_model_names={set(llm_router.get_model_names())}\"\n                    },\n                )","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/customer_endpoints.py#L388-L424","documentation":"POST /customer/new starts with a hard check that prisma_client exists: creating an end customer requires writing LiteLLM_EndUserTable rows (plus an optional budget row). Without a database the endpoint returns HTTP 500 with CommonProxyErrors.db_not_connected_error, whose text points at DATABASE_URL and the virtual-keys docs (litellm/proxy/_types.py:3632).","triggerScenarios":"POST /customer/new on a proxy started with no DATABASE_URL, or whose Prisma connection failed at boot - e.g. a config.yaml containing only model_list.","commonSituations":"Trying out customer/budget tracking on a minimal proxy setup; DATABASE_URL present in dev but stripped from the deployed container; DB credential rotation silently breaking startup.","solutions":["Set DATABASE_URL to a postgresql:// connection string in the proxy environment and restart","Verify Prisma connected at startup (no Prisma errors in boot logs)","Retry the create once another DB-backed route (e.g. /customer/info) succeeds","If you only need model routing without budgets/tracking, skip customer creation entirely"],"exampleFix":"# before\nlitellm --config config.yaml   # no DATABASE_URL -> /customer/new 500s\n\n# after\nexport DATABASE_URL=postgresql://postgres:postgres@localhost:5432/litellm\nlitellm --config config.yaml","handlingStrategy":"validation","validationCode":"import os\n\n\ndef can_create_customers() -> bool:\n    return os.getenv(\"DATABASE_URL\", \"\").startswith((\"postgresql://\", \"postgres://\"))","typeGuard":null,"tryCatchPattern":"try:\n    r = httpx.post(f\"{base}/customer/new\", json=payload, headers=headers)\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code == 500 and \"DB not connected\" in e.response.text:\n        raise RuntimeError(\"proxy lacks DATABASE_URL; customer endpoints need Postgres\") from e\n    raise","preventionTips":["Treat DATABASE_URL as mandatory for any deployment using management endpoints","Add a health gate after deploy that calls one DB-backed endpoint before declaring the proxy ready","Keep dev/prod parity for env vars so a missing DATABASE_URL is caught in dev first"],"tags":["litellm","database-connection","postgres","customer-management"],"backgroundTag":"database-not-connected","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}