{"record":{"id":"5dab48393cfad261","repo":"BerriAI/litellm","slug":"global-spend-logs-error-user-id-is-none","errorCode":null,"errorMessage":"/global/spend/logs Error: User ID is None","messagePattern":"/global/spend/logs Error: User ID is None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/proxy/spend_tracking/spend_management_endpoints.py","lineNumber":3193,"sourceCode":"\n\nasync def global_spend_for_internal_user(\n    api_key: str | None = None,\n    user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),\n):\n    from litellm.proxy.proxy_server import prisma_client\n\n    if prisma_client is None:\n        raise ProxyException(\n            message=\"Prisma Client is not initialized\",\n            type=\"internal_error\",\n            param=\"None\",\n            code=status.HTTP_500_INTERNAL_SERVER_ERROR,\n        )\n    try:\n        user_id: Final = user_api_key_dict.user_id\n        if user_id is None:\n            raise ValueError(\"/global/spend/logs Error: User ID is None\")\n        if api_key is not None:\n            sql_query = \"\"\"\n                SELECT * FROM \"MonthlyGlobalSpendPerUserPerKey\"\n                WHERE \"api_key\" = $1 AND \"user\" = $2\n                ORDER BY \"date\";\n                \"\"\"\n\n            response: Sequence[Mapping[str, object]] = await _query_raw(prisma_client, sql_query, api_key, user_id)\n\n            return response\n\n        sql_query = \"\"\"SELECT * FROM \"MonthlyGlobalSpendPerUserPerKey\"  WHERE \"user\" = $1 ORDER BY \"date\";\"\"\"\n\n        response = await _query_raw(prisma_client, sql_query, user_id)\n\n        return response\n    except Exception as e:\n        verbose_proxy_logger.error(\"/global/spend/logs Error: %s\", e)","sourceCodeStart":3175,"sourceCodeEnd":3211,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/spend_tracking/spend_management_endpoints.py#L3175-L3211","documentation":"Error \"/global/spend/logs Error: User ID is None\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/proxy/spend_tracking/spend_management_endpoints.py:3193 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Authenticate with a valid virtual key or user session so a user_id is resolved before calling /global/spend/logs.","If calling programmatically, include the Authorization header with a valid 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-14T05:17:10.506Z"}