litellm - 💡(How to fix) Fix [Bug]: Deleting a key leaves orphaned team_id references in usage/logs — team name disappears from historical records [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#25710Fetched 2026-04-16 06:37:02
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
labeled ×1
RAW_BUFFERClick to expand / collapse

Check for existing issues

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

What happened?

When an API key is hard-deleted via /key/delete, the key hash is retained in LiteLLM_SpendLogs and usage aggregates (as expected for historical accounting), but the association between that key hash and its team is lost everywhere except the raw key_name / key_alias. Specifically:

  • The key hash still appears in Usage Dashboard and Spend Logs.
  • team_id on those historical rows becomes unresolvable — the UI shows an empty/blank Team Name column for every row belonging to the deleted key.
  • Only the key_name / key_alias remains visible; team_alias is gone.

Expected: Historical spend rows for a deleted key should continue to display the team name they were originally billed to. Either (a) the team_idteam_alias lookup should survive key deletion, or (b) the team_alias should be denormalized onto the spend-log row at write time so it is not lost when the key row is removed.

Actual: Team Name column renders blank for historical usage/logs of deleted keys, making per-team reporting and audit impossible after any key rotation.

Steps to Reproduce

  1. Create a team with team_alias = "team-A".
  2. Create a key under that team and make a few /chat/completions calls so spend logs are recorded.
  3. Confirm Usage Dashboard / Spend Logs show Team Name = team-A for those rows.
  4. Call /key/delete (hard delete) for that key.
  5. Reload Usage Dashboard / Spend Logs — the rows for that key's hash still exist, but the Team Name column is now empty. key_alias is still rendered, but team attribution is gone.

What part of LiteLLM is this about?

Proxy (symptom surfaces in the UI Dashboard)

What LiteLLM version are you on?

v1.82.3

extent analysis

TL;DR

Denormalize the team_alias onto the spend-log row at write time to preserve team attribution for historical usage/logs of deleted keys.

Guidance

  • To resolve the issue, consider modifying the database schema to store the team_alias directly on the spend-log rows, allowing for team attribution to persist even after key deletion.
  • Review the current implementation of the /key/delete endpoint to understand how the team_id association is being removed and determine if it can be modified to preserve this information.
  • Investigate the possibility of creating a cached or materialized view of team aliases to facilitate lookups and improve performance.
  • Verify that the proposed solution does not introduce data inconsistencies or affect other parts of the system, such as key rotation or team management.

Example

-- Example of denormalizing team_alias onto spend-log rows
CREATE TABLE SpendLogs (
  id SERIAL PRIMARY KEY,
  key_hash VARCHAR(255),
  team_alias VARCHAR(255),  -- Denormalized team alias
  usage_data JSONB
);

Notes

The proposed solution assumes that the team_alias is relatively static and can be safely denormalized onto the spend-log rows. However, if team aliases are subject to frequent changes, a more complex solution may be required to maintain data consistency.

Recommendation

Apply workaround: Denormalize the team_alias onto the spend-log row at write time, as this approach allows for team attribution to be preserved without requiring significant changes to the existing system.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]: Deleting a key leaves orphaned team_id references in usage/logs — team name disappears from historical records [1 participants]