{"record":{"id":"aabb13f6452cc6c8","repo":"BerriAI/litellm","slug":"not-found-error","errorCode":"not_found_error","errorMessage":"Key not found in database","messagePattern":"Key not found in database","errorType":"http","errorClass":"ProxyException","httpStatus":404,"severity":"error","filePath":"litellm/proxy/management_endpoints/key_management_endpoints.py","lineNumber":3675,"sourceCode":"    from litellm.proxy.proxy_server import prisma_client, user_api_key_cache\n\n    try:\n        if prisma_client is None:\n            raise Exception(\n                \"Database not connected. Connect a database to your proxy - https://docs.litellm.ai/docs/simple_proxy#managing-auth---virtual-keys\"\n            )\n\n        # default to using Auth token if no key is passed in\n        key = key or user_api_key_dict.api_key\n        hashed_key: str | None = key\n        if key is not None:\n            hashed_key = _hash_token_if_needed(token=key)\n        key_info = await VerificationTokenRepository(prisma_client).table.find_unique(\n            where={\"token\": hashed_key},\n            include={\"litellm_budget_table\": True},\n        )\n        if key_info is None:\n            raise ProxyException(\n                message=\"Key not found in database\",\n                type=ProxyErrorTypes.not_found_error,\n                param=\"key\",\n                code=status.HTTP_404_NOT_FOUND,\n            )\n\n        if (\n            await _can_user_query_key_info(\n                user_api_key_dict=user_api_key_dict,\n                key=key,\n                key_info=key_info,\n            )\n            is not True\n        ):\n            raise HTTPException(\n                status_code=status.HTTP_403_FORBIDDEN,\n                detail=f\"You are not allowed to access this key's info. Your role={user_api_key_dict.user_role}\",\n            )","sourceCodeStart":3657,"sourceCodeEnd":3693,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/key_management_endpoints.py#L3657-L3693","documentation":"GET /key/info looked up the (hashed) key token via find_unique on the verification-token table and got no row. The key may have been deleted, expired keys still return rows (expiry is checked elsewhere), so 'not found' specifically means no such token exists in the DB — including when you passed the raw token while the DB stores hashes handled by _hash_token_if_needed (that case is normalized), so the usual causes are deletion or a wrong/foreign key value. Returned as a typed ProxyException with code not_found_error and HTTP 404.","triggerScenarios":"GET /key/info?key=sk-typo or a key deleted via /key/delete; querying with an alias string instead of the token; querying a key generated on a different proxy/database.","commonSituations":"Dashboard caching a key list after an admin purged keys; copy-paste truncating the token; pointing a client at the wrong environment's proxy; key rotated by an async job between listing and lookup.","solutions":["Re-list live keys (GET /key/info without key for your own key, or admin batch /v2/key/info) and use a current token.","If querying by human-friendly name, pass key_alias via /v2/key/info instead of the raw token value.","Confirm you're hitting the right proxy host/database for that key."],"exampleFix":"# before\ninfo = client.get(\"/key/info\", params={\"key\": \"sk-copied-wrong\"})\n\n# after\nresp = client.post(\"/v2/key/info\", json={\"key_aliases\": [\"my-alias\"]})\nif resp.status_code == 404:\n    log.warning(\"key no longer exists; refresh key list\")","handlingStrategy":"try-catch","validationCode":"def key_exists(client, key: str) -> bool:\n    resp = client.get(\"/key/info\", params={\"key\": key})\n    return resp.status_code == 200","typeGuard":null,"tryCatchPattern":"try:\n    info = client.get(\"/key/info\", params={\"key\": key})\n    info.raise_for_status()\nexcept HTTPError as e:\n    if e.response.status_code == 404:\n        evict_from_cache(key)   # deleted/rotated elsewhere\n        return None\n    raise","preventionTips":["Treat 404 on key info as an expected lifecycle event: evict from caches, don't retry.","Prefer key_alias lookups over raw tokens in dashboards so rotation doesn't break queries.","Pin clients to one environment's proxy URL to avoid querying keys that live in another DB."],"tags":["not-found","key-management","litellm-proxy"],"backgroundTag":"resource-not-found","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}