Repository navigation
refactor: expose public hidden_params accessors - #44668
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This reverts commit 621e5ff.
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai review |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai review |
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai review |
…_hidden_params Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # tests/unit/proxy/hooks/test_dynamic_rate_limiter.py
|
@greptileai review |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai review |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai review |
|
bugbot run |
There was a problem hiding this comment.
✅ 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 913c0a9. Configure here.
…table/1.104.x The public hidden_params accessor comes from #44668, which is not on stable/1.104.x, so the backported test reads the private attribute like the rest of the file
TLDR
Problem this solves:
reportPrivateUsagehits come from readingresponse._hidden_paramsHow it solves it:
hidden_paramsproperty on every response type that stores_hidden_paramshidden_params_hidden_paramsstays as storage, so existing user code keeps workingDecisionsResponseis frozen, so it gets a read-only propertyHiddenParamsmodel are read and written throughHiddenParamsModelView, which only exposes set fields and extras, and transfers between responses move the raw storage object like main did_hidden_paramsgo through small getattr/setattr helpers inlitellm_core_utils/hidden_params.pyreportPrivateUsageto zero, the budget ratchet lowers the limit after mergeUser Flow
Before: an SDK or proxy user reads response metadata through the underscore attribute
litellm.completion(...)or POST http://localhost:4000/v1/chat/completionsresponse._hidden_params["response_cost"], or the proxy returnsx-litellm-response-costandx-litellm-model-idheadersAfter: the same calls return the same data, and a public name is also available
response._hidden_paramsand the newresponse.hidden_paramsreturn the same dict, and the proxy headers are unchangedPre-Submission checklist
Screenshots / Proof of Fix
Video of the live run is in the Slack thread https://berriaillm.slack.com/archives/C0B302ZJU05/p1791232426675779
Shared setup is two proxies on random free ports, one per worktree, with real OpenAI and Anthropic keys, no DB, and this config
Before (2156d6c)
qa-chatreturns 200 withx-litellm-response-cost: 3e-06,x-litellm-model-id: qa-chat,x-litellm-model-api-base, and duration headers"stream": truestreams to[DONE], final usage chunk shows 14 tokens and cost 3e-06qa-responsesreturns 200 with cost5.1e-06and the same metadata headersqa-anthropicreturns 200 with cost5.5e-05qa-embeddingsreturns 200 with cost8e-08qa-fallbackreturns 200 fromqa-chatwithx-litellm-attempted-fallbacks: 1x-litellm-cache-keyon the hitlitellm.completion(...)givesresponse._hidden_params["response_cost"] == 3e-06, andresponse.hidden_paramsraisesAttributeErrorCustomLLMinlitellm.custom_provider_mapthat calls OpenAI and returns a plain userBaseModelwith only_hidden_paramskeepsresponse_cost0.0042 and bothadditional_headersAfter (9061b14)
x-litellm-*values apart from call ids and durations5.1e-065.5e-058e-08x-litellm-attempted-fallbacks: 1response.hidden_params is response._hidden_paramsisTruefor both reading and assigningType
🧹 Refactoring
Caveats (if any)
Low
/v1/completionsmetadata was not checked live because OpenAI now returns 404 for gpt-3.5-turbo-instruct, davinci-002 and babbage-002 on both commits, unit tests cover that pathModelResponseBasekeeps its shared class-level_hidden_params = {}default, unchanged hereFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/32b275f5ec964f1f82cf6192e19a6237
Open in Devin Desktop: https://app.devin.ai/desktop/session/32b275f5ec964f1f82cf6192e19a6237?variant=devin
Requested by: @mateo-berri