diff --git a/litellm/proxy/spend_tracking/spend_management_endpoints.py b/litellm/proxy/spend_tracking/spend_management_endpoints.py index d030fabe8b5..c0cd462d153 100644 --- a/litellm/proxy/spend_tracking/spend_management_endpoints.py +++ b/litellm/proxy/spend_tracking/spend_management_endpoints.py @@ -2200,6 +2200,8 @@ async def ui_view_request_response_for_request_id( "/spend/logs", tags=["Budget & Spend Tracking"], dependencies=[Depends(user_api_key_auth)], + deprecated=True, + summary="Deprecated: use /spend/logs/ui for paginated spend logs", responses={ 200: {"model": List[LiteLLM_SpendLogs]}, }, @@ -2233,7 +2235,7 @@ async def view_spend_logs( # noqa: PLR0915 ): """ [DEPRECATED] This endpoint is not paginated and can cause performance issues. - Please use `/spend/logs/v2` instead for paginated access to spend logs. + Please use `/spend/logs/ui` instead for paginated access to spend logs. View all spend logs, if request_id is provided, only logs for that request_id will be returned @@ -2241,34 +2243,14 @@ async def view_spend_logs( # noqa: PLR0915 - summarize=true (default): Returns aggregated spend data grouped by date (maintains backward compatibility) - summarize=false: Returns filtered individual log entries within the date range - Example Request for all logs + Recommended paginated UI spend logs request: ``` - curl -X GET "http://0.0.0.0:8000/spend/logs" \ --H "Authorization: Bearer sk-1234" - ``` - - Example Request for specific request_id - ``` - curl -X GET "http://0.0.0.0:8000/spend/logs?request_id=chatcmpl-6dcb2540-d3d7-4e49-bb27-291f863f112e" \ --H "Authorization: Bearer sk-1234" - ``` - - Example Request for specific api_key - ``` - curl -X GET "http://0.0.0.0:8000/spend/logs?api_key=sk-test-example-key-123" \ --H "Authorization: Bearer sk-1234" - ``` - - Example Request for specific user_id - ``` - curl -X GET "http://0.0.0.0:8000/spend/logs?user_id=ishaan@berri.ai" \ --H "Authorization: Bearer sk-1234" - ``` - - Example Request for date range with individual logs (unsummarized) - ``` - curl -X GET "http://0.0.0.0:8000/spend/logs?start_date=2024-01-01&end_date=2024-01-02&summarize=false" \ --H "Authorization: Bearer sk-1234" + curl -G "http://0.0.0.0:4000/spend/logs/ui" \ + -H "Authorization: Bearer " \ + --data-urlencode "start_date=2024-01-01 00:00:00" \ + --data-urlencode "end_date=2024-01-02 00:00:00" \ + --data-urlencode "page=1" \ + --data-urlencode "page_size=50" ``` """ from litellm.proxy.proxy_server import prisma_client diff --git a/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py b/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py index 4bcabfe853a..6b8d28cc60a 100644 --- a/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py +++ b/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py @@ -127,6 +127,20 @@ async def test_is_admin_view_safe_false(): assert spend_management_endpoints._is_admin_view_safe(auth) is False +def test_legacy_spend_logs_openapi_points_to_ui_endpoint(client): + response = client.get("/openapi.json") + assert response.status_code == 200 + + operation = response.json()["paths"]["/spend/logs"]["get"] + description = operation.get("description", "") + + assert operation.get("deprecated") is True + assert "/spend/logs/ui" in description + assert "curl -G" in description + assert "page_size=50" in description + assert 'curl -X GET "http://0.0.0.0:8000/spend/logs"' not in description + + @pytest.mark.asyncio async def test_is_admin_view_safe_exception(): # Ensure exceptions are swallowed and return False