BerriAI/litellm · error · HTTPException

Database not connected

Error message

Database not connected

What it means

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.

Source

Thrown at enterprise/litellm_enterprise/proxy/vector_stores/endpoints.py:64

async def new_vector_store(
    vector_store: LiteLLM_ManagedVectorStore,
    user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
):
    """
    Create a new vector store.

    Parameters:
    - vector_store_id: str - Unique identifier for the vector store
    - custom_llm_provider: str - Provider of the vector store
    - vector_store_name: Optional[str] - Name of the vector store
    - vector_store_description: Optional[str] - Description of the vector store
    - vector_store_metadata: Optional[Dict] - Additional metadata for the vector store
    """
    from litellm.proxy.proxy_server import prisma_client
    from litellm.types.router import GenericLiteLLMParams

    if prisma_client is None:
        raise HTTPException(status_code=500, detail="Database not connected")

    try:
        # Check if vector store already exists
        existing_vector_store = (
            await prisma_client.db.litellm_managedvectorstorestable.find_unique(
                where={"vector_store_id": vector_store.get("vector_store_id")}
            )
        )
        if existing_vector_store is not None:
            raise HTTPException(
                status_code=400,
                detail=f"Vector store with ID {vector_store.get('vector_store_id')} already exists",
            )

        if vector_store.get("vector_store_metadata") is not None:
            vector_store["vector_store_metadata"] = safe_dumps(
                vector_store.get("vector_store_metadata")
            )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set DATABASE_URL in the proxy environment/config to a reachable Postgres instance and restart the proxy
  2. Confirm the DB is reachable and the schema exists (let the proxy run Prisma migrations or run `litellm --prisma migrate`)
  3. Check /health/liveliness or proxy startup logs for Prisma connection errors
  4. Retry the request after startup logs show the database connected

Example fix

# before
export DATABASE_URL=""  # or unset
litellm --config proxy_config.yaml   # POST /vector_store/create -> 500 Database not connected

# after
export DATABASE_URL="postgresql://user:pass@host:5432/litellm"
litellm --config proxy_config.yaml   # endpoint now persists vector stores
Defensive patterns

Strategy: validation

Validate before calling

import httpx

# gate on proxy health before calling vector-store management APIs
health = httpx.get("http://proxy:4000/health/liveliness", timeout=5)
if health.status_code != 200:
    raise RuntimeError("LiteLLM proxy not healthy; DB-backed endpoints unavailable")

# strongest signal: the proxy was started with a DATABASE_URL
import os
assert os.environ.get("DATABASE_URL"), "DATABASE_URL must be set for vector store management"

Try / catch

resp = client.post("/vector_store/create", json=payload)
if resp.status_code == 500 and resp.json().get("detail") == "Database not connected":
    raise RuntimeError("Proxy has no DB: set DATABASE_URL and restart") from None

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/776975ceb242fd16. Report an issue: GitHub.