{"record":{"id":"9346af8abe655978","repo":"BerriAI/litellm","slug":"only-proxy-admin-roles-can-view-tool-spend-across","errorCode":null,"errorMessage":"Only proxy admin roles can view tool spend across the deployment","messagePattern":"Only proxy admin roles can view tool spend across the deployment","errorType":"http","errorClass":"HTTPException","httpStatus":403,"severity":"error","filePath":"litellm/proxy/management_endpoints/tool_management_endpoints.py","lineNumber":264,"sourceCode":"\n    Reads the ``LiteLLM_DailyToolSpend`` rollup, written at request time from invoked\n    tools only (MCP tool calls and response tool_calls; declaring a tool without\n    invoking it does not count). A request that invoked multiple tools counts its\n    full spend toward each of them, so per-tool numbers are attributions and do not\n    sum to a deduplicated total.\n\n    ``by_tool`` is the top ``TOOL_SPEND_TOP_TOOLS`` tools by spend, aggregated in\n    SQL, and ``daily`` covers only those tools, so the response is bounded by\n    days x TOOL_SPEND_TOP_TOOLS regardless of the requested range or how many\n    distinct tool names exist.\n    \"\"\"\n    from litellm.proxy.proxy_server import prisma_client\n\n    if user_api_key_dict.user_role not in (\n        LitellmUserRoles.PROXY_ADMIN,\n        LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY,\n    ):\n        raise HTTPException(\n            status_code=403,\n            detail=\"Only proxy admin roles can view tool spend across the deployment\",\n        )\n\n    if prisma_client is None:\n        raise HTTPException(status_code=500, detail=CommonProxyErrors.db_not_connected_error.value)\n\n    end_day: Final = _parse_day_start(end_date) or datetime.now(timezone.utc)\n    start_day: Final = _parse_day_start(start_date) or end_day - timedelta(days=30)\n    start_str: Final = start_day.strftime(\"%Y-%m-%d\")\n    end_str: Final = end_day.strftime(\"%Y-%m-%d\")\n    date_window: Final = {\"date\": {\"gte\": start_str, \"lte\": end_str}}\n\n    table: Final = _typed_table(DailyToolSpendRepository(prisma_client))\n    top_tools: Final = _TOP_TOOL_ROWS.validate_python(\n        await table.group_by(\n            by=[\"tool_name\"],\n            sum={\"spend\": True, \"total_tokens\": True, \"request_count\": True},","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/tool_management_endpoints.py#L246-L282","documentation":"Error \"Only proxy admin roles can view tool spend across the deployment\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/proxy/management_endpoints/tool_management_endpoints.py:264 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call this endpoint with a PROXY_ADMIN 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"}