BerriAI/litellm · error · HTTPException

DB not connected. This endpoint needs a database; set DATABA

Error message

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

What it means

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).

Source

Thrown at litellm/proxy/management_endpoints/customer_endpoints.py:406

    """
    Validation:
        - check if default model exists 
        - create budget object if not already created
    
    - Add user to end user table 

    Return 
    - end-user object
    - currently allowed models 
    """
    from litellm.proxy.proxy_server import (
        litellm_proxy_admin_name,
        llm_router,
        prisma_client,
    )

    if prisma_client is None:
        raise HTTPException(
            status_code=500,
            detail={"error": CommonProxyErrors.db_not_connected_error.value},
        )
    try:
        ## VALIDATION ##
        if data.default_model is not None:
            if llm_router is None:
                raise HTTPException(
                    status_code=422,
                    detail={"error": CommonProxyErrors.no_llm_router.value},
                )
            elif data.default_model not in llm_router.get_model_names():
                raise HTTPException(
                    status_code=422,
                    detail={
                        "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())}"
                    },
                )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set DATABASE_URL to a postgresql:// connection string in the proxy environment and restart
  2. Verify Prisma connected at startup (no Prisma errors in boot logs)
  3. Retry the create once another DB-backed route (e.g. /customer/info) succeeds
  4. If you only need model routing without budgets/tracking, skip customer creation entirely

Example fix

# before
litellm --config config.yaml   # no DATABASE_URL -> /customer/new 500s

# after
export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/litellm
litellm --config config.yaml
Defensive patterns

Strategy: validation

Validate before calling

import os


def can_create_customers() -> bool:
    return os.getenv("DATABASE_URL", "").startswith(("postgresql://", "postgres://"))

Try / catch

try:
    r = httpx.post(f"{base}/customer/new", json=payload, headers=headers)
except httpx.HTTPStatusError as e:
    if e.response.status_code == 500 and "DB not connected" in e.response.text:
        raise RuntimeError("proxy lacks DATABASE_URL; customer endpoints need Postgres") from e
    raise

Prevention

When it happens

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

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

Related errors


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