{"record":{"id":"776975ceb242fd16","repo":"BerriAI/litellm","slug":"database-not-connected-776975","errorCode":null,"errorMessage":"Database not connected","messagePattern":"Database not connected","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"enterprise/litellm_enterprise/proxy/vector_stores/endpoints.py","lineNumber":64,"sourceCode":"async def new_vector_store(\n    vector_store: LiteLLM_ManagedVectorStore,\n    user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),\n):\n    \"\"\"\n    Create a new vector store.\n\n    Parameters:\n    - vector_store_id: str - Unique identifier for the vector store\n    - custom_llm_provider: str - Provider of the vector store\n    - vector_store_name: Optional[str] - Name of the vector store\n    - vector_store_description: Optional[str] - Description of the vector store\n    - vector_store_metadata: Optional[Dict] - Additional metadata for the vector store\n    \"\"\"\n    from litellm.proxy.proxy_server import prisma_client\n    from litellm.types.router import GenericLiteLLMParams\n\n    if prisma_client is None:\n        raise HTTPException(status_code=500, detail=\"Database not connected\")\n\n    try:\n        # Check if vector store already exists\n        existing_vector_store = (\n            await prisma_client.db.litellm_managedvectorstorestable.find_unique(\n                where={\"vector_store_id\": vector_store.get(\"vector_store_id\")}\n            )\n        )\n        if existing_vector_store is not None:\n            raise HTTPException(\n                status_code=400,\n                detail=f\"Vector store with ID {vector_store.get('vector_store_id')} already exists\",\n            )\n\n        if vector_store.get(\"vector_store_metadata\") is not None:\n            vector_store[\"vector_store_metadata\"] = safe_dumps(\n                vector_store.get(\"vector_store_metadata\")\n            )","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/enterprise/litellm_enterprise/proxy/vector_stores/endpoints.py#L46-L82","documentation":"The enterprise vector-store management endpoint (create) raises HTTPException 500 \"Database not connected\" when the proxy's Prisma client is None. Vector store records live in the LiteLLM Proxy database (litellm_managedvectorstorestable), so these endpoints are unusable when the proxy runs without DATABASE_URL configured or before the DB connection is established.","triggerScenarios":"POST to the vector store create endpoint while prisma_client is None: proxy started with no DATABASE_URL in env/config, DB URL present but migrations/schema not applied, or the request races proxy startup before Prisma connects.","commonSituations":"Running the proxy in config-only mode (no Postgres) and trying vector store management; docker-compose that forgot to wire DATABASE_URL; hitting the endpoint immediately after proxy boot before the DB init task finishes; DB credentials wrong so connect silently failed.","solutions":["Set DATABASE_URL in the proxy environment/config to a reachable Postgres instance and restart the proxy","Confirm the DB is reachable and the schema exists (let the proxy run Prisma migrations or run `litellm --prisma migrate`)","Check /health/liveliness or proxy startup logs for Prisma connection errors","Retry the request after startup logs show the database connected"],"exampleFix":"# before\nexport DATABASE_URL=\"\"  # or unset\nlitellm --config proxy_config.yaml   # POST /vector_store/create -> 500 Database not connected\n\n# after\nexport DATABASE_URL=\"postgresql://user:pass@host:5432/litellm\"\nlitellm --config proxy_config.yaml   # endpoint now persists vector stores","handlingStrategy":"validation","validationCode":"import httpx\n\n# gate on proxy health before calling vector-store management APIs\nhealth = httpx.get(\"http://proxy:4000/health/liveliness\", timeout=5)\nif health.status_code != 200:\n    raise RuntimeError(\"LiteLLM proxy not healthy; DB-backed endpoints unavailable\")\n\n# strongest signal: the proxy was started with a DATABASE_URL\nimport os\nassert os.environ.get(\"DATABASE_URL\"), \"DATABASE_URL must be set for vector store management\"","typeGuard":null,"tryCatchPattern":"resp = client.post(\"/vector_store/create\", json=payload)\nif resp.status_code == 500 and resp.json().get(\"detail\") == \"Database not connected\":\n    raise RuntimeError(\"Proxy has no DB: set DATABASE_URL and restart\") from None","preventionTips":["Always deploy the proxy with DATABASE_URL when using vector store management, budgets, or virtual keys","Wire a readiness/health probe so traffic only reaches the proxy after the DB connects","Smoke-test one management endpoint right after deploy to catch DB wiring issues early"],"tags":["database","prisma","vector-store","proxy","postgres"],"backgroundTag":"database-not-connected","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}