BerriAI/litellm · error · KeyNotFoundError

token_not_found_in_db

token_not_found_in_db

Error message

Authentication Error, Invalid proxy server token passed. key={hashed_token}, not found in db. Create key via `/key/generate` call.

What it means

Raised after a cache miss and DB lookup when the hashed token matches no key row: the presented proxy key is invalid/revoked. The message points to /key/generate since only the hash is stored, not recoverable keys.

Source

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

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

        if key.object_permission_id and not key.object_permission:
            try:
                key.object_permission = await get_object_permission(
                    object_permission_id=key.object_permission_id,
                    prisma_client=self._prisma,
                    user_api_key_cache=self._cache,
                    parent_otel_span=self._parent_otel_span,
                    proxy_logging_obj=self._proxy_logging_obj,
                )
            except Exception as e:
                verbose_proxy_logger.debug(
                    "Failed to load object_permission for key with object_permission_id=%s: %s",
                    key.object_permission_id,
                    e,
                )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Create a key via the /key/generate endpoint and use that key.
  2. Check for typos or truncation in the Bearer token being sent.

Example fix

curl -X POST $PROXY/key/generate -H 'Authorization: Bearer $MASTER_KEY' -d '{}'
Defensive patterns

Strategy: validation

When it happens

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

Common situations: The presented proxy token was not found in the database (invalid, deleted, or never created).

Understand the failure class


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