Repository navigation
feat(ui): show daily token totals on the model leaderboard - #44044
Conversation
|
| labelFormatter={(label, payload) => | ||
| `${label} · Total ${formatMetric( | ||
| payload.reduce((sum, item) => sum + Number(item.value ?? 0), 0), | ||
| shown, | ||
| )}` |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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!
| 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(); | ||
| }); |
There was a problem hiding this comment.
…ust the top ranked ones
de7ca64 to
d6c8b65
Compare
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptile approve |
|
Approved. The follow-up now computes |
TLDR
Problem this solves:
How it solves it:
/model-insightsnow also returns per-day totals across every modelIntentional 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
Before screenshot (changed areas boxed in red):
After: the same admin sees one bar per day and the day's total token count
Gateway total 3.1B, and per-model counts for that single dayGateway total 147) while every charted model reads 0After screenshot (changed areas boxed in red):
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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@greptileaito 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 adminBefore (91ff045)
2026-09-24and per-model weekly counts with no total (see the Before screenshot in User Flow)After (788b6de)
2026-09-20 · Gateway total 3.1B(see the first After screenshot in User Flow)2026-10-01 · Gateway total 147while every charted model reads 0 (see the second After screenshot)Type
🆕 New Feature
Caveats (if any)
Low
/model-insightsruns one extra grouped query, by date only, over the same bounded windowFinal Attestation
🤖 Generated with Claude Code