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
/**
* Token Health API Route — Batch G
*
* Exposes aggregate health status of OAuth tokens.
* Used by TokenHealthBadge in the Header.
*/
import { getProviderConnections } from "@/lib/db/providers";
import { sanitizeErrorMessage } from "@omniroute/open-sse/utils/error.ts";
export async function GET() {
try {
const connections = await getProviderConnections({ authType: "oauth" });
const oauthConns = (connections || []).filter((c) => c.isActive && c.refreshToken);
const total = oauthConns.length;
const healthy = oauthConns.filter((c) => c.testStatus === "active" || !c.lastError).length;
const errored = oauthConns.filter(
(c) => c.testStatus === "error" || c.lastErrorType === "token_refresh_failed"
).length;
const lastCheck = oauthConns.reduce((latest, c) => {
if (!c.lastHealthCheckAt) return latest;
return latest && latest > c.lastHealthCheckAt ? latest : c.lastHealthCheckAt;
}, null);
return Response.json({
total,
healthy,
errored,
warning: total - healthy - errored,
lastCheckAt: lastCheck,
status: errored > 0 ? "error" : healthy < total ? "warning" : "healthy",
});
} catch (err) {
return Response.json(
{ error: sanitizeErrorMessage((err as Error)?.message), status: "unknown" },
{ status: 500 }
);
}
}