Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

deepgram-pricing.test.ts

102 lines3.5 KB

1import { describe, expect, it } from 'vitest'
2​
3import { price } from '@modelschemas/rate-card'
4import type { RateCard } from '@modelschemas/rate-card'
5​
6import { deepgramCard, parseDeepgramPricing } from './deepgram-pricing.ts'
7​
8const SOURCE = {
9 url: 'https://deepgram.com/pricing',
10 hash: 'abc',
11 extractedAt: '2026-10-03T00:00:00.000Z',
13​
14function offers(rows: Array<[string, string]>): string {
15 const ld = rows
16 .map(
17 ([product, amount]) =>
18 `{"@type":"Offer","name":"Deepgram Voice AI Platform Pricing - ${product} - Pay As You Go","price":"${amount}","priceCurrency":"USD"}`,
19 )
20 .join(',')
21 const units = rows
22 .map(([product, amount]) =>
23 product === 'Flux TTS' || product.startsWith('Aura')
24 ? `$${amount}/1k characters`
25 : `$${amount}/min`,
26 )
27 .join(' ')
28 return `${ld} ${units}`
30​
31const PAGE =
32 offers([
33 ['Streaming - Flux English', '0.0065'],
34 ['Streaming - Flux Multilingual', '0.0078'],
35 ['Streaming - Nova-3 Monolingual', '0.0048'],
36 ['Streaming - Nova-3 Multilingual', '0.0058'],
37 ['Pre-Recorded - Nova-3 Monolingual', '0.0043'],
38 ['Pre-Recorded - Nova-3 Multilingual', '0.0052'],
39 ['Pre-Recorded - Whisper Large', '0.0048'],
40 ['Flux TTS', '0.0450'],
41 ['Aura-2', '0.030'],
42 ['Aura-1', '0.0150'],
43 ]) +
44 '{"@type":"Offer","name":"Deepgram Voice AI Platform Pricing - Streaming - Nova-3 Monolingual - Growth","price":"9.99"}'
45​
46function usd(
47 card: RateCard | null,
48 usage: Record<string, number | string>,
49): number {
50 if (!card) throw new Error('missing card')
51 return price(card, {}, usage)
53​
54describe('deepgram pricing page', () => {
55 it('reads Pay As You Go family rates and skips a unit the page does not show', () => {
56 const rates = parseDeepgramPricing(PAGE)
57 expect(rates.get('Streaming - Flux English')).toBe(0.0065)
58 expect(rates.get('Aura-2')).toBe(0.03)
59 expect(rates.get('Aura-1')).toBe(0.015)
60 expect(rates.get('Streaming - Nova-3 Monolingual')).toBe(0.0048)
61 expect(parseDeepgramPricing(PAGE.replace('$0.0065/min', ''))).toEqual(
62 new Map(),
63 )
64 })
65​
66 it('shares one Aura-2 character rate and prices Nova-3 by mode', () => {
67 const rates = parseDeepgramPricing(PAGE)
68 const aura = deepgramCard('aura-2-thalia-en', rates, SOURCE)
69 const aura1 = deepgramCard('aura-asteria-en', rates, SOURCE)
70 const fluxVoice = deepgramCard('flux-alexis-en', rates, SOURCE)
71 const nova = deepgramCard('nova-3-general', rates, SOURCE)
72 const medical = deepgramCard('nova-3-medical', rates, SOURCE)
73 expect(usd(aura, { characters: 1000 })).toBeCloseTo(0.03, 9)
74 expect(usd(aura1, { characters: 1000 })).toBeCloseTo(0.015, 9)
75 expect(usd(fluxVoice, { characters: 1000 })).toBeCloseTo(0.045, 9)
76 expect(
77 usd(nova, {
78 audio_seconds: 60,
79 listen_mode: 'streaming',
80 language_scope: 'monolingual',
81 }),
82 ).toBeCloseTo(0.0048, 9)
83 expect(
84 usd(nova, {
85 audio_seconds: 60,
86 listen_mode: 'pre_recorded',
87 language_scope: 'multilingual',
88 }),
89 ).toBeCloseTo(0.0052, 9)
90 expect(
91 usd(medical, { audio_seconds: 60, listen_mode: 'pre_recorded' }),
92 ).toBeCloseTo(0.0043, 9)
93 expect(deepgramCard('nova-2-general', rates, SOURCE)).toBeNull()
94 expect(deepgramCard('whisper-large', rates, SOURCE)).toBeNull()
95 expect(deepgramCard('enhanced-general', rates, SOURCE)).toBeNull()
96 expect(
97 usd(deepgramCard('flux-general-en', rates, SOURCE), {
98 audio_seconds: 60,
99 }),
100 ).toBeCloseTo(0.0065, 9)
101 })
102})