Skip to content

feat(ui): show daily token totals on the model leaderboard - #44044

Merged
ishaan-berri merged 14 commits into
mainfrom
litellm_model_leaderboard_daily_tokens
Oct 1, 2026
Merged

ishaan-berri merged 14 commits into
mainfrom
litellm_model_leaderboard_daily_tokens

Conversation

@ishaan-berri

@ishaan-berri ishaan-berri commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Model Leaderboard only charts weekly buckets
  • No way to read actual tokens used on a given day
  • Tooltip never shows the bucket's total

How it solves it:

  • Adds a Daily / Weekly toggle to the Top models chart, Daily by default
  • /model-insights now also returns per-day totals across every model
  • Tooltip header shows that gateway total, not just the charted top ten

Intentional product change: the Top models chart opens on daily bars instead of weekly ones. Weekly is one click away

User Flow

Before: an admin who wants to know how many tokens the gateway used yesterday can only see 7-day totals

  1. They open http://localhost:4000/ui/?page=model-insights with the Tokens tab selected
  2. The chart says "Weekly tokens across your gateway" and has only Linear / Log toggles
  3. Hovering a bar shows a week start date and per-model counts for the whole week, with no total

Before screenshot (changed areas boxed in red):

Before: weekly bars only, tooltip header is just a week start date

After: the same admin sees one bar per day and the day's total token count

  1. They open http://localhost:4000/ui/?page=model-insights with the Tokens tab selected
  2. The chart says "Daily tokens across your gateway" and has a new Daily / Weekly toggle, Daily selected
  3. Hovering a bar shows that day's date, Gateway total 3.1B, and per-model counts for that single day
  4. On a day where only models outside the top ten ran, the header still shows the real total (Gateway total 147) while every charted model reads 0
  5. Clicking Weekly brings back the old weekly bars, also with the gateway total in the tooltip

After screenshot (changed areas boxed in red):

After: daily bars, Daily / Weekly toggle, tooltip header shows the day and its gateway total

After: on 2026-10-01 only models outside the top ten ran, and the header still reports Gateway total 147

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/unit/<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)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Setup: proxy from this branch on localhost:41926 (4000 was taken by another local proxy) (litellm/proxy/dev_config.yaml) against a Postgres that already had a year of per-model daily usage rows, Admin UI dev server on localhost:3001, logged in as the env admin

Before (91ff045)

  1. Open http://localhost:3001/model-insights, Tokens tab
  2. The chart shows weekly bars only. Hovering the last full week shows 2026-09-24 and per-model weekly counts with no total (see the Before screenshot in User Flow)

After (788b6de)

  1. The API now returns gateway-wide totals. On 2026-10-01 only three models outside the year's top ten ran (two real gpt-4o-mini calls plus earlier failed Anthropic calls), so the top-ten rows are empty but the total is not
$ curl -s "localhost:41926/model-insights?metric=tokens" -H "Authorization: Bearer $KEY" \
    | jq '{top_ten_rows_on_oct_1: [.daily[] | select(.date=="2026-10-01")], gateway_total_on_oct_1: [.daily_totals[] | select(.date=="2026-10-01") | .prompt_tokens + .completion_tokens]}'
{
  "top_ten_rows_on_oct_1": [],
  "gateway_total_on_oct_1": [147]
}
  1. Open http://localhost:3001/model-insights, Tokens tab. The chart shows one bar per day with Daily selected. Hovering 2026-09-20 shows 2026-09-20 · Gateway total 3.1B (see the first After screenshot in User Flow)
  2. Hovering 2026-10-01 shows 2026-10-01 · Gateway total 147 while every charted model reads 0 (see the second After screenshot)
  3. Clicking Weekly switches back to 7-day bars, and the subtitle changes to "Weekly tokens across your gateway"

Type

🆕 New Feature

Caveats (if any)

Low

  • A full year of daily bars is dense, so bars are thin at the default range
  • The leaderboard share and delta below the chart are unchanged and still cover the whole period
  • /model-insights runs one extra grouped query, by date only, over the same bounded window

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

🤖 Generated with Claude Code

