From 51875ec3e05df93c6ef6898ad5696d2c5d2c874f Mon Sep 17 00:00:00 2001 From: Charlie Freeman <243496084+cf3901646@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:21:59 +0800 Subject: [PATCH] fix(ui): percent-encode logId/request_id in /spend/logs/ui endpoint (#47808) --- litellm/proxy/client/cli/commands/debug.py | 3 ++- .../src/components/networking.test.ts | 16 ++++++++++++++++ .../src/components/networking.tsx | 5 +++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/client/cli/commands/debug.py b/litellm/proxy/client/cli/commands/debug.py index 8728a9323b7..15aee610cb0 100644 --- a/litellm/proxy/client/cli/commands/debug.py +++ b/litellm/proxy/client/cli/commands/debug.py @@ -9,6 +9,7 @@ single markdown report that can be pasted into a bug report or handed to another import json import os import re +import urllib.parse from collections.abc import Mapping, Sequence from dataclasses import dataclass from datetime import datetime, timezone @@ -177,7 +178,7 @@ class SpendLogsFetcher: return DebugFailure(f"Unexpected {uri} response: {e}") def payload(self, request_id: str) -> RequestResponsePayload | None | DebugFailure: - uri: Final = f"/spend/logs/ui/{request_id}" + uri: Final = f"/spend/logs/ui/{urllib.parse.quote(request_id, safe='')}" raw: Final = self._get(uri) if isinstance(raw, DebugFailure): return raw diff --git a/ui/litellm-dashboard/src/components/networking.test.ts b/ui/litellm-dashboard/src/components/networking.test.ts index e7a55870345..6a4a4eaab1e 100644 --- a/ui/litellm-dashboard/src/components/networking.test.ts +++ b/ui/litellm-dashboard/src/components/networking.test.ts @@ -1177,4 +1177,20 @@ describe("getUiConfig runtime backend discovery", () => { discovery_mode: "well_known_fallback", }); }); + it("encodes special characters in logId when calling uiSpendLogDetailsCall", async () => { + const originalFetch = global.fetch; + const mockFetch = vi.fn().mockResolvedValue({ + ok: true, + json: vi.fn().mockResolvedValue({ id: "test" }), + }); + global.fetch = mockFetch; + + try { + await Networking.uiSpendLogDetailsCall("token-123", "chatcmpl-123#a1", "2026-01-01"); + const calledUrl = String(mockFetch.mock.calls.at(-1)?.[0]); + expect(calledUrl).toContain("/spend/logs/ui/chatcmpl-123%23a1?start_date=2026-01-01"); + } finally { + global.fetch = originalFetch; + } + }); }); diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx index 4df34275923..42895c41df9 100644 --- a/ui/litellm-dashboard/src/components/networking.tsx +++ b/ui/litellm-dashboard/src/components/networking.tsx @@ -4779,9 +4779,10 @@ export const createGuardrailCall = async (accessToken: string, guardrailData: an export const uiSpendLogDetailsCall = async (accessToken: string, logId: string, start_date: string) => { try { // Construct base URL + const encodedLogId = encodeURIComponent(logId); let url = proxyBaseUrl - ? `${proxyBaseUrl}/spend/logs/ui/${logId}?start_date=${encodeURIComponent(start_date)}` - : `/spend/logs/ui/${logId}?start_date=${encodeURIComponent(start_date)}`; + ? `${proxyBaseUrl}/spend/logs/ui/${encodedLogId}?start_date=${encodeURIComponent(start_date)}` + : `/spend/logs/ui/${encodedLogId}?start_date=${encodeURIComponent(start_date)}`; const response = await fetch(url, { method: "GET",