Skip to content

Add summarize parameter to /spend/logs API for individual transaction logs #11556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

colesmcintosh
Copy link
Collaborator

@colesmcintosh colesmcintosh commented Jun 9, 2025

Title

Add summarize parameter to /spend/logs API for individual transaction logs

Relevant issues

Fixes #11449

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

New Feature

Changes

Problem Solved

The /spend/logs API had inconsistent behavior when using date filters:

  • Without date filters: Returned individual log entries (expected)
  • With date filters: Returned summarized/aggregated data (unexpected)

This made it difficult to extract raw transaction data for analytics dashboards when filtering by date range.

Solution Implementation

Added a new summarize parameter to the /spend/logs endpoint with non-breaking behavior:

API Changes (litellm/proxy/spend_tracking/spend_management_endpoints.py)

  • Added summarize: bool = True parameter with default value for backward compatibility
  • Modified logic to return individual logs when summarize=False and date filters are provided
  • Maintained existing summarized behavior when summarize=True (default)

New Functionality

  • summarize=true (default): Returns aggregated data grouped by date (legacy behavior)
  • summarize=false: Returns filtered individual transaction logs within date range

Examples

# Get individual transaction logs (NEW)
curl -X GET "http://localhost:4000/spend/logs?start_date=2024-01-01&end_date=2024-01-02&summarize=false" \
-H "Authorization: Bearer sk-1234"

# Get summarized data (EXISTING - unchanged)
curl -X GET "http://localhost:4000/spend/logs?start_date=2024-01-01&end_date=2024-01-02" \
-H "Authorization: Bearer sk-1234"

Testing (tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py)

  • Added comprehensive test test_view_spend_logs_summarize_parameter()
  • Tests both summarize=True and summarize=False scenarios
  • Verified all existing tests still pass (no regressions)
Screenshot 2025-06-18 at 2 41 21 PM

Documentation (docs/my-website/docs/proxy/cost_tracking.md)

  • Added concise section explaining the new parameter
  • Provided practical examples for both use cases
  • Clear guidance on when to use each mode

Use Cases Enabled

  • Analytics Dashboards: Extract complete transaction metadata with summarize=false
  • ETL Processes: Get unsummarized data for data warehouses and BI tools
  • Audit & Compliance: Detailed transaction logs for specific time periods
  • Legacy Reports: Maintain existing summarized behavior for backward compatibility

Backward Compatibility

Fully backward compatible - existing integrations continue working unchanged since summarize=True is the default value.

…transaction logs

- Introduced a new `summarize` parameter to control data format when querying spend logs.
- `summarize=true` (default) returns aggregated data, while `summarize=false` provides individual transaction logs.
- Updated documentation and added tests to validate the new functionality.
Copy link

vercel bot commented Jun 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2025 4:51pm

@colesmcintosh colesmcintosh marked this pull request as ready for review June 9, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Spend Logs API Filter should maintain same response schema when date range filters are given
1 participant