/** * llmindex.io — GET /api/v1/leaderboard (global ranking, paginated, cached 1h) * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * License: Proprietary — © Simon-Pierre Boucher, all rights reserved */ import { type NextRequest } from 'next/server'; import { getLeaderboard } from '@/lib/data'; import { apiError, apiJson } from '@/lib/api'; import { rateLimit } from '@/lib/rate-limit'; export const dynamic = 'force-dynamic'; export async function GET(req: NextRequest) { const limited = await rateLimit(req); if (limited) return limited; const params = req.nextUrl.searchParams; const limit = Math.min(200, Math.max(1, Number(params.get('limit') ?? 50))); const offset = Math.max(0, Number(params.get('offset') ?? 0)); const data = await getLeaderboard('global', limit, offset); if (!data) return apiError(503, 'no_score_run_available'); return apiJson( { index_version: data.run.indexVersion, run: { id: data.run.id, kind: data.run.kind, status: data.run.status, created_at: data.run.createdAt, notes: data.run.notes, }, pagination: { limit, offset, count: data.entries.length }, entries: data.entries.map((e) => ({ rank: e.rank, model: e.slug, name: e.name, provider: e.provider, score: e.score, score_low: e.scoreLow, score_high: e.scoreHigh, })), }, { cacheSeconds: 3600 }, ); }