diff --git a/api/cron/monitor-chutes.ts b/api/cron/monitor-chutes.ts new file mode 100644 index 000000000..c2f20dacd --- /dev/null +++ b/api/cron/monitor-chutes.ts @@ -0,0 +1,34 @@ +import { runMonitor, round6 } from '../../models-monitor/lib.ts' + +export const config = { maxDuration: 60 } + +export default async function handler(req: Request) { + if (req.headers.get('authorization') !== `Bearer ${process.env.CRON_SECRET}`) { + return new Response('Unauthorized', { status: 401 }) + } + + try { + await runMonitor({ + name: 'Chutes', + title: '🛰 Chutes Models Update', + s3Key: 'chutes/snapshot.json', + async fetchModels() { + const headers: Record = {} + if (process.env.CHUTES_API_KEY) headers['Authorization'] = `Bearer ${process.env.CHUTES_API_KEY}` + + const res = await fetch('https://llm.chutes.ai/v1/models', { headers }) + if (!res.ok) throw new Error(`Chutes API error: ${res.status}`) + const data = await res.json() as { data: Array<{ id: string; pricing: { prompt: number; completion: number } }> } + return data.data.map(m => ({ + id: m.id, + price_prompt: round6(m.pricing.prompt), + price_completion: round6(m.pricing.completion), + })) + }, + }) + return new Response('ok') + } catch (err) { + console.error(err) + return new Response(String(err), { status: 500 }) + } +} diff --git a/api/cron/monitor-openrouter.ts b/api/cron/monitor-openrouter.ts new file mode 100644 index 000000000..5a96ebd05 --- /dev/null +++ b/api/cron/monitor-openrouter.ts @@ -0,0 +1,31 @@ +import { runMonitor, round6 } from '../../models-monitor/lib.ts' + +export const config = { maxDuration: 60 } + +export default async function handler(req: Request) { + if (req.headers.get('authorization') !== `Bearer ${process.env.CRON_SECRET}`) { + return new Response('Unauthorized', { status: 401 }) + } + + try { + await runMonitor({ + name: 'OpenRouter', + title: '🛰 OpenRouter Models Update', + s3Key: 'openrouter/snapshot.json', + async fetchModels() { + const res = await fetch('https://openrouter.ai/api/v1/models') + if (!res.ok) throw new Error(`OpenRouter API error: ${res.status}`) + const data = await res.json() as { data: Array<{ id: string; pricing: { prompt: string; completion: string } }> } + return data.data.map(m => ({ + id: m.id, + price_prompt: round6(parseFloat(m.pricing.prompt) * 1_000_000), + price_completion: round6(parseFloat(m.pricing.completion) * 1_000_000), + })) + }, + }) + return new Response('ok') + } catch (err) { + console.error(err) + return new Response(String(err), { status: 500 }) + } +}