From b0a140647fcea3a3e63a7b1fcef0ee4cca0b2189 Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Sun, 26 Apr 2026 08:23:37 +0530 Subject: [PATCH] fix(mavvrik): add api_key to ORDER BY for stable OFFSET pagination Without dus.api_key in the ORDER BY, pagination is unstable: multiple rows can share the same (date, user_id, model) with different api_key values. When page boundaries fall inside such a group the DB can return those rows in any order, causing duplicates or silent drops across pages. Fix: add dus.api_key to the sort key, matching the table's @@unique constraint: (user_id, date, api_key, model, custom_llm_provider, ...). This guarantees a stable total order for all OFFSET-based pagination. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- litellm/integrations/mavvrik/exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/integrations/mavvrik/exporter.py b/litellm/integrations/mavvrik/exporter.py index 7e49c7e9fa7..8a2117d11dd 100644 --- a/litellm/integrations/mavvrik/exporter.py +++ b/litellm/integrations/mavvrik/exporter.py @@ -52,7 +52,7 @@ LEFT JOIN "LiteLLM_VerificationToken" vt ON dus.api_key = vt.token LEFT JOIN "LiteLLM_TeamTable" tt ON vt.team_id = tt.team_id LEFT JOIN "LiteLLM_UserTable" ut ON dus.user_id = ut.user_id WHERE dus.date = $1 -ORDER BY dus.date, dus.user_id, dus.model ASC +ORDER BY dus.date, dus.user_id, dus.api_key, dus.model ASC """ _EARLIEST_DATE_QUERY = 'SELECT MIN(date) AS earliest FROM "LiteLLM_DailyUserSpend"'