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 { NextResponse } from "next/server";
import {
getLastProviderLimitsAutoSyncTime,
getProviderLimitsSyncIntervalMinutes,
getSanitizedCachedProviderLimitsMap,
syncAllProviderLimits,
} from "@/lib/usage/providerLimits";
import { attachConnectionSpeedStats } from "@/lib/usage/connectionSpeedStats";
/**
* GET /api/usage/provider-limits
* Returns cached Provider Limits data without triggering live refreshes. Each entry
* also carries its connection's read-time `speed` stats when available.
*/
export async function GET() {
try {
return NextResponse.json({
caches: attachConnectionSpeedStats(await getSanitizedCachedProviderLimitsMap()),
intervalMinutes: getProviderLimitsSyncIntervalMinutes(),
lastAutoSyncAt: await getLastProviderLimitsAutoSyncTime(),
});
} catch (error) {
console.error("[API] GET /api/usage/provider-limits error:", error);
return NextResponse.json({ error: "Failed to fetch cached provider limits" }, { status: 500 });
}
}
/**
* POST /api/usage/provider-limits
* Manually refresh all supported Provider Limits entries.
*/
export async function POST() {
try {
const result = await syncAllProviderLimits({ source: "manual" });
const caches = attachConnectionSpeedStats(await getSanitizedCachedProviderLimitsMap());
return NextResponse.json({
...result,
caches,
intervalMinutes: getProviderLimitsSyncIntervalMinutes(),
lastAutoSyncAt: await getLastProviderLimitsAutoSyncTime(),
});
} catch (error) {
console.error("[API] POST /api/usage/provider-limits error:", error);
return NextResponse.json({ error: "Failed to refresh provider limits" }, { status: 500 });
}
}