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.1 KB
Raw Blame
import os from "os";
import { NextResponse } from "next/server";
import { isAuthenticated } from "@/shared/utils/apiAuth";
import { getRuntimePorts } from "@/lib/runtime/ports";

export const dynamic = "force-dynamic";

export async function GET(request: Request) {
  if (!(await isAuthenticated(request))) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }

  const { apiPort } = getRuntimePorts();
  const interfaces = os.networkInterfaces();
  const localUrl = `http://localhost:${apiPort}/v1`;
  const lanUrls: string[] = [];
  let tailscaleIpUrl: string | null = null;

  for (const [ifaceName, addrs] of Object.entries(interfaces)) {
    for (const addr of addrs ?? []) {
      if (addr.family !== "IPv4" || addr.internal) continue;
      const isTailscale =
        ifaceName.toLowerCase().startsWith("tailscale") || addr.address.startsWith("100.");
      if (isTailscale) {
        tailscaleIpUrl = `http://${addr.address}:${apiPort}/v1`;
      } else {
        lanUrls.push(`http://${addr.address}:${apiPort}/v1`);
      }
    }
  }

  return NextResponse.json({ localUrl, lanUrls, tailscaleIpUrl });
}