{"record":{"id":"0cf906a25772564d","repo":"BerriAI/litellm","slug":"not-authorized-to-view-spend-for-another-user","errorCode":null,"errorMessage":"Not authorized to view spend for another user.","messagePattern":"Not authorized to view spend for another user\\.","errorType":"http","errorClass":"HTTPException","httpStatus":403,"severity":"error","filePath":"litellm/proxy/spend_tracking/spend_management_endpoints.py","lineNumber":353,"sourceCode":"    ```\n    curl -X GET \"http://0.0.0.0:8000/spend/users?user_id=1234\" \\\n-H \"Authorization: Bearer sk-1234\"\n    ```\n    \"\"\"\n    from litellm.proxy.proxy_server import prisma_client\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        if not _is_admin_view_safe(user_api_key_dict=user_api_key_dict):\n            caller_user_id: Final = user_api_key_dict.user_id\n            if not caller_user_id:\n                return []\n            if user_id is not None and user_id != caller_user_id:\n                raise HTTPException(\n                    status_code=status.HTTP_403_FORBIDDEN,\n                    detail={\"error\": \"Not authorized to view spend for another user.\"},\n                )\n            user_id = caller_user_id\n\n        if user_id is not None:\n            user_info = await prisma_client.get_data(table_name=\"user\", query_type=\"find_unique\", user_id=user_id)\n            result = [user_info]\n        else:\n            user_info = await prisma_client.get_data(table_name=\"user\", query_type=\"find_all\")\n            result = user_info\n\n        _strip_password_from_users(result)\n        return result\n\n    except HTTPException:\n        raise\n    except Exception as e:","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/spend_tracking/spend_management_endpoints.py#L335-L371","documentation":"Error \"Not authorized to view spend for another user.\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/proxy/spend_tracking/spend_management_endpoints.py:353 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Query spend only for your own user_id, or use a proxy admin key to view other users' spend."],"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"}