BerriAI/litellm · error · HTTPException

Postgres DB Not connected

Error message

Postgres DB Not connected

What it means

Returned by POST /customer/block (alias /end_user/block) when the proxy's prisma_client is None, i.e. the process started without a database connection. Blocking end users requires upserting blocked=true rows in LiteLLM_EndUserTable, so without Prisma the endpoint aborts with HTTP 500 'Postgres DB Not connected'.

Source

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

        ```
    """
    from litellm.proxy.proxy_server import prisma_client

    try:
        records: Final = []
        if prisma_client is not None:
            for id in data.user_ids:
                record = await _typed_table(EndUserRepository(prisma_client)).upsert(
                    where={"user_id": id},
                    data={
                        "create": {"user_id": id, "blocked": True},
                        "update": {"blocked": True},
                    },
                )
                records.append(record)
            await _evict_end_user_cache_keys(_end_user_cache_keys(data.user_ids))
        else:
            raise HTTPException(
                status_code=500,
                detail={"error": "Postgres DB Not connected"},
            )

        return {"blocked_users": records}
    except Exception as e:
        verbose_proxy_logger.error("An error occurred - %s", e)
        raise HTTPException(status_code=500, detail={"error": str(e)})


@router.post(
    "/end_user/unblock",
    tags=["Customer Management"],
    dependencies=[Depends(user_api_key_auth)],
    include_in_schema=False,
)
@router.post(
    "/customer/unblock",

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set DATABASE_URL to a PostgreSQL connection string (postgresql://user:pass@host:5432/db) in the proxy environment and restart
  2. Check proxy startup logs for Prisma connect errors and fix credentials/network/SSL issues
  3. Confirm the DB is live via another DB-backed route (e.g. GET /key/info or GET /customer/list) before retrying the block
  4. If you do not need persistence, stop calling block endpoints - they have no in-memory mode

Example fix

# before
litellm --config config.yaml   # config.yaml has no database_url -> /customer/block 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 proxy_has_database() -> bool:
    url = os.getenv("DATABASE_URL", "")
    return url.startswith(("postgresql://", "postgres://"))


assert proxy_has_database(), "proxy needs DATABASE_URL before /customer/block can work"

Try / catch

try:
    resp = client.post("/customer/block", json={"user_ids": ids})
except HTTPException as e:
    if e.status_code == 500 and "Not connected" in str(e.detail):
        raise RuntimeError("proxy has no DATABASE_URL configured") from e
    raise

Prevention

When it happens

Trigger: POST /customer/block (or /end_user/block) with {"user_ids": [...]} against a proxy started without DATABASE_URL, or whose Prisma connection failed at startup leaving prisma_client None.

Common situations: Running litellm via pip with a config.yaml that has no database_url; DATABASE_URL pointing at a non-Postgres engine (management endpoints need postgresql://); the DB was unreachable at boot so every DB-backed management route 500s.

Related errors


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