Open History to see the last commit
1import { afterEach, describe, expect, it } from 'vitest'
2
3import { DEEPGRAM_PRICING_URL } from '../deepgram-pricing.ts'
4import { provider } from './deepgram.ts'
5
6const originalFetch = globalThis.fetch
7
8afterEach(() => {
9 globalThis.fetch = originalFetch
10})
11
12describe('deepgram provider', () => {
13 it('exports seed metadata for auto-registration', () => {
14 expect(provider.id).toBe('deepgram')
15 expect(provider.displayName).toBe('Deepgram')
16 expect(provider.authEnvVar).toBe('DEEPGRAM_API_KEY')
17 expect(provider.specSourceUrl).toBe(
18 'https://developers.deepgram.com/openapi.json',
19 )
20 expect(provider.modelsEndpoint).toBe('https://api.deepgram.com/v1/models')
21 expect(provider.defaultDerivation).toBe('upstream-spec')
22 })
23})
24
25describe('deepgram classify', () => {
26 it('maps listen, speak, and agent converse to audio', () => {
27 expect(provider.classify('/v1/listen', {})).toBe('audio')
28 expect(provider.classify('/v2/listen', {})).toBe('audio')
29 expect(provider.classify('/v1/speak', {})).toBe('audio')
30 expect(provider.classify('/v2/speak', {})).toBe('audio')
31 expect(provider.classify('/v1/agent/converse', {})).toBe('audio')
32 })
33
34 it('drops project, key, auth, read, and models surfaces', () => {
35 expect(provider.classify('/v1/projects', {})).toBeNull()
36 expect(provider.classify('/v1/projects/{project_id}/keys', {})).toBeNull()
37 expect(provider.classify('/v1/projects/{project_id}/agents', {})).toBeNull()
38 expect(provider.classify('/v1/auth/grant', {})).toBeNull()
39 expect(provider.classify('/v1/read', {})).toBeNull()
40 expect(provider.classify('/v1/models', {})).toBeNull()
41 })
42})
43
44describe('deepgram listModels', () => {
45 it('skips when the API key is absent', async () => {
46 const result = await provider.listModels({})
47 expect(result.models).toEqual([])
48 expect(result.skipped).toBe('deepgram: DEEPGRAM_API_KEY not set — skipped')
49 })
50
51 it('lists STT and TTS models with Token auth', async () => {
52 const calls: Array<{ url: string; init?: RequestInit }> = []
53 globalThis.fetch = ((url: string, init?: RequestInit) => {
54 calls.push({ url: String(url), init })
55 if (String(url) === DEEPGRAM_PRICING_URL) {
56 return Promise.resolve(
57 new Response(
58 [
59 '{"name":"Deepgram Voice AI Platform Pricing - Streaming - Flux English - Pay As You Go","price":"0.0065"}',
60 '{"name":"Deepgram Voice AI Platform Pricing - Streaming - Flux Multilingual - Pay As You Go","price":"0.0078"}',
61 '{"name":"Deepgram Voice AI Platform Pricing - Streaming - Nova-3 Monolingual - Pay As You Go","price":"0.0048"}',
62 '{"name":"Deepgram Voice AI Platform Pricing - Streaming - Nova-3 Multilingual - Pay As You Go","price":"0.0058"}',
63 '{"name":"Deepgram Voice AI Platform Pricing - Pre-Recorded - Nova-3 Monolingual - Pay As You Go","price":"0.0043"}',
64 '{"name":"Deepgram Voice AI Platform Pricing - Pre-Recorded - Nova-3 Multilingual - Pay As You Go","price":"0.0052"}',
65 '{"name":"Deepgram Voice AI Platform Pricing - Flux TTS - Pay As You Go","price":"0.0450"}',
66 '{"name":"Deepgram Voice AI Platform Pricing - Aura-2 - Pay As You Go","price":"0.030"}',
67 '{"name":"Deepgram Voice AI Platform Pricing - Aura-1 - Pay As You Go","price":"0.0150"}',
68 '$0.0065/min $0.0078/min $0.0048/min $0.0058/min $0.0043/min $0.0052/min $0.0450/1k $0.030/1k $0.0150/1k',
69 ].join(' '),
70 ),
71 )
72 }
73 return Promise.resolve(
74 new Response(
75 JSON.stringify({
76 stt: [{ name: 'Nova-3', canonical_name: 'nova-3' }],
77 tts: [
78 { name: 'Aura-2 Thalia', canonical_name: 'aura-2-thalia-en' },
79 { name: 'Nova-2', canonical_name: 'nova-2-general' },
80 ],
81 }),
82 ),
83 )
84 }) as typeof fetch
85
86 const result = await provider.listModels({ DEEPGRAM_API_KEY: 'test-key' })
87 expect(result.skipped).toBeUndefined()
88 expect(
89 result.models.map(
90 ({ pricing: _pricing, factSources: _sources, ...model }) => model,
91 ),
92 ).toEqual([
93 {
94 rawId: 'nova-3',
95 displayName: 'Nova-3',
96 activity: 'audio',
97 modalities: { input: ['audio'], output: ['text'] },
98 schemaEndpointId: 'v1/listen',
99 },
100 {
101 rawId: 'aura-2-thalia-en',
102 displayName: 'Aura-2 Thalia',
103 activity: 'audio',
104 modalities: { input: ['text'], output: ['audio'] },
105 schemaEndpointId: 'v1/speak',
106 },
107 {
108 rawId: 'nova-2-general',
109 displayName: 'Nova-2',
110 activity: 'audio',
111 modalities: { input: ['text'], output: ['audio'] },
112 schemaEndpointId: 'v1/speak',
113 },
114 ])
115 expect(result.models[0]?.pricing).toBeTruthy()
116 expect(result.models[1]?.pricing).toBeTruthy()
117 expect(result.models[2]?.pricing ?? null).toBeNull()
118 expect(calls[0]).toEqual({
119 url: 'https://api.deepgram.com/v1/models',
120 init: { headers: { Authorization: 'Token test-key' } },
121 })
122 expect(calls[1]?.url).toBe(DEEPGRAM_PRICING_URL)
123 })
124})
125
126describe('deepgram fetchSpec', () => {
127 it('loads the public OpenAPI document without a key', async () => {
128 const spec = {
129 openapi: '3.1.0',
130 info: { title: 'REST API', version: '1.0.0' },
131 paths: {
132 '/v1/listen': { post: { summary: 'Transcribe' } },
133 },
134 }
135 const urls: Array<string> = []
136 globalThis.fetch = ((url: string) => {
137 urls.push(String(url))
138 return Promise.resolve(new Response(JSON.stringify(spec)))
139 }) as typeof fetch
140
141 const result = await provider.fetchSpec({})
142 expect(urls).toEqual(['https://developers.deepgram.com/openapi.json'])
143 expect(result.skipped).toBeUndefined()
144 expect(result.outputStrategy).toBe('post-200')
145 expect(result.specs).toHaveLength(1)
146 expect(result.specs[0]?.info?.title).toBe('REST API')
147 expect(result.sources[0]?.url).toBe(
148 'https://developers.deepgram.com/openapi.json',
149 )
150 expect(result.sources[0]?.hash).toMatch(/^[0-9a-f]{64}$/)
151 })
152})