BerriAI/litellm · error · NoDatabaseConnectionError

No DB Connected. See - https://docs.litellm.ai/docs/proxy/vi

Error message

No DB Connected. See - https://docs.litellm.ai/docs/proxy/virtual_keys

What it means

Raised by the key-store resolver when a request must be authenticated from the database but the Prisma client is not initialized (proxy running without a database). Virtual-key resolution requires the LiteLLM DB; the message points at the virtual-keys docs. It is the auth-path equivalent of the endpoints' 'Prisma client not initialized' 500.

Source

Thrown at litellm/proxy/auth/resolvers/store.py:104

            subject_fallback=key.token,
            credential_ref=CredentialRef(token_id=key.token),
        )

    @staticmethod
    def key_from_principal(principal: Principal) -> UserAPIKeyAuth:
        """Hand back the resolved key object carried on the Principal.

        Stopgap for the request flow that still consumes ``UserAPIKeyAuth`` for
        budget, rate-limit, and policy state. Only Principals produced by
        ``resolve`` carry a source key.
        """
        if principal.source_key is None:
            raise PrincipalMissingSourceKeyError()
        return principal.source_key

    async def _resolve_key(self, hashed_token: str) -> UserAPIKeyAuth:
        if self._prisma is None:
            raise NoDatabaseConnectionError()

        cached: Final = await self._cache.async_get_cache(key=hashed_token, model_type=UserAPIKeyAuth)
        if cached is not None:
            return _copy_user_api_key_auth_for_cache(user_api_key_obj=cached)

        if self._check_cache_only:
            raise KeyNotInCacheError(hashed_token)

        from_db: Final[BaseModel | None] = await _fetch_key_object_from_db_with_reconnect(
            hashed_token=hashed_token,
            prisma_client=self._prisma,
            parent_otel_span=self._parent_otel_span,
            proxy_logging_obj=self._proxy_logging_obj,
        )
        if from_db is None:
            raise KeyNotFoundError(hashed_token)

        key: Final = UserAPIKeyAuth.model_validate(from_db.model_dump(exclude_none=True))

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set DATABASE_URL to a PostgreSQL connection string so the proxy can store virtual keys.
  2. See https://docs.litellm.ai/docs/proxy/virtual_keys for database setup.

Example fix

export DATABASE_URL=postgresql://user:pass@host:5432/litellm
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/proxy/auth/resolvers/store.py:104 when the library encounters an invalid state.

Common situations: A key lookup was attempted but no database is connected to the proxy.


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