{"record":{"id":"5a4f95bfb69ffedc","repo":"BerriAI/litellm","slug":"not-authorized-to-view-spend-log-for-request-id-r","errorCode":null,"errorMessage":"Not authorized to view spend log for request_id={request_id}","messagePattern":"Not authorized to view spend log for request_id=(.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":403,"severity":"error","filePath":"litellm/proxy/spend_tracking/spend_management_endpoints.py","lineNumber":4248,"sourceCode":"    Raises HTTP 403 if not.\n    \"\"\"\n    row: Final = await _find_spend_log_row(prisma_client, request_id)\n    if row is None:\n        return\n\n    if row.user is not None and row.user == user_api_key_dict.user_id:\n        return\n\n    if row.team_id:\n        can_view: Final = await _can_team_member_view_log(\n            prisma_client=prisma_client,\n            user_api_key_dict=user_api_key_dict,\n            team_id=row.team_id,\n        )\n        if can_view:\n            return\n\n    raise HTTPException(\n        status_code=status.HTTP_403_FORBIDDEN,\n        detail={\"error\": f\"Not authorized to view spend log for request_id={request_id}\"},\n    )\n\n\nasync def _get_permitted_team_ids_for_spend_logs(\n    prisma_client: PrismaClient,\n    user_api_key_dict: UserAPIKeyAuth,\n) -> list[str]:\n    \"\"\"\n    Return team IDs where the user is either a team admin or has the\n    ``/spend/logs`` permission, allowing them to view team-wide spend logs.\n    \"\"\"\n    # Imported here to avoid circular import: proxy_server imports this module.\n    from litellm.proxy.auth.auth_checks import get_user_object\n    from litellm.proxy.management_endpoints.common_utils import (\n        _is_user_team_admin,\n        _team_member_has_permission,","sourceCodeStart":4230,"sourceCodeEnd":4266,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/spend_tracking/spend_management_endpoints.py#L4230-L4266","documentation":"Error \"Not authorized to view spend log for request_id={request_id}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/proxy/spend_tracking/spend_management_endpoints.py:4248 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a key/user that owns the given request_id, or a proxy admin key, to view its spend log.","Confirm the request_id belongs to your team or key."],"exampleFix":null,"handlingStrategy":null,"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-14T00:17:10.932Z"}