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
26 changes: 15 additions & 11 deletions api/cron/monitor-chutes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { runMonitor, round6 } from '@models.dev/monitor'
import { runMonitor, round6 } from '../../packages/monitor/index.ts'

export const config = { maxDuration: 60 }
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 })
export default async function handler(req: any, res: any) {
const authHeader = req.headers['authorization']
if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
return res.status(401).send('Unauthorized')
}

try {
Expand All @@ -16,19 +19,20 @@ export default async function handler(req: Request) {
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 } }> }
const fetchRes = await fetch('https://llm.chutes.ai/v1/models', { headers })
if (!fetchRes.ok) throw new Error(`Chutes API error: ${fetchRes.status}`)
const data = await fetchRes.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')
return res.send('ok')
} catch (err) {
console.error(err)
return new Response(String(err), { status: 500 })
return res.status(500).send('error')
}
}
}
25 changes: 14 additions & 11 deletions api/cron/monitor-openrouter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { runMonitor, round6 } from '@models.dev/monitor'
import { runMonitor, round6 } from '../../packages/monitor/index.ts'

export const config = { maxDuration: 60 }
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 })
export default async function handler(req: any, res: any) {
const authHeader = req.headers['authorization']
if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
return res.status(401).send('Unauthorized')
}

try {
Expand All @@ -13,19 +16,19 @@ export default async function handler(req: Request) {
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 } }> }
const fetchRes = await fetch('https://openrouter.ai/api/v1/models')
if (!fetchRes.ok) throw new Error(`OpenRouter API error: ${fetchRes.status}`)
const data = await fetchRes.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')
return res.send('ok')
} catch (err) {
console.error(err)
return new Response(String(err), { status: 500 })
return res.status(500).send('error')
}
}
}
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
}
},
"dependencies": {
"@aws-sdk/client-s3": "^3.1000.0"
"@aws-sdk/client-s3": "^3.1000.0",
"@models.dev/monitor": "workspace:*"
}
}
38 changes: 0 additions & 38 deletions packages/web/api/cron/monitor-chutes.ts

This file was deleted.

34 changes: 0 additions & 34 deletions packages/web/api/cron/monitor-openrouter.ts

This file was deleted.

9 changes: 5 additions & 4 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"installCommand": "bun install",
"framework": null,
"cleanUrls": false,
"functions": {
"api/cron/*.ts": {
"includeFiles": "packages/monitor/**"
}
},
"crons": [
{
"path": "/api/cron/monitor-openrouter",
Expand All @@ -32,10 +37,6 @@
{
"source": "/logos/:path*",
"destination": "/logos/default.svg"
},
{
"source": "/(.*)",
"destination": "/_index.html"
}
]
}