Skip to content

fix(usage): preserve daily spend by public model - #42587

Closed
tin-berri wants to merge 1 commit into
mainfrom
litellm_daily_spend_model_group
Closed

tin-berri wants to merge 1 commit into
mainfrom
litellm_daily_spend_model_group

Conversation

@tin-berri

@tin-berri tin-berri commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Usage merges public model names sharing one deployment

How it solves it:

  • Keep each public model’s daily totals separate
  • Preserve stable PTU charges across model renames

Intentional product change: Usage shows N/A when there are no successful requests to average, and explains UTC daily totals

User Flow

Before: two public names can appear as one model in Usage

  1. Send POST https://litellm-domain/v1/chat/completions as the same key using direct-model, then alternate-model, backed by one deployment
  2. Open https://litellm-domain/ui/usage/ and select the request date
  3. One model row contains both requests; the other name is absent

After: Usage retains the separate public names and their totals

  1. Send the same two requests using direct-model and alternate-model
  2. Open https://litellm-domain/ui/usage/ and select the request date
  3. Each model row contains its own spend, tokens and requests

Relevant issues

  • Fix the daily model breakdown while preserving total spend
  • Keep the migration and PTU compatibility changes together
  • Evaluation billing is tracked independently in LIT-9199

Changes

  • Include model_group in all six daily queue, bulk-upsert and database identities
  • Synchronize three Prisma schemas and replace six unique indexes without rewriting historical rows
  • Preserve stable PTU IDs across renames and concurrent writes
  • Explain zero-request averages and UTC usage days in the dashboard

Linear ticket

Resolves LIT-9198

Pre-Submission checklist

  • Meaningful regressions: 94 added test lines / 97 implementation lines
  • 357 targeted Python tests and 61 dashboard tests pass independently
  • make check, discovery/shard guards and migration scanner pass locally
  • This PR addresses one defect and can merge independently
  • Fresh CI, coverage and reviews pending on this split commit

Type

Bug Fix

Caveats (if any)

Severe

  • Drain buffers and stop old writers before index replacement
  • Index construction blocks writes; schedule a maintenance window
  • Rollback requires reconciling rows before restoring old indexes

Medium

  • Historical merged model attribution cannot be reconstructed

Low

  • Fresh live proof is being captured on the split commit
  • Previous combined CI exposed unrelated dependency and ROI-fixture failures

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai Please review the current commit for attribution correctness, migration safety, and preservation of provisioned-throughput billing across renames

@tin-berri

tin-berri commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

bugbot run

Please review the current commit for daily usage attribution, database identity changes, and provisioned-throughput rename safety

@codspeed

codspeed Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_daily_spend_model_group (c6669ba) with main (5724117)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The reviewed changes appear safe to merge, with no outstanding previous findings or accepted new defects from the current-tip rebase.

Summary

This PR separates daily usage by public model group, preserves stable PTU charging identities, and attributes shadow-evaluation costs to the initiating administrator. It also updates the dashboard’s internal-usage presentation and supporting billing integrations.

  • Expands six daily-spend identities and matching bulk upserts to include model_group.
  • Projects shadow-router and judge-call billing onto the evaluation creator while retaining internal-call metadata.
  • Keeps PTU flat-cost rollups stable across public-model renames.
  • Updates usage and evaluation UI copy, dates, and unavailable-average rendering.
  • Adds regression coverage across spend queues, billing callbacks, evaluation ownership, PTU rollups, and dashboard components.

Reviews (8) · Last reviewed commit: "fix(usage): separate router costs and bi..."

@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.

@tin-berri

Copy link
Copy Markdown
Contributor Author

CodSpeed compared different CPUs and an older base. The resolver is unchanged; same-environment A/B measured 2.01µs versus 2.08µs, below its 10% threshold

@codecov

