Repository navigation
fix(proxy): preserve routed model for streamed spend logging - #42176
senthurapandi2000 wants to merge 4 commits into
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Thanks for turning this around fast. CI is green and the shape is right: put the routed model back before the success dispatch. Three things before this lands. 1. You read the client name from The proxy stamps chunks using The repro in the issue uses an alias as 2. Please do not fork the predicate.
3. The sync path has the same hole.
One behaviour note for the description: your mutation runs before the deep copy at |
|
Correcting my point 2 above, and adding a measurement that changes what it asks for. I told you to lift Measured, litellm 1.101.0, driving a real
So that predicate does not distinguish the two cases by itself on this shape. What saves the upstream version is only its second half, End to end on the same harness, restamp applied the way
Worth noting the failure mode: when the stamped name has no entry in the price map at all, this is not the silent One case to put in the tests, since it is the one the current guard gets wrong. With a key alias configured (
Both rows pass through the same code path; only the source of the client name separates them. |
|
Thanks for the detailed review and for the additional measurement. I see the issue with reading body["model"] after alias rewriting, and why the client-name check is load-bearing for the chunk predicate. I’ll update this to use _litellm_client_requested_model with the existing fallback semantics, reuse the shared predicate instead of duplicating it, cover the sync next path as well, and add a key-alias regression case matching the real chunk shape. I’ll also call out the cached-response model change in the PR description. |
| e, | ||
| ) | ||
| if isinstance(e, HTTPException) and hasattr(captured_logging_obj, "model_call_details"): | ||
| if isinstance(e, HTTPException) and hasattr(captured_logging_obj, "`model_call_details`"): |
There was a problem hiding this comment.
Low: Guardrail block marker is never recorded
The backticks make this check false for production logging objects, so a client whose streamed response triggers an HTTPException in a post-call guardrail can have the event logged without the guardrail_blocked audit marker. A MagicMock-based test may miss this because mocks synthesize arbitrary attributes.
| if isinstance(e, HTTPException) and hasattr(captured_logging_obj, "`model_call_details`"): | |
| if isinstance(e, HTTPException) and hasattr(captured_logging_obj, "model_call_details"): |
PR overviewThis PR updates proxy request processing so streamed spend logs preserve the model selected by routing. One low-severity issue remains: streamed responses blocked by a post-call guardrail may be logged without the expected guardrail-blocked audit marker. This affects audit accuracy under a specific exception path rather than enforcement of the guardrail itself. Open issues (1)
Fixed/addressed: 0 · PR risk: 3/10 |
|
Closing the loop here: the alias/streaming diagnosis in #42161 turned out to be wrong, as the issue thread shows. The real cause is |
|
Thanks for digging into this. The same fix landed in #44341 (v1.106.0), and streamed alias requests price correctly on main now, so closing this as superseded |
Summary
Fixes #42161.
Streaming requests using a client-facing model alias could be logged with the alias instead of the routed deployment model. Since the alias may not have pricing information, spend calculation could incorrectly resolve to 0 even though usage was present.
This change restores the wrapper's routed model before success logging when the assembled streaming response still contains the client-facing alias.
It also preserves the model returned by
stream_chunk_builderwhen the builder legitimately recovers a different routed/fallback model from a later stream chunk.Changes
Testing