Skip to content

feat(ui): add session id filter to request logs - #32568

Merged
tin-berri merged 4 commits into
BerriAI:litellm_internal_stagingfrom
thibault-linktree:litellm_ui_session_id_filter
Jul 9, 2026
Merged

feat(ui): add session id filter to request logs#32568
tin-berri merged 4 commits into
BerriAI:litellm_internal_stagingfrom
thibault-linktree:litellm_ui_session_id_filter

Conversation

@thibault-linktree

@thibault-linktree thibault-linktree commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #32585

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Captured at 9a4652e against a live proxy (python litellm/proxy/proxy_cli.py --config litellm/proxy/dev_config.yaml --detailed_debug --use_v2_migration_resolver on localhost:4000 with a local Postgres), hitting the real OpenAI API with real spend

First, three real chat completions across two sessions, using the x-litellm-session-id header:

for msg in "Say exactly: first call" "Say exactly: second call"; do
  curl -s http://localhost:4000/v1/chat/completions \
    -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
    -H "x-litellm-session-id: session-filter-demo-1" \
    -d "{\"model\": \"gpt-4o-mini\", \"messages\": [{\"role\": \"user\", \"content\": \"$msg\"}]}"
done
curl -s http://localhost:4000/v1/chat/completions \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -H "x-litellm-session-id: session-filter-demo-2" \
  -d '{"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Say exactly: other session"}]}'
chatcmpl-DzYBwiyvPqgfkGKDCLWkaLuRCGfiZ -> First call.
chatcmpl-DzYBxzJOqKPt9xORX3c1EqsDMxTfm -> Second call.
chatcmpl-DzYByXcuTk8q7pj89gjgLYt7DvcQd -> Other session

Then the logs endpoint with the new session_id filter:

START=$(date -u -v-1H '+%Y-%m-%d %H:%M:%S' | sed 's/ /%20/'); END=$(date -u -v+1H '+%Y-%m-%d %H:%M:%S' | sed 's/ /%20/')
curl -s "http://localhost:4000/spend/logs/ui?session_id=session-filter-demo-1&start_date=$START&end_date=$END" -H "Authorization: Bearer sk-1234"
curl -s "http://localhost:4000/spend/logs/ui?session_id=session-filter-demo-2&start_date=$START&end_date=$END" -H "Authorization: Bearer sk-1234"
curl -s "http://localhost:4000/spend/logs/ui?start_date=$START&end_date=$END" -H "Authorization: Bearer sk-1234"
== filter session-filter-demo-1 ==
total: 2
chatcmpl-DzYBxzJOqKPt9xORX3c1EqsDMxTfm session-filter-demo-1
chatcmpl-DzYBwiyvPqgfkGKDCLWkaLuRCGfiZ session-filter-demo-1
== filter session-filter-demo-2 ==
total: 1
chatcmpl-DzYByXcuTk8q7pj89gjgLYt7DvcQd session-filter-demo-2
== no session filter ==
total: 3

UI screenshots of the new Session ID field in the Logs filter panel to follow

Type

🆕 New Feature

Changes

The Requests logs tab lets you filter by request id but not by session id, so tracking a full conversation means clicking through rows manually. This adds a Session ID filter end to end

On the backend, /spend/logs/v2 and /spend/logs/ui gain a session_id query parameter that does an exact match on the session_id column of LiteLLM_SpendLogs (already indexed), following the exact same pattern as the existing request_id filter

On the dashboard, the Logs filter panel gains a Session ID text input wired through FILTER_KEYS, the debounced text filter list, and uiSpendLogsCall, which forwards it as the session_id query param. schema.d.ts is regenerated for the new parameter

Tests: a new endpoint test asserts that filtering by session id returns only that session's rows (the shared mock prisma helper now also supports the session-count enrichment queries, so endpoint tests can use rows that carry a session_id), and the frontend filter mapping test table gains the Session ID to session_id case

