Skip to content

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

1.6 KB
Raw Blame
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
import { getAllRateLimitStatus } from "@omniroute/open-sse/services/rateLimitManager.ts";
import { getStats as getComboSemaphoreStats } from "@omniroute/open-sse/services/rateLimitSemaphore.ts";
import {
  getStats as getSemaphoreStats,
  resetAll as resetAllSemaphores,
} from "@omniroute/open-sse/services/accountSemaphore.ts";
import { requireManagementAuth } from "@/lib/api/requireManagementAuth";

export async function GET(request: Request) {
  const authError = await requireManagementAuth(request);
  if (authError) {
    authError.headers.set("Cache-Control", "private, no-store");
    return authError;
  }

  return NextResponse.json(
    {
      timestamp: new Date().toISOString(),
      rateLimits: getAllRateLimitStatus(),
      comboQueues: getComboSemaphoreStats("combo:"),
      semaphores: getSemaphoreStats(),
    },
    { headers: { "Cache-Control": "private, no-store" } }
  );
}

export async function POST(request: Request) {
  const authError = await requireManagementAuth(request);
  if (authError) {
    authError.headers.set("Cache-Control", "private, no-store");
    return authError;
  }

  const url = new URL(request.url);
  const action = url.searchParams.get("action");
  if (action === "reset-semaphores") {
    resetAllSemaphores();
    return NextResponse.json(
      { ok: true, action },
      { headers: { "Cache-Control": "private, no-store" } }
    );
  }
  return NextResponse.json(
    { error: "unknown action" },
    { status: 400, headers: { "Cache-Control": "private, no-store" } }
  );
}