Skip to content

feat(usage): cursor pagination for the aggregated key breakdown - #43195

Closed
devin-ai-integration[bot] wants to merge 12 commits into
mainfrom
litellm_usage_cursor_pagination
Closed

devin-ai-integration[bot] wants to merge 12 commits into
mainfrom
litellm_usage_cursor_pagination

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • /user/daily/activity/aggregated and /team/daily/activity/aggregated accept cursor
  • Response metadata.next_cursor is a keyset cursor on (spend, key), null on the last page
  • Each page still costs one bounded query of 100 keys, nothing is loaded eagerly
  • Malformed cursors return 400 "Invalid cursor"
  • Global Usage and Team Usage key panels get a "Load more keys" button that appends the next page

This is the pagination half of #42836, rebased on top of the merged search PRs

User Flow

Before: an admin with 340 keys can only ever see the top 100 in the Usage page or the API

  1. They open https://litellm-domain/ui/?page=usage and the Key Activity panel
  2. The note reads "Only the 100 highest-spend keys of 340 are loaded" with nothing to click
  3. GET https://litellm-domain/user/daily/activity/aggregated?start_date=...&end_date=... returns the same 100 keys on every call

After: the same admin walks through all 340 keys one page at a time

  1. They open https://litellm-domain/ui/?page=usage and the Key Activity panel
  2. The count reads "Showing 100 of 340 keys" next to a "Load more keys" button (the old truncation note is gone)
  3. Clicking it appends the next 100 keys and the count updates to 200 of 340; after the last page the button disappears
  4. GET https://litellm-domain/user/daily/activity/aggregated?start_date=...&end_date=... now returns metadata.next_cursor; passing it back as cursor=... returns the next 100 keys, until next_cursor is null

Local run against a proxy seeded with 105 keys, first page and after "Load more keys" (recording in the Slack thread linked from the session; taken before the note was folded into the count):

Key Activity panel with 100 of 105 keys loaded and the Load more keys button

Key Activity panel after Load more keys with all 105 keys loaded

Pre-Submission checklist

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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Type

🆕 New Feature

Caveats (if any)

Low

  • Page totals (total_spend, total_api_keys) are repeated on every page, not per page
  • A key whose spend changes between page requests can appear twice or be skipped; the UI merge dedupes by key
  • Every page reruns the key-free rollup and the per-entity totals, which the UI discards after page one; a slimmer follow-up query for later pages can drop that if it shows up in latency

Link to Devin session: https://app.devin.ai/sessions/ec188efd8ecc4cd69f8351cce1e2fe86
Open in Devin Desktop: https://app.devin.ai/desktop/session/ec188efd8ecc4cd69f8351cce1e2fe86?variant=devin
Requested by: @kerry-berri


Note

Medium Risk
Changes spend analytics SQL and new query parameters on admin usage endpoints; bounded pages limit blast radius, but incorrect cursor/keyset logic could skip or duplicate keys in the UI.

Overview
Adds cursor-based pagination for the per-key slice of aggregated daily usage so admins can load more than the top 100 keys without one huge response.

API: /user/daily/activity/aggregated and /team/daily/activity/aggregated accept an optional cursor query param. Responses include metadata.next_cursor (opaque keyset on spend + api_key); invalid cursors return 400. The aggregated SQL ranks keys by spend and applies the cursor before the existing USAGE_TOP_API_KEYS_LIMIT cap; global totals and non-key rollups stay full-range.

UI: Global Usage and Team Usage Key Activity show “Showing N of M keys”, a Load more keys control that passes the cursor and merges the next page into breakdowns via mergeKeyPage, and updated networking helpers. OpenAPI snapshot and TypeScript schema reflect next_cursor and cursor.

Reviewed by Cursor Bugbot for commit 014c868. Bugbot is set up for automated code reviews on this repo. Configure here.

kerry-berri and others added 7 commits September 25, 2026 18:38
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

CLAassistant commented Sep 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds cursor-based pagination to usage analytics endpoints.

The PR appears safe to merge; no new actionable issue or outstanding previous finding remains

Summary

The PR adds cursor pagination to aggregated per-key usage and Load more keys controls to the Global Usage and Team Usage panels. The changes since the previous review replace mutations in the page-merge helper with immutable construction

Reviews (5) · Last reviewed commit: "refactor(usage): build the merged key pa..."

@greptile-apps

This comment has been minimized.

@codspeed

codspeed Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_usage_cursor_pagination (014c868) with main (6b76888)

Open in CodSpeed

@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 014c868. Configure here.

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.

2 participants