route.ts
718 bytes
| 1 | import { NextResponse } from 'next/server'; |
|---|---|
| 2 | import { getModels } from '@/lib/model-cache'; |
| 3 | |
| 4 | export const runtime = 'nodejs'; |
| 5 | // Must be dynamic: the catalog depends on runtime env (MOCK_LLM) and must not |
| 6 | // be frozen into the build. Freshness is handled by the in-process 10-min cache |
| 7 | // in model-cache.ts, not by Next's static cache. |
| 8 | export const dynamic = 'force-dynamic'; |
| 9 | |
| 10 | export async function GET() { |
| 11 | const models = await getModels(); |
| 12 | return NextResponse.json({ |
| 13 | models: models.map((m) => ({ |
| 14 | id: m.id, |
| 15 | name: m.name, |
| 16 | contextLength: m.context_length ?? null, |
| 17 | promptPrice: Number(m.pricing?.prompt ?? '0'), |
| 18 | completionPrice: Number(m.pricing?.completion ?? '0'), |
| 19 | })), |
| 20 | }); |
| 21 | } |
| 22 | |