Skip to content

feat(proxy): add model_group filter to /spend/logs/v2 endpoint - #29405

Merged
Sameerlite merged 1 commit into
BerriAI:litellm_oss_stagingfrom
silencedoctor:feat/spend-logs-v2-model-group-filter
Jun 2, 2026
Merged

feat(proxy): add model_group filter to /spend/logs/v2 endpoint#29405
Sameerlite merged 1 commit into
BerriAI:litellm_oss_stagingfrom
silencedoctor:feat/spend-logs-v2-model-group-filter

Conversation

@silencedoctor

Copy link
Copy Markdown
Contributor

♻️ Re-targeted from #26080. The original PR was closed by the OSS review bot. Its head branch was force-pushed after closure, so GitHub will not allow reopening it — this is a fresh PR with the same change, retargeted onto the current litellm_internal_staging integration branch. (Originally superseded #24782.)

Relevant issues

Fixes #26079

Type

🆕 New Feature

Changes

Adds an optional model_group query parameter to /spend/logs/v2 and /spend/logs/ui that filters spend logs where model_group = <value>. The implementation mirrors the existing model and model_id filters exactly.

No schema changes requiredmodel_group is already a column in the LiteLLM_SpendLogs table 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 — added model_group Query 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

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).
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ yuneng-berri
✅ silencedoctor
❌ shin-berri
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR wires an optional model_group query parameter through the existing /spend/logs/v2 (and /spend/logs/ui) handler, enabling callers to filter spend logs by model group. The change is entirely additive and mirrors the model_id filter implementation that was already present.

  • Three-line change to spend_management_endpoints.py: FastAPI Query declaration, where_conditions assignment, and the SQL equality-filter tuple — each positioned immediately after the parallel model_id code.
  • One new mock-only pytest test validates the filter is applied and returns only the matching log entry, consistent with the existing model_id test above it.

Confidence Score: 5/5

Safe 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 model and model_id. The new column (model_group) already exists in the schema and is already returned in responses, so no migration is needed. The mock test validates the happy path. No existing behavior is altered.

No files require special attention.

Important Files Changed

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

@Sameerlite
Sameerlite changed the base branch from litellm_internal_staging to litellm_oss_staging June 2, 2026 11:42

@Sameerlite Sameerlite left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Sameerlite
Sameerlite merged commit 150c6eb into BerriAI:litellm_oss_staging Jun 2, 2026
88 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.

[Feature]: Add model_group filter to /spend/logs/v2 endpoint

3 participants