{"record":{"id":"9064378c1d22bcc0","repo":"BerriAI/litellm","slug":"database-not-connected-connect-a-database-to-your-906437","errorCode":null,"errorMessage":"Database not connected. Connect a database to your proxy - https://docs.litellm.ai/docs/simple_proxy#managing-auth---virtual-keys","messagePattern":"Database not connected\\. Connect a database to your proxy - https://docs\\.litellm\\.ai/docs/simple_proxy#managing-auth---virtual-keys","errorType":"exception","errorClass":"Exception","httpStatus":500,"severity":"critical","filePath":"litellm/proxy/management_endpoints/key_management_endpoints.py","lineNumber":3550,"sourceCode":"    **New endpoint**. Currently admin only.\n    Parameters:\n        keys: Optional[list] = body parameter representing the key(s) in the request\n        user_api_key_dict: UserAPIKeyAuth = Dependency representing the user's API key\n    Returns:\n        Dict containing the key and its associated information\n\n    Example Curl:\n    ```\n    curl -X GET \"http://0.0.0.0:4000/key/info\" \\\n    -H \"Authorization: Bearer sk-1234\" \\\n    -d {\"keys\": [\"sk-1\", \"sk-2\", \"sk-3\"]}\n    ```\n    \"\"\"\n    from litellm.proxy.proxy_server import prisma_client, user_api_key_cache\n\n    try:\n        if prisma_client is None:\n            raise Exception(\n                \"Database not connected. Connect a database to your proxy - https://docs.litellm.ai/docs/simple_proxy#managing-auth---virtual-keys\"\n            )\n        if data is None:\n            raise HTTPException(\n                status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,\n                detail={\"message\": \"Malformed request. No keys passed in.\"},\n            )\n\n        # Resolve key_aliases to tokens so we never pass token=None (unbounded query)\n        tokens_to_query: Final = list(data.keys) if data.keys else []\n        if data.key_aliases:\n            alias_rows: Final = await _prisma_table(VerificationTokenRepository(prisma_client)).find_many(\n                where={\"key_alias\": {\"in\": data.key_aliases}},\n                include={\"litellm_budget_table\": True},\n            )\n            alias_tokens: Final = [row.token for row in alias_rows if row.token]\n            tokens_to_query.extend(alias_tokens)\n","sourceCodeStart":3532,"sourceCodeEnd":3568,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/key_management_endpoints.py#L3532-L3568","documentation":"POST /v2/key/info (batched key info lookup) needs the Prisma DB because key records live there. The handler checks prisma_client at call time and raises this Exception (rendered as a 500-family error) when the proxy has no database configured. The message links the docs for attaching a database, since virtual-key management is fundamentally a DB-backed feature.","triggerScenarios":"Calling POST /v2/key/info on a proxy started without DATABASE_URL / database_connection config; the DB env var not reaching the container/pod; config file loaded from a path lacking the database block.","commonSituations":"Trying key-management APIs on a config-only proxy meant purely for model routing; docker-compose that forgets to pass DATABASE_URL into the litellm service; DB secret present at build time but not runtime.","solutions":["Configure and restart with a Postgres database: set DATABASE_URL env var or database_connection.url in the config YAML.","Confirm the variable is visible to the running process (docker exec env | grep DATABASE_URL, or pod exec).","Until a DB is attached, expect all key endpoints (/key/info, /key/generate, /key/delete) to fail the same way — this is a deployment gap, not a per-call issue."],"exampleFix":"# before\n# docker-compose.yml service has no DATABASE_URL\n\n# after\nservices:\n  litellm:\n    image: ghcr.io/berriai/litellm:main-latest\n    environment:\n      DATABASE_URL: postgresql://user:pass@db:5432/litellm\n    command: [\"--config\", \"/app/config.yaml\"]","handlingStrategy":"validation","validationCode":"if not os.environ.get(\"DATABASE_URL\"):\n    raise RuntimeError(\"cannot query /v2/key/info: litellm proxy needs a Postgres DB (DATABASE_URL)\")\nresp = client.post(\"/v2/key/info\", json={\"keys\": [\"sk-1\"]})","typeGuard":null,"tryCatchPattern":"try:\n    resp = client.post(\"/v2/key/info\", json={\"keys\": keys})\n    resp.raise_for_status()\nexcept HTTPError as e:\n    if \"Database not connected\" in e.response.text:\n        fail_deploy(\"proxy started without DB; attach DATABASE_URL and restart\")\n    raise","preventionTips":["Gate any key-management integration behind a DB-required configuration assertion at startup.","Include DATABASE_URL in the deployment checklist for every environment that uses virtual keys.","Smoke-test a DB-backed endpoint post-deploy so misconfigurations surface before users do."],"tags":["database","connection","key-management","litellm-proxy","config"],"backgroundTag":"database-not-connected","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}