@ishaan-berri
ishaan-berri requested a review from a team October 1, 2026 17:52
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adds daily granularity option to the model insights chart.

The PR should not merge until the daily tooltip stops presenting a top-ten subtotal as the gateway total.

Findings

  1. P1 Total excludes other models ▶
  2. P2 Daily bars are too dense ▶
  3. P2 Tooltip total is untested ▶

Summary

The PR adds daily-by-default buckets, a Daily/Weekly chart toggle, and a formatted tooltip total.

  • Daily and weekly aggregation are covered by data-level tests.
  • The displayed total excludes models outside the backend’s top-ten selection, and the default year-long daily chart is difficult to inspect.
  • The tooltip output itself is not asserted by the new view test.

Reviews (1) · Last reviewed commit: "test(ui): cover the daily/weekly toggle ..."

Comment on lines +269 to +273
labelFormatter={(label, payload) =>
`${label} · Total ${formatMetric(
payload.reduce((sum, item) => sum + Number(item.value ?? 0), 0),
shown,
)}`

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.

P1 Total excludes other models

When a gateway has more than ten models, /model-insights supplies daily rows only for the top ten. This tooltip labels their sum “Total,” so an admin checking yesterday’s gateway token usage sees an undercount. Include the omitted usage or label the figure as the total for the displayed models.

const [loaded, setLoaded] = React.useState<{ metric: Metric; response: ModelInsightsResponse } | null>(null);
const [metric, setMetric] = React.useState<Metric>("tokens");
const [scale, setScale] = React.useState<Scale>("linear");
const [granularity, setGranularity] = React.useState<Granularity>("day");

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.

P2 Daily bars are too dense

The default response covers 365 days, so opening the chart now fits 365 daily categories into the same width that previously held about 53 weekly categories. At ordinary dashboard widths, the bars become hard to see or hover, making the new default view difficult to use. A shorter daily window or another way to inspect individual days would help.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +153 to +168
it("charts one bar per day by default and switches to weekly bars", async () => {
render(<ModelInsightsView accessToken="token" />);
await screen.findByText("fast-chat");
const chart = screen.getByTestId("usage-chart");
const days = (Date.parse(response.end_date) - Date.parse(response.start_date)) / 86_400_000 + 1;

expect(screen.getByRole("tab", { name: "Daily" })).toHaveAttribute("aria-selected", "true");
expect(chart).toHaveAttribute("data-buckets", String(days));
expect(screen.getByText("Daily tokens across your gateway")).toBeInTheDocument();

await userEvent.click(screen.getByRole("tab", { name: "Weekly" }));

expect(chart).toHaveAttribute("data-buckets", String(Math.ceil(days / 7)));
expect(chart).toHaveAttribute("data-first", response.start_date);
expect(screen.getByText("Weekly tokens across your gateway")).toBeInTheDocument();
});

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.

P2 Tooltip total is untested

This test checks bucket counts and subtitles, but both tooltip components are mocked to null. A wrong total or metric in the new tooltip would therefore leave the tests green. Assert the displayed date and total using a representative multi-model payload.

@ishaan-berri
ishaan-berri force-pushed the litellm_model_leaderboard_daily_tokens branch from de7ca64 to d6c8b65 Compare October 1, 2026 18:14
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ishaan-berri

Copy link
Copy Markdown
Contributor Author

@greptile approve

@greptile-apps

greptile-apps Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Approved. The follow-up now computes daily_totals with an unfiltered date-only aggregation, so the tooltip’s gateway total includes models outside the ranked top ten. Daily and weekly bucket alignment is covered by the data tests, and the view test verifies the daily default plus weekly toggle. The remaining density trade-off is intentional and documented in the PR.

@codspeed

codspeed Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_model_leaderboard_daily_tokens (788b6de) with main (259c166)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (a76b59d) during the generation of this report, so 259c166 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@ishaan-berri
ishaan-berri enabled auto-merge (squash) October 1, 2026 19:07
@ishaan-berri
ishaan-berri merged commit fcf8797 into main Oct 1, 2026
98 of 101 checks passed
@ishaan-berri
ishaan-berri deleted the litellm_model_leaderboard_daily_tokens branch October 1, 2026 19:12
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.

3 participants