litellm - ✅(Solved) Fix [Feature]: Add model_group filter to /spend/logs/v2 endpoint [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#24781Fetched 2026-04-08 01:54:01
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
cross-referenced ×1labeled ×1referenced ×1

Fix Action

Fixed

PR fix notes

PR #24782: feat: add model_group filter to /spend/logs/v2 endpoint

Description (problem / solution / changelog)

Relevant issues

Fixes #24781

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Type

🆕 New Feature

Changes

Add an optional model_group query parameter to the /spend/logs/v2 and /spend/logs/ui endpoints, enabling users to filter spend logs by model group (the public-facing model name used by the Router for load-balancing).

What changed

litellm/proxy/spend_tracking/spend_management_endpoints.py

  • Added model_group as an optional query parameter (consistent with existing model and model_id params)
  • Added Prisma where_conditions for model_group filtering
  • Added model_group to the raw SQL equality filter list

tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py

  • Added test_ui_view_spend_logs_with_model_group following the same pattern as the existing test_ui_view_spend_logs_with_model and test_ui_view_spend_logs_with_model_id tests

Why

The model_group column already exists in the LiteLLM_SpendLogs table and is returned in responses, but there was no way to filter by it. This is needed for downstream consumers that want to analyze usage at the model-group level (e.g., all deployments of "gpt-4") rather than individual deployment models.

Test plan

  • test_ui_view_spend_logs_with_model_group — verifies that passing model_group=gpt-4 returns only logs with that model group
  • All 51 existing tests in test_spend_management_endpoints.py continue to pass
  • Adjacent test_ui_view_spend_logs_with_model and test_ui_view_spend_logs_with_model_id tests unaffected

Changed files

  • litellm/proxy/spend_tracking/spend_management_endpoints.py (modified, +7/-0)
  • tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py (modified, +65/-0)
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

The Feature

The /spend/logs/v2 endpoint currently supports filtering by model, model_id, team_id, user_id, api_key, end_user, status_filter, key_alias, error_code, and error_message — but it does not support filtering by model_group.

The model_group column already exists in the LiteLLM_SpendLogs table (schema.prisma) and is already returned in the response payload. The only missing piece is a query parameter to filter by it.

Requested change: Add an optional model_group query parameter to /spend/logs/v2 (and /spend/logs/ui) that filters logs where model_group = <value>, consistent with how the existing model and model_id filters work.

Motivation, pitch

We are building an AI Gateway usage dashboard on top of LiteLLM Proxy. Users need to filter request logs by model_group (the public-facing model name / router group) to analyze usage and costs at the model-group level rather than the individual deployment level.

Currently, filtering by model returns logs for a specific deployment model name, but there is no way to filter by the logical model group that the Router uses for load-balancing. Since model_group is already stored in the spend logs table and returned in responses, adding a filter parameter would be a small, low-risk change that enables this common use case.

What part of LiteLLM is this about?

Proxy

LiteLLM is hiring a founding backend engineer, are you interested in joining us and shipping to all our users?

No


Re-filed from #24781 with a fresh PR rebased onto current main. Original issue and PR #24782 stalled for 3 weeks without review.

extent analysis

Fix Plan

To add an optional model_group query parameter to the /spend/logs/v2 and /spend/logs/ui endpoints, follow these steps:

  • Update the API endpoint to accept the model_group query parameter
  • Modify the database query to filter by model_group when the parameter is provided

Example Code

// Update the API endpoint to accept the model_group query parameter
app.get('/spend/logs/v2', async (req, res) => {
  const { model_group, ...otherParams } = req.query;

  // Modify the database query to filter by model_group
  const logs = await prisma.liteLLMSpendLogs.findMany({
    where: {
      ...otherParams,
      model_group: model_group ? { equals: model_group } : undefined,
    },
  });

  res.json(logs);
});

Verification

To verify the fix, test the endpoint with the model_group query parameter:

curl 'https://example.com/spend/logs/v2?model_group=my_model_group'

This should return only the logs where model_group equals my_model_group.

Extra Tips

  • Make sure to update the API documentation to include the new model_group query parameter.
  • Consider adding validation for the model_group parameter to ensure it matches the expected format.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - ✅(Solved) Fix [Feature]: Add model_group filter to /spend/logs/v2 endpoint [2 pull requests, 1 participants]