{"record":{"id":"c573e996a17f3611","repo":"BerriAI/litellm","slug":"key-health-check-failed-e","errorCode":null,"errorMessage":"Key health check failed: {e}","messagePattern":"Key health check failed: (.+?)","errorType":"http","errorClass":"ProxyException","httpStatus":500,"severity":"error","filePath":"litellm/proxy/management_endpoints/key_management_endpoints.py","lineNumber":6493,"sourceCode":"        )\n\n        # Check if logging is configured in metadata\n        if key_metadata and \"logging\" in key_metadata:\n            logging_statuses: Final = await test_key_logging(\n                user_api_key_dict=user_api_key_dict,\n                request=request,\n                key_logging=decrypt_callback_vars(key_metadata)[\"logging\"],\n            )\n            health_status[\"logging_callbacks\"] = logging_statuses\n\n            # Check if any logging callback is unhealthy\n            if logging_statuses.get(\"status\") == \"unhealthy\":\n                health_status[\"key\"] = \"unhealthy\"\n\n        return KeyHealthResponse(**health_status)\n\n    except Exception as e:\n        raise ProxyException(\n            message=f\"Key health check failed: {e}\",\n            type=ProxyErrorTypes.internal_server_error,\n            param=getattr(e, \"param\", \"None\"),\n            code=status.HTTP_500_INTERNAL_SERVER_ERROR,\n        )\n\n\nasync def _can_user_query_key_info(\n    user_api_key_dict: UserAPIKeyAuth,\n    key: str | None,\n    key_info: LiteLLM_VerificationToken,\n) -> bool:\n    \"\"\"\n    Helper to check if the user has access to the key's info\n    \"\"\"\n    if (\n        (\n            user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN.value","sourceCodeStart":6475,"sourceCodeEnd":6511,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/key_management_endpoints.py#L6475-L6511","documentation":"Catch-all wrapper around the key health-check endpoint (GET /key/health): any exception raised while building the health report — DB reads, decryption of key metadata, logging-callback probes — is re-raised as a 500 ProxyException whose message embeds the original error text. The proxy_logging/verbose logs carry the full traceback; the client only sees this summary.","triggerScenarios":"A malformed 'logging' entry in key metadata that blows up during callback status checks; database connectivity blips while fetching the key row; decryption failures on metadata encrypted with a different LITELLM_SALT_KEY; bugs in custom logging callbacks invoked during the probe request.","commonSituations":"Rotating the salt/encryption key after keys were created; custom callback classes that raise on init; transient Postgres restarts; upgrading LiteLLM versions where metadata schema changed.","solutions":["Read the nested message after the colon — it names the actual failure (e.g. 'callback_name is required in key_logging' or a Prisma error)","Check the proxy server logs at ERROR level for the full traceback of the same request","If the cause is key metadata, regenerate or update the key so its 'logging'/'metadata' JSON is well-formed","Fix the underlying dependency (DB connectivity, LITELLM_SALT_KEY, custom callback) and re-run the health check"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    r = await client.get('/key/health', params={'key': tok})\n    r.raise_for_status()\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code == 500:\n        inner = e.response.json().get('error', '')\n        if 'callback_name' in inner:\n            fix_key_logging_metadata(tok)      # data problem, fixable client-side\n        else:\n            page_on_caller('key health degraded', inner)  # infra problem; check proxy logs\n    raise","preventionTips":["Treat /key/health as advisory: alert on failures but keep request serving independent of it","Keep key metadata small and machine-generated to avoid malformed 'logging' entries","Correlate the 500 with server logs via request id before acting on the summarized message"],"tags":["health-check","internal-server-error","litellm-proxy","keys","wraps-cause"],"backgroundTag":"health-check-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}