codecov Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tin-berri
tin-berri force-pushed the litellm_daily_spend_model_group branch from 0bbf28d to 1a2decb Compare September 22, 2026 21:43
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai Please review 1a2decb, including the corrected global rollup fixture and regression coverage proving legacy NULL/empty totals remain included

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

Please review 1a2decb; live usage APIs and added regression coverage confirm legacy NULL/empty totals remain included

@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.

@tin-berri

Copy link
Copy Markdown
Contributor Author

The same glibc CVE fails on main's unchanged base image. Resolving this requires upgrading the pinned base image separately

@tin-berri
tin-berri force-pushed the litellm_daily_spend_model_group branch from 1a2decb to 11a5b06 Compare September 22, 2026 23:34
@tin-berri tin-berri changed the title fix(usage): preserve model groups in daily spend aggregation fix(shadow-eval): charge evaluation spend to the initiating admin Sep 22, 2026
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai Please review the revised admin-owned evaluation accounting, including preserved routing identity, billing exports, and sidecar replay

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

Please review the revised evaluation billing ownership and confirm sampled-user accounting and routing remain correctly isolated

@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.

Comment thread litellm/litellm_core_utils/internal_call_metadata.py Outdated
Comment thread tests/test_litellm/integrations/test_shadow_eval_logger.py Outdated
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai Please review d5220d5: creator model budgets now load per sample, and the router test injects its observer before construction

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

Please review d5220d5 for creator budget ownership, refreshed configuration, deleted creators, and callback context propagation

@tin-berri

Copy link
Copy Markdown
Contributor Author

CodeQL 9134 flags existing API-token SHA256; passwords use salted scrypt. SARIF confirms the token path, and all 14 helper regressions pass

@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.

Comment thread litellm/litellm_core_utils/internal_call_metadata.py Outdated
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai Please review current tip 0197df1: tests now match implementation size, retaining creator ownership, production controls, and replay coverage

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

Please review current tip 0197df1; consolidated tests preserve ownership regressions, financial exports, creator budgets, and production controls

@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.

@tin-berri
tin-berri force-pushed the litellm_daily_spend_model_group branch from 0197df1 to 5015c2c Compare September 23, 2026 01:35
@tin-berri tin-berri changed the title fix(shadow-eval): charge evaluation spend to the initiating admin fix(usage): separate router costs and bill evaluations to admins Sep 23, 2026
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai Please review current tip 5015c2c for model group isolation, admin billing, coordinated migration, PTU rename safety and Usage clarity

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run
Please review 5015c2c for separate router accounting, initiating-admin ownership, migration compatibility, primary PTU reads and zero-request Usage displays

@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.

@tin-berri
tin-berri force-pushed the litellm_daily_spend_model_group branch from 5015c2c to e5deff1 Compare September 23, 2026 01:46
Comment thread litellm/proxy/auth/user_api_key_auth.py Outdated
@veria-ai

veria-ai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai Please review current tip e5deff1 after rebasing onto current main. The two conflicts combined test imports; 195 spend tests and 577 auto-router/logging tests pass. Daily public model grouping, PTU identity, and initiating-admin evaluation billing remain the scope. Fresh live replay and CI are running.

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

Please review current tip e5deff1 after the rebase.

@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 e5deff1. Configure here.

@tin-berri
tin-berri force-pushed the litellm_daily_spend_model_group branch from 93157d3 to c6669ba Compare October 3, 2026 07:34
@tin-berri tin-berri changed the title fix(usage): separate router costs and bill evaluations to admins fix(usage): preserve daily spend by public model Oct 3, 2026
@tin-berri tin-berri closed this Oct 3, 2026
@tin-berri

Copy link
Copy Markdown
Contributor Author

Superseded by #44357 for public-model usage. Evaluation billing is isolated in #44356; both replacement PRs can merge independently

This branch was successfully deployed

No deployments
e2e-changed — c6669bab Deployed Oct 3, 2026 by tin-berri via oauth #2809
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.

1 participant