{"record":{"id":"e64fa54d75e4b047","repo":"BerriAI/litellm","slug":"key-doesn-t-exist-in-cache-check-cache-only-true","errorCode":null,"errorMessage":"Key doesn't exist in cache + check_cache_only=True. key={hashed_token}.","messagePattern":"Key doesn't exist in cache \\+ check_cache_only=True\\. key=(.+?)\\.","errorType":"exception","errorClass":"KeyNotInCacheError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/auth/resolvers/store.py","lineNumber":111,"sourceCode":"\n        Stopgap for the request flow that still consumes ``UserAPIKeyAuth`` for\n        budget, rate-limit, and policy state. Only Principals produced by\n        ``resolve`` carry a source key.\n        \"\"\"\n        if principal.source_key is None:\n            raise PrincipalMissingSourceKeyError()\n        return principal.source_key\n\n    async def _resolve_key(self, hashed_token: str) -> UserAPIKeyAuth:\n        if self._prisma is None:\n            raise NoDatabaseConnectionError()\n\n        cached: Final = await self._cache.async_get_cache(key=hashed_token, model_type=UserAPIKeyAuth)\n        if cached is not None:\n            return _copy_user_api_key_auth_for_cache(user_api_key_obj=cached)\n\n        if self._check_cache_only:\n            raise KeyNotInCacheError(hashed_token)\n\n        from_db: Final[BaseModel | None] = await _fetch_key_object_from_db_with_reconnect(\n            hashed_token=hashed_token,\n            prisma_client=self._prisma,\n            parent_otel_span=self._parent_otel_span,\n            proxy_logging_obj=self._proxy_logging_obj,\n        )\n        if from_db is None:\n            raise KeyNotFoundError(hashed_token)\n\n        key: Final = UserAPIKeyAuth.model_validate(from_db.model_dump(exclude_none=True))\n\n        if key.object_permission_id and not key.object_permission:\n            try:\n                key.object_permission = await get_object_permission(\n                    object_permission_id=key.object_permission_id,\n                    prisma_client=self._prisma,\n                    user_api_key_cache=self._cache,","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/auth/resolvers/store.py#L93-L129","documentation":"Raised by _resolve_key when the caller demanded cache-only resolution (check_cache_only=True — typically under high load or DB outage) and the hashed token had no cache entry. It means the key was never seen (unknown/invalid token) or its cache entry expired and DB fallback is forbidden, so authentication fails without hitting the database; the hashed token is embedded for correlation.","triggerScenarios":"Thrown at litellm/proxy/auth/resolvers/store.py:111 when the library encounters an invalid state.","commonSituations":"The key was looked up with check_cache_only=True and was not present in the cache.","solutions":["Disable check_cache_only so the resolver can fall back to the database.","Warm the cache or reissue the key so it exists in cache."],"exampleFix":"Retry the request without check_cache_only=True, or restart the proxy to refresh its cache.","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}