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

fish-audio.test.ts

170 lines5.5 KB

1import { price } from '@modelschemas/rate-card'
2import { afterEach, describe, expect, it } from 'vitest'
3​
4import { classifyAndBundle } from '#/server/ingest/sync.ts'
5import { parseStoredRateCard } from '#/server/rate-card.ts'
6​
7import type { OpenApiDocument } from '../types.ts'
8import {
9 FISH_AUDIO_PRICING_URL,
10 fishAudioCard,
11 parseFishAudioPricing,
12 provider,
13} from './fish-audio.ts'
14​
15const originalFetch = globalThis.fetch
16​
17afterEach(() => {
18 globalThis.fetch = originalFetch
19})
20​
21// Excerpt of the pricing page as served on 2026-11-10.
22const PRICING_PAGE = `
23## API Pricing
24​
25### Text-to-Speech (TTS) Models
26​
27| Model Name | Price (USD) |
28| - | - |
29| \`drama-3\` | \\$50.00 / M UTF-8 bytes |
30| \`s2.1-pro\` | \\$15.00 / M UTF-8 bytes |
31| \`s2.1-pro-free\` | \\$0.00 / M UTF-8 bytes |
32| \`s1\` (deprecated, retiring December 31, 2026) | \\$15.00 / M UTF-8 bytes |
33​
34Through November 30, 2026 (until December 1, 00:00 PT / 08:00 UTC), \`drama-3\` is
35billed at a launch promotion price of \\$10.00 / M UTF-8 bytes, 80% off the list
36price above.
37​
38### Automatic Speech Recognition (ASR) Models
39​
40| Model Name | Price (USD) |
41| - | - |
42| \`transcribe-1-pro\` (recommended) | \\$0.36 / audio hour |
43| \`transcribe-stream-1\` (Realtime ASR, Preview) | \\$0.36 / session hour |
44​
45### Voice Design
46​
47| Model Name | Price (USD) |
48| - | - |
49| \`voice-design-1\` | \\$0.01 / successful API request |
50​
51## Rate Limits
52​
53| Tier | Spending Threshold | Concurrent Requests |
54| - | - | - |
55| Starter | \\< \\$100 paid | 5 requests |
57​
58const SOURCE = {
59 url: FISH_AUDIO_PRICING_URL,
60 hash: 'a'.repeat(64),
61 extractedAt: '2026-11-10T00:00:00.000Z',
63const PROMO_END = Date.UTC(2026, 11, 1, 8)
64​
65describe('parseFishAudioPricing', () => {
66 const rows = parseFishAudioPricing(PRICING_PAGE)
67​
68 it('reads each section row and the drama-3 promotion', () => {
69 expect([...rows.keys()]).toEqual([
70 'drama-3',
71 's2.1-pro',
72 's2.1-pro-free',
73 's1',
74 'transcribe-1-pro',
75 'transcribe-stream-1',
76 'voice-design-1',
77 ])
78 expect(rows.get('drama-3')?.promo).toEqual({ usd: 10, endsAt: PROMO_END })
79 expect(rows.get('transcribe-1-pro')?.route).toBe('v1/asr')
80 })
81​
82 it('bills the promotion until it ends, then the list price', () => {
83 const drama = rows.get('drama-3')
84 if (!drama) throw new Error('no drama-3')
85 const during = fishAudioCard(drama, SOURCE, PROMO_END - 1)
86 expect(during && price(during, {}, { utf8_bytes: 1e6 })).toBeCloseTo(10)
87 expect(during?.source.expiresAt).toBe('2026-12-01T08:00:00.000Z')
88 const after = fishAudioCard(drama, SOURCE, PROMO_END)
89 expect(after && price(after, {}, { utf8_bytes: 1e6 })).toBeCloseTo(50)
90 expect(after?.source.expiresAt).toBeUndefined()
91 })
92​
93 it('prices per audio second, per request, and free at zero', () => {
94 const card = (id: string) => {
95 const row = rows.get(id)
96 return row ? fishAudioCard(row, SOURCE, 0) : null
97 }
98 const asr = card('transcribe-1-pro')
99 expect(asr && price(asr, {}, { audio_seconds: 3600 })).toBeCloseTo(0.36)
100 const design = card('voice-design-1')
101 expect(design && price(design)).toBeCloseTo(0.01)
102 const free = card('s2.1-pro-free')
103 expect(parseStoredRateCard(free)).not.toBeNull()
104 expect(free && price(free, {}, { utf8_bytes: 1e6 })).toBe(0)
105 })
106​
107 it('throws on an unread price, an unparsed promotion, or a row with no id', () => {
108 expect(() =>
109 parseFishAudioPricing(PRICING_PAGE.replace('/ audio hour', '/ minute')),
110 ).toThrow(/transcribe-1-pro has an unread price/)
111 expect(() =>
112 parseFishAudioPricing(
113 PRICING_PAGE.replace('Through November 30, 2026', 'Until Nov 30'),
114 ),
115 ).toThrow(/promotion/)
116 expect(() =>
117 parseFishAudioPricing(PRICING_PAGE.replace('`s2.1-pro`', 's2.1-pro')),
118 ).toThrow(/row "s2.1-pro" names no model id/)
119 })
120})
121​
122describe('fish-audio provider', () => {
123 it('lists models from the pricing page; the realtime model binds no route', async () => {
124 globalThis.fetch = () => Promise.resolve(new Response(PRICING_PAGE))
125 const { models } = await provider.listModels({})
126 const byId = new Map(models.map((m) => [m.rawId, m]))
127 expect(byId.get('s2.1-pro')?.schemaEndpointId).toBe('v1/tts')
128 expect(byId.get('transcribe-stream-1')?.schemaEndpointId).toBeNull()
129 expect(byId.get('transcribe-1-pro')?.modalities).toMatchObject({
130 input: ['audio'],
131 output: ['text'],
132 })
133 expect(models.every((m) => m.activity === 'audio')).toBe(true)
134 })
135​
136 it('classifies the speech routes and voice-model create, not agents', () => {
137 const body = (properties: Record<string, unknown>) => ({
138 requestBody: {
139 content: {
140 'application/json': { schema: { type: 'object', properties } },
141 },
142 },
143 responses: { '200': { description: 'ok' } },
144 })
145 const spec = {
146 openapi: '3.1.0',
147 paths: {
148 '/v1/tts': { post: body({ text: { type: 'string' } }) },
149 '/v1/asr': { post: body({ audio: { type: 'string' } }) },
150 '/model': { post: body({ title: { type: 'string' } }) },
151 '/v1/agent/agents': { post: body({ name: { type: 'string' } }) },
152 },
153 } as unknown as OpenApiDocument
154 const { endpoints } = classifyAndBundle(provider, {
155 specs: [spec],
156 sources: [
157 {
158 url: 'https://docs.fish.audio/api-reference/openapi.json',
159 hash: 'h',
160 },
161 ],
162 outputStrategy: 'post-200',
163 })
164 expect(endpoints.map((e) => e.dbId)).toEqual([
165 'fish-audio/v1/tts',
166 'fish-audio/v1/asr',
167 'fish-audio/model',
168 ])
169 })
170})