Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix: API Manager usage stats showing 0 for all registered keys
ivan_yakimkin9bfbbd65f576
diff --git a/src/app/(dashboard)/dashboard/api-manager/ApiManagerPageClient.tsx b/src/app/(dashboard)/dashboard/api-manager/ApiManagerPageClient.tsxindex 2b6b37fb24..1635025b97 100644--- a/src/app/(dashboard)/dashboard/api-manager/ApiManagerPageClient.tsx+++ b/src/app/(dashboard)/dashboard/api-manager/ApiManagerPageClient.tsx@@ -166,24 +166,42 @@ export default function ApiManagerPageClient() {const fetchUsageStats = async (apiKeys: ApiKey[]) => {if (apiKeys.length === 0) return;try {- const res = await fetch("/api/usage/call-logs?limit=1000");- if (!res.ok) return;- const logs = await res.json();+ // Fetch analytics (accurate aggregated counts) and recent call-logs+ // (for lastUsed timestamps) in parallel.+ // The previous approach matched call-logs by key.id === log.apiKeyId,+ // but these use different ID schemes and never matched, yielding 0.+ const [analyticsRes, logsRes] = await Promise.all([+ fetch("/api/usage/analytics?range=all"),+ fetch("/api/usage/call-logs?limit=1000"),+ ]);++ const analytics = analyticsRes.ok ? await analyticsRes.json() : null;+ const byApiKey: any[] = analytics?.byApiKey || [];+ const logs = logsRes.ok ? await logsRes.json() : [];+const stats: Record<string, KeyUsageStats> = {};for (const key of apiKeys) {+ // Match analytics entry by key name (reliable across both systems)+ const analyticsMatch = byApiKey.find(+ (entry: any) => entry.apiKeyName === key.name+ );++ // Find the most recent call-log for this key to determine lastUsedconst keyLogs = (logs || []).filter(- (log: any) => log.apiKeyId === key.id || log.apiKeyName === key.name+ (log: any) => log.apiKeyName === key.name);+ const lastUsed =+ keyLogs.length > 0+ ? keyLogs.sort(+ (a: any, b: any) =>+ new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()+ )[0]?.timestamp+ : null;+stats[key.id] = {- totalRequests: keyLogs.length,- lastUsed:- keyLogs.length > 0- ? keyLogs.sort(- (a: any, b: any) =>- new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()- )[0]?.timestamp- : null,+ totalRequests: analyticsMatch?.requests ?? 0,+ lastUsed,};}setUsageStats(stats);