mattrguerra/cortexmainPrivate on GitHub, published here in full

snapshot-pricing.mjs

Language JavaScript1.3 KB27 lines

scripts/snapshot-pricing.mjs

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