Skip to content

[Bug]: /spend/logs (DailySpend table) returns inflated spend totals that diverge from /spend/keys and dashboard #25351

@Zetaphor

Description

@Zetaphor

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:

Source Total 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:

Source 30-day Spend
/global/spend/logs (SpendLogs) $53.50
/spend/logs (DailySpend) $41.13
Ratio 0.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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions