snapshot-pricing.mjs
Language JavaScript1.3 KB27 lines
// Refresh the bundled price list: node scripts/snapshot-pricing.mjs// DeepInfra's model list needs no key. Only ids, prices, context and tags are// kept (the descriptions are marketing copy the app never shows).import { writeFileSync } from 'node:fs'const res = await fetch('https://api.deepinfra.com/v1/openai/models')if (!res.ok) throw new Error(`models list: HTTP ${res.status}`)const { data } = await res.json()const keep = data.filter((m) => m.metadata?.tags?.includes('chat') && m.metadata?.pricing?.input_tokens != null).map((m) => ({id: m.id,metadata: {context_length: m.metadata.context_length ?? null,max_tokens: m.metadata.max_tokens ?? null,pricing: Object.fromEntries(['input_tokens', 'output_tokens', 'cache_read_tokens'].filter((k) => m.metadata.pricing[k] != null).map((k) => [k, Math.round(m.metadata.pricing[k] * 1e6) / 1e6]),),tags: m.metadata.tags,},})).sort((a, b) => a.id.localeCompare(b.id))const out = { fetched_at: new Date().toISOString().slice(0, 10), source: 'https://api.deepinfra.com/v1/openai/models', data: keep }writeFileSync(new URL('../crates/cortex-core/data/pricing-snapshot.json', import.meta.url), JSON.stringify(out, null, 1) + '\n')console.log(`wrote ${keep.length} chat models`)