image

@greptile-apps

greptile-apps Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a session_id filter end-to-end: a new query parameter on /spend/logs/v2 and /spend/logs/ui, a LIKE-based substring match on the session_id column with proper metacharacter escaping (%, _, \), and a Session ID text input in the dashboard filter panel wired through FILTER_KEYS and debounced input handling.

  • Backend (spend_management_endpoints.py): the new session_id param escapes LIKE metacharacters before binding the pattern %...% as a SQL parameter — an improvement over the existing key_alias/error_message LIKE filters which skip escaping. Both /spend/logs/v2 and /spend/logs/ui gain the filter since they share a single handler.
  • Tests (test_spend_management_endpoints.py): parameterized test covers full-id, partial prefix, cross-session substring, and no-match cases; the shared mock's group_by is generalized to support any by column, resolving the earlier review comment.
  • Frontend (log_filter_logic.tsx, filter_options.ts, networking.tsx, schema.d.ts): Session ID is added uniformly alongside the other text-input filters with no deviations from existing patterns.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to an additive query parameter on the spend logs endpoint with no modifications to existing filter paths.

The backend change adds a single optional LIKE filter that is only activated when session_id is supplied; all values are SQL-parameter-bound, wildcards are escaped, and nothing in the existing filter logic is touched. The frontend wiring follows the exact same pattern as every other text filter in the panel. Tests cover the key boundary cases (partial match, cross-session prefix, no-match) and the shared mock helper was correctly generalized rather than hacked.

No files require special attention.

Important Files Changed

Filename Overview
litellm/proxy/spend_tracking/spend_management_endpoints.py Adds session_id query parameter to both /spend/logs/v2 and /spend/logs/ui (shared function), with a LIKE-based substring filter that correctly escapes %, _, and \ before binding as a SQL parameter.
tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py Adds parameterized test covering full-id match, partial prefix match, cross-session partial match, and no-match for the new session_id filter; generalizes the shared group_by mock to support arbitrary grouping columns.
ui/litellm-dashboard/src/components/view_logs/log_filter_logic.tsx Adds SESSION_ID to FILTER_KEYS, TEXT_FILTER_KEYS, defaultFilters, and the effectiveFilters → API params mapping; wiring is consistent with how other text filters are handled.
ui/litellm-dashboard/src/components/view_logs/filter_options.ts Adds Session ID as a non-searchable text filter option, consistent with Key Hash and Request ID entries.
ui/litellm-dashboard/src/components/networking.tsx Extends UiSpendLogsParams interface with optional session_id field.
ui/litellm-dashboard/src/components/view_logs/log_filter_logic.test.tsx Adds Session IDsession_id mapping to the existing filter-key parameterization test table.
ui/litellm-dashboard/src/lib/http/schema.d.ts Regenerated OpenAPI schema with session_id parameter added to both /spend/logs/v2 and /spend/logs/ui operations.

Reviews (2): Last reviewed commit: "feat(ui): support partial match on sessi..." | Re-trigger Greptile

Comment thread tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py Outdated
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 30 untouched benchmarks


Comparing thibault-linktree:litellm_ui_session_id_filter (8a44fdd) with litellm_internal_staging (142d5aa)

Open in CodSpeed

@thibault-linktree

Copy link
Copy Markdown
Contributor Author

@greptileai

Since the first review: the session_id filter now does a partial (substring) match instead of exact equality, following the error_message/key_alias LIKE pattern with wildcard escaping, and the shared test mock's group_by was generalized per the earlier comment. On the CodSpeed report: the flagged benchmark exercises the completion call path, which this PR does not touch (it only adds a query parameter to the spend logs endpoint), so the regression looks like runner noise

@tin-berri
tin-berri merged commit 131aa05 into BerriAI:litellm_internal_staging Jul 9, 2026
284 of 286 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]: Filter request logs by session ID in the Admin UI

2 participants