// Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // Project: chat.spboucher.ai import { NextResponse } from "next/server"; import { requireSession } from "@/lib/auth/guard"; import { ensureCatalogFresh, listCatalog, catalogSyncedAt } from "@/lib/catalog"; export const runtime = "nodejs"; export async function GET() { const { unauthorized } = await requireSession(); if (unauthorized) return unauthorized; try { await ensureCatalogFresh(); } catch { return NextResponse.json( { error: "Could not load the model catalog from OpenRouter. Check connectivity and retry." }, { status: 502 } ); } return NextResponse.json({ models: listCatalog(), syncedAt: catalogSyncedAt() }); }