From b29c0bfb8f81f8474cde5bcd189b77b38a48a2f7 Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Thu, 12 Feb 2026 21:52:04 -0800 Subject: [PATCH] Update litellm/proxy/spend_tracking/spend_management_endpoints.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- litellm/proxy/spend_tracking/spend_management_endpoints.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/spend_tracking/spend_management_endpoints.py b/litellm/proxy/spend_tracking/spend_management_endpoints.py index 0c91fd00b3..3c93530cf6 100644 --- a/litellm/proxy/spend_tracking/spend_management_endpoints.py +++ b/litellm/proxy/spend_tracking/spend_management_endpoints.py @@ -1928,6 +1928,10 @@ async def ui_view_spend_logs( # noqa: PLR0915 sql_params.append(f"%{error_message}%") p += 1 + # Quote column names that need quoting in SQL + _sql_col = f'"{order_column}"' if order_column in ("startTime", "endTime") else order_column + _sql_dir = "ASC" if order_direction == "asc" else "DESC" + sql_query = f""" SELECT request_id, call_type, api_key, spend, total_tokens, @@ -1939,7 +1943,7 @@ async def ui_view_spend_logs( # noqa: PLR0915 session_id, status, mcp_namespaced_tool_name, agent_id FROM "LiteLLM_SpendLogs" WHERE {" AND ".join(sql_conditions)} - ORDER BY "startTime" DESC + ORDER BY {_sql_col} {_sql_dir} LIMIT ${p} OFFSET ${p + 1} """ sql_params.extend([page_size, skip])