From cd67a86f96b4968de38e0124f2de4b43785ceaad Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 20 Jul 2026 14:47:35 +0000 Subject: [PATCH] fix(cost-optimization): correct limit/offset ordering and timestamp casts Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../management_endpoints/cost_optimization_endpoints.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/litellm/proxy/management_endpoints/cost_optimization_endpoints.py b/litellm/proxy/management_endpoints/cost_optimization_endpoints.py index 44af7822ef0..b6ab592de50 100644 --- a/litellm/proxy/management_endpoints/cost_optimization_endpoints.py +++ b/litellm/proxy/management_endpoints/cost_optimization_endpoints.py @@ -136,10 +136,10 @@ async def cost_optimization_usage_logs( conditions = [_optimized_where_sql()] params: list[object] = [] if start_date: - conditions.append('"startTime" >= $%d' % (len(params) + 1)) + conditions.append('"startTime" >= $%d::timestamp' % (len(params) + 1)) params.append(_parse_date(start_date)) if end_date: - conditions.append('"startTime" < $%d' % (len(params) + 1)) + conditions.append('"startTime" < $%d::timestamp' % (len(params) + 1)) params.append(_parse_date(end_date, end=True)) where_sql = " AND ".join(conditions) @@ -155,8 +155,8 @@ async def cost_optimization_usage_logs( ) total_value = total_rows[0].get("total") if total_rows else 0 total = int(total_value) if isinstance(total_value, (int, float)) else 0 - offset_placeholder = len(params) + 1 - limit_placeholder = len(params) + 2 + limit_placeholder = len(params) + 1 + offset_placeholder = len(params) + 2 rows = cast( # cast-ok: Prisma raw query returns rows with the selected columns list[Mapping[str, object]], await query_raw(