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

byteplus-speech-pricing.test.ts

81 lines2.6 KB

1import { describe, expect, it } from 'vitest'
2​
3import { price, priceDetailed } from '@modelschemas/rate-card'
4​
5import type { ByteplusDoc } from './byteplus-pricing.ts'
6import {
7 compileSeedAudioCard,
8 parseSeedAsrRate,
9 parseSeedAudioCap,
10 parseSeedAudioRate,
11 parseSpeechRates,
12} from './byteplus-speech-pricing.ts'
13import asrPricing from './fixtures/byteplus-asr-pricing.json'
14import audioPricing from './fixtures/byteplus-audio-pricing.json'
15​
16// The two billing pages' `curDoc.Content`, read 2026-11-17.
17const audioDoc = audioPricing as unknown as ByteplusDoc
18const asrDoc = asrPricing as unknown as ByteplusDoc
19/** The `original_duration` line of the API page, as its op reads. */
20const apiDoc: ByteplusDoc = {
21 data: {
22 '0': {
23 ops: [
24 {
25 insert:
26 "Duration of the model's original output audio (in seconds). This is also the duration used for billing, with a maximum of 120s.\n",
27 },
28 ],
29 },
30 },
32​
33const SOURCE = { url: 'https://x', hash: 'h', extractedAt: '2026-11-17' }
34​
35describe('byteplus speech pricing pages', () => {
36 it('reads Seed Audio 1.0 at $0.15 per minute', () => {
37 expect(parseSeedAudioRate(audioDoc)).toBe(0.0025)
38 })
39​
40 it('reads each ASR mode and picks fast mode for seed-asr', () => {
41 expect(parseSpeechRates(asrDoc).map((rate) => rate.label)).toEqual([
42 'Streaming ASR',
43 'Audio File ASR',
44 'Audio File ASR Fast Mode',
45 ])
46 // $0.36 per hour.
47 expect(parseSeedAsrRate(asrDoc)).toBe(0.0001)
48 })
49​
50 it('reads the 120 second billing maximum off the API page', () => {
51 expect(parseSeedAudioCap(apiDoc)).toBe(120)
52 })
53​
54 it('throws rather than pricing a page it cannot read', () => {
55 expect(() => parseSeedAudioRate(asrDoc)).toThrow(/3 price tables/)
56 expect(() => parseSeedAsrRate(audioDoc)).toThrow(/0 "Audio File ASR Fast/)
57 expect(() => parseSeedAudioCap(audioDoc)).toThrow(/maximum of Ns/)
58 const perMonth = JSON.parse(
59 JSON.stringify(audioDoc).replace('minute\\n', 'month\\n'),
60 ) as ByteplusDoc
61 expect(() => parseSeedAudioRate(perMonth)).toThrow(/unreadable/)
62 })
63})
64​
65describe('Seed Audio card', () => {
66 const card = compileSeedAudioCard(
67 0.0025,
68 { seconds: 120, url: 'https://api', hash: 'c' },
69 SOURCE,
70 )
71​
72 it('bills the seconds the response reports', () => {
73 expect(price(card, {}, { original_duration: 60 })).toBeCloseTo(0.15, 12)
74 })
75​
76 it('labels the 120 second maximum as an estimate when none are given', () => {
77 const held = priceDetailed(card, {}, {})
78 expect(held.estimated).toEqual(['original_duration'])
79 expect(held.amount).toBeCloseTo(0.3, 12)
80 })
81})