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
import { getProxyHealthStats } from "@/lib/db/proxies";
import { createErrorResponseFromUnknown } from "@/lib/api/errorResponse";
import { requireManagementAuth } from "@/lib/api/requireManagementAuth";
import { getSweepVerdicts } from "@/lib/proxyHealth/sweepVerdict";
import { getBlockedHistory } from "@/lib/proxyHealth/blockedHistory";
export async function GET(request: Request) {
const authError = await requireManagementAuth(request);
if (authError) return authError;
try {
const { searchParams } = new URL(request.url);
const hours = Number(searchParams.get("hours") || 24);
const items = await getProxyHealthStats({ hours });
const verdicts = getSweepVerdicts(items.map((item) => String(item.proxyId ?? "")));
const now = Date.now();
const withSweep = items.map((item) => {
const id = String(item.proxyId ?? "");
const verdict = verdicts[id];
const out: Record<string, unknown> = { ...item };
if (verdict) out.sweep = { ...verdict, ageMs: Math.max(0, now - verdict.at) };
const history = getBlockedHistory(id);
if (history) out.blockedHistory = { ...history, ageMs: Math.max(0, now - history.lastSeen) };
return out;
});
return Response.json({ items: withSweep, total: withSweep.length, windowHours: hours });
} catch (error) {
return createErrorResponseFromUnknown(error, "Failed to load proxy health stats");
}
}