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 { requireManagementAuth } from "@/lib/api/requireManagementAuth";
import { extractCodexAuthZip } from "@/lib/oauth/utils/codexAuthZipExtract";
import { sanitizeErrorMessage } from "@omniroute/open-sse/utils/error";
const ZIP_BODY_LIMIT = 11 * 1024 * 1024; // 11 MB — slightly above the 10 MB extracted limit
export async function POST(request: Request) {
const authError = await requireManagementAuth(request);
if (authError) return authError;
const contentLength = Number(request.headers.get("content-length") || "0");
if (contentLength > ZIP_BODY_LIMIT) {
return NextResponse.json(
{ error: "ZIP file exceeds the 10 MB size limit", code: "file_too_large" },
{ status: 413 }
);
}
let buffer: Buffer;
try {
const arrayBuffer = await request.arrayBuffer();
if (arrayBuffer.byteLength > ZIP_BODY_LIMIT) {
return NextResponse.json(
{ error: "ZIP file exceeds the 10 MB size limit", code: "file_too_large" },
{ status: 413 }
);
}
buffer = Buffer.from(arrayBuffer);
} catch {
return NextResponse.json({ error: "Failed to read request body" }, { status: 400 });
}
try {
const files = extractCodexAuthZip(buffer);
const entries = files.map((f) => {
try {
return { name: f.name, json: JSON.parse(f.content), parseError: null };
} catch {
return { name: f.name, json: null, parseError: "Not valid JSON" };
}
});
return NextResponse.json({ entries });
} catch (error) {
return NextResponse.json(
{ error: sanitizeErrorMessage(error) || "Failed to extract ZIP", code: "extract_failed" },
{ status: 400 }
);
}
}