feat(proxy): add model_group filter to /spend/logs/v2 endpoint - #29405
Conversation
Add an optional `model_group` query parameter to the `/spend/logs/v2` and `/spend/logs/ui` endpoints, allowing users to filter spend logs by model group. This is consistent with the existing `model` and `model_id` filters and requires no schema changes since `model_group` is already a column in the `LiteLLM_SpendLogs` table. Supersedes BerriAI#24782 (rebased onto latest main).
|
|
Greptile SummaryThis PR wires an optional
Confidence Score: 5/5Safe to merge — the change is purely additive, touches only the spend-logs query path, and uses parameterized SQL so there is no injection risk. The change is a minimal three-spot addition that follows the exact pattern already in use for No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/spend_tracking/spend_management_endpoints.py | Adds model_group query param to ui_view_spend_logs (serves both /spend/logs/v2 and /spend/logs/ui); wired through where_conditions, and the SQL equality-filter loop in 3 places, all mirroring the existing model_id pattern exactly. |
| tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py | Adds one async mock-only test (test_ui_view_spend_logs_with_model_group) that validates the filter is applied and only the matching log is returned; consistent with the model_id test structure above it. |
Reviews (1): Last reviewed commit: "feat(proxy): add model_group filter to /..." | Re-trigger Greptile
Relevant issues
Fixes #26079
Type
🆕 New Feature
Changes
Adds an optional
model_groupquery parameter to/spend/logs/v2and/spend/logs/uithat filters spend logs wheremodel_group = <value>. The implementation mirrors the existingmodelandmodel_idfilters exactly.No schema changes required —
model_groupis already a column in theLiteLLM_SpendLogstable and is already returned in the response payload. This PR only wires the missing filter parameter through to the SQL query.Code touched
litellm/proxy/spend_tracking/spend_management_endpoints.py— addedmodel_groupQuery param +where_conditions["model_group"]filter + serialization tuple entry (3 spots, 7 lines)tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py— covers: filter applied when set, filter omitted when None, no result when no match, combined with other filters