BerriAI/litellm · critical · Exception

No db connected

Error message

No db connected

What it means

Raised by get_end_user_object when an end-user row must be loaded (for example the token carries end_user_max_budget) but prisma_client is None - the proxy started without a database because DATABASE_URL was never set. End-user budgets and trackers are DB-backed features that cannot run in DB-less mode.

Source

Thrown at litellm/proxy/auth/auth_checks.py:1522

    If end user exists but has no budget_id, applies the default budget
    (if configured via litellm.max_end_user_budget_id).

    Args:
        end_user_id: The ID of the end user
        prisma_client: Database client instance
        user_api_key_cache: Cache for storing/retrieving data
        route: The request route
        parent_otel_span: Optional OpenTelemetry span for tracing
        proxy_logging_obj: Optional proxy logging object
        token_end_user_max_budget: ``valid_token.end_user_max_budget``, when the caller holds a
            token. Budget enforcement reads the row's spend, so a row that restricts nothing on
            its own must still be loaded when the token carries a budget for it.

    Returns:
        LiteLLM_EndUserTable if found, None otherwise
    """
    if prisma_client is None:
        raise Exception("No db connected")

    if end_user_id is None:
        return None

    _key: Final = end_user_cache_key(end_user_id)

    # Check cache first
    cached_user_obj: Final = await user_api_key_cache.async_get_cache(
        key=_key,
        model_type=LiteLLM_EndUserTable,
    )
    if cached_user_obj is not None:
        return_obj = cached_user_obj
        # Apply default budget if needed
        return_obj = await _apply_default_budget_to_end_user(
            end_user_obj=return_obj,
            prisma_client=prisma_client,
            user_api_key_cache=user_api_key_cache,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set DATABASE_URL on the proxy and start it (litellm --config config.yaml --database_url $DATABASE_URL), then run prisma migrations
  2. Until a DB exists, stop using end-user budgets / keys with end_user_max_budget
  3. Confirm connectivity via the proxy health endpoints once started

Example fix

# before
docker run litellm/litellm --config config.yaml  # no DATABASE_URL

# after
docker run -e DATABASE_URL="postgresql://user:pass@host:5432/litellm" \
  litellm/litellm --config config.yaml
Defensive patterns

Strategy: validation

Validate before calling

# operator preflight: refuse to start DB-dependent features without a DB
import os

if not os.getenv("DATABASE_URL"):
    raise SystemExit(
        "end-user budgets / virtual keys require DATABASE_URL - unset them or configure the DB"
    )

Try / catch

try:
    resp = client.chat.completions.create(**payload)
except Exception as e:
    if "No db connected" in str(e):
        raise RuntimeError("proxy misconfigured: DATABASE_URL missing") from e
    raise

Prevention

When it happens

Trigger: A request identifies an end user (X-Litellm-End-User header or end-user param) together with a key that sets end_user_max_budget, while the proxy has no DATABASE_URL configured.

Common situations: Running the proxy from a single config.yaml without a database, then attaching budgeted virtual keys or end-user limits; forgetting DATABASE_URL in docker-compose/k8s after adding virtual-key features.

Related errors


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