Skip to content

[Bug Fix] Spend Tracking Bug Fix, don't modify in memory default litellm params #10167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 19, 2025

Conversation

ishaan-jaff
Copy link
Contributor

@ishaan-jaff ishaan-jaff commented Apr 19, 2025

[Bug Fix] Spend Tracking Bug Fix, don't modify in memory default litellm params

When a user invokes the /responses endpoint and then immediately calls /chat/completions, the cost/spend for the /chat/completions call was not being recorded.

What caused the issue:

  • The /responses handler passes metadata_variable_name="litellm_metadata", so the helper moves the defaults under that key instead of "metadata".
  • Because we operated directly on the router’s shared default_litellm_params dict, that rename stuck for all future calls.
  • The original code popped "metadata" out of self.default_litellm_params and re‑inserted it under the new name in place.
  • Subsequent calls to _update_kwargs_with_default_litellm_params saw only litellm_metadata in the defaults, so they merged into the wrong field.

Fix made

By copying default_litellm_params and popping/merging metadata on that local copy, we avoid mutating the router’s shared defaults dict. Metadata now always lands under the correct metadata_variable_name per call, so downstream spend‑tracking reliably picks it up.

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on (make test-unit)[https://docs.litellm.ai/docs/extras/contributing_code]
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
✅ Test

Changes

Copy link

vercel bot commented Apr 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 19, 2025 9:12pm

@ishaan-jaff ishaan-jaff merged commit b0024bb into main Apr 19, 2025
16 of 42 checks passed
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