litellm - 💡(How to fix) Fix [Bug]: /spend/logs (DailySpend table) returns inflated spend totals that diverge from /spend/keys and dashboard [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#25351Fetched 2026-04-09 07:52:35
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
labeled ×1

Code Example

API_KEY="your-master-key"

# 1. Get the authoritative total from per-key spend
curl -s -H "Authorization: Bearer $API_KEY" \
  "http://localhost:4000/spend/keys" | \
  python3 -c "import sys,json; d=json.load(sys.stdin); print(f'spend/keys sum: \${sum(k.get(\"spend\",0) or 0 for k in d):.4f}')"

# 2. Get the DailySpend total
curl -s -H "Authorization: Bearer $API_KEY" \
  "http://localhost:4000/spend/logs?start_date=2020-01-01&end_date=2030-01-01" | \
  python3 -c "import sys,json; d=json.load(sys.stdin); print(f'spend/logs sum: \${sum(e.get(\"spend\",0) or 0 for e in d):.4f}')"

# 3. Compare — these should be close but likely won't be
RAW_BUFFERClick to expand / collapse

Note: This was automatically submitted by my agent at my request.

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

The /spend/logs endpoint (backed by the DailySpend table) returns spend totals that are significantly higher than both the /spend/keys sum and the LiteLLM admin dashboard's "Total Spend" figure. All three should agree, but they diverge by ~3x for all-time queries.

Observed values for the same all-time period:

SourceTotal Spend
LiteLLM Admin Dashboard ("Project Spend")$82.92
GET /spend/keys (sum of per-key spend)$82.86
GET /global/spend$53.47 (only ~30 days retained)
GET /global/spend/logs (sum of daily entries)$53.50 (only ~30 days retained)
GET /spend/logs (sum of spend field across entries)$253.58
GET /spend/logs (sum of per-model values in models dicts)$253.58

The dashboard and /spend/keys agree ($82.9). The SpendLogs-backed endpoints agree ($53.5, limited by ~30-day retention). But the DailySpend-backed /spend/logs reports $253.58 — roughly 3x the authoritative total.

The inflation is also not uniform across time. Comparing the same 30-day window (Mar 9 – Apr 8) where SpendLogs data is available:

Source30-day Spend
/global/spend/logs (SpendLogs)$53.50
/spend/logs (DailySpend)$41.13
Ratio0.77 (DailySpend is lower)

So for recent data, DailySpend under-reports (ratio 0.77), while for all-time data it massively over-reports (ratio 3.06). The inconsistency makes it impossible to apply a simple correction factor.

Impact

Any API consumer using /spend/logs to compute spend totals or per-model breakdowns will get incorrect values. The models dict within each entry (which is the only API source for per-model spend breakdown across all time) inherits this inflation.

This is distinct from:

  • #21894 (DailyTagSpend inflation from jsonb_array_elements_text)
  • #22176 (off-by-one date range in UI)
  • #10876 (dashboard views showing different totals)

Steps to Reproduce

API_KEY="your-master-key"

# 1. Get the authoritative total from per-key spend
curl -s -H "Authorization: Bearer $API_KEY" \
  "http://localhost:4000/spend/keys" | \
  python3 -c "import sys,json; d=json.load(sys.stdin); print(f'spend/keys sum: \${sum(k.get(\"spend\",0) or 0 for k in d):.4f}')"

# 2. Get the DailySpend total
curl -s -H "Authorization: Bearer $API_KEY" \
  "http://localhost:4000/spend/logs?start_date=2020-01-01&end_date=2030-01-01" | \
  python3 -c "import sys,json; d=json.load(sys.stdin); print(f'spend/logs sum: \${sum(e.get(\"spend\",0) or 0 for e in d):.4f}')"

# 3. Compare — these should be close but likely won't be

Expected behavior

/spend/logs spend totals should be consistent with /spend/keys and the admin dashboard's "Project Spend" for the same time range.

Relevant log output

No response

What part of LiteLLM is this about?

Proxy, Spend Tracking

What LiteLLM version are you on?

v1.81.12 (ghcr.io/berriai/litellm:main-stable)

Twitter / LinkedIn details

No response

extent analysis

TL;DR

The /spend/logs endpoint's spend totals are inconsistent with other sources, suggesting a data inconsistency or calculation issue in the DailySpend table or its querying logic.

Guidance

  • Investigate the data in the DailySpend table to identify any inconsistencies or anomalies that could be causing the inflated spend totals.
  • Compare the querying logic for /spend/logs and /spend/keys to ensure that they are calculating spend totals in the same way.
  • Check for any recent changes to the DailySpend table or its querying logic that could be contributing to the issue.
  • Consider running a query to reconcile the spend totals from the DailySpend table with those from the SpendLogs table to identify any discrepancies.

Example

No specific code example is provided, but the issue includes example curl commands and Python scripts to reproduce the issue, which could be used as a starting point for further investigation.

Notes

The issue is specific to the /spend/logs endpoint and the DailySpend table, and does not appear to be related to other known issues. The inconsistent spend totals suggest a data or calculation issue, but further investigation is needed to determine the root cause.

Recommendation

Apply a workaround by using the /spend/keys endpoint or the admin dashboard's "Project Spend" figure as the authoritative source for spend totals, until the issue with the DailySpend table or its querying logic can be resolved.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

/spend/logs spend totals should be consistent with /spend/keys and the admin dashboard's "Project Spend" for the same time range.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING