Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions api/cron/monitor-chutes.ts
Original file line number Diff line number Diff line change
@@ -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<string, string> = {}
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 })
}
}
31 changes: 31 additions & 0 deletions api/cron/monitor-openrouter.ts
Original file line number Diff line number Diff line change
@@ -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 })
}
}