From 87569d6a82549bcd37c89aa7bb767e2edb3ff664 Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Fri, 29 May 2026 16:13:54 -0300 Subject: [PATCH] fix(usage): analytics route reads combo_name/requested_model from call_logs only The 3.8.6 variant of #2904 added SELECTs of combo_name/requested_model against usage_history, but those columns only exist in call_logs (no migration adds them to usage_history). This returned HTTP 500 on /api/usage/analytics. Restore the working query shape from the 3.8.7 variant. Fixes 18 failing usage-analytics-route tests. --- src/app/api/usage/analytics/route.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/app/api/usage/analytics/route.ts b/src/app/api/usage/analytics/route.ts index 6fd5475018..2d3f8f3c2d 100644 --- a/src/app/api/usage/analytics/route.ts +++ b/src/app/api/usage/analytics/route.ts @@ -404,9 +404,7 @@ export async function GET(request: Request) { latency_ms, connection_id, api_key_id, - api_key_name, - combo_name, - requested_model + api_key_name FROM usage_history ${rawWhere} UNION ALL @@ -424,22 +422,19 @@ export async function GET(request: Request) { 0 as latency_ms, NULL as connection_id, NULL as api_key_id, - NULL as api_key_name, - NULL as combo_name, - NULL as requested_model + NULL as api_key_name FROM daily_usage_summary ${aggWhere} - )` + )` : `(SELECT timestamp, provider, model, tokens_input, tokens_output, tokens_cache_read, tokens_cache_creation, tokens_reasoning, service_tier, success, latency_ms, - connection_id, api_key_id, api_key_name, - combo_name, requested_model + connection_id, api_key_id, api_key_name FROM usage_history ${whereClause} - )`; + )`; // When using the unified source the WHERE filters are already embedded inside. // For the original whereClause-based queries that still reference usage_history directly