Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { price, priceDetailed } from '@modelschemas/rate-card'
4
5import { storeListedPricing } from '../rate-card.ts'
6
7import {
8 byteplusRatesFor,
9 compileSeedanceCard,
10 compileSeedreamProCard,
11 parseByteplusAliases,
12 parseByteplusImages,
13 parseByteplusPixelTiers,
14 parseByteplusPricing,
15 parseByteplusVideo,
16 parseSeedanceGeometry,
17 sharePublishedAliases,
18} from './byteplus-pricing.ts'
19import type { ByteplusDoc } from './byteplus-pricing.ts'
20
21function cell(id: string, text: string) {
22 return {
23 ops: [{ insert: '*', attributes: { lmkr: '1' } }, { insert: `${text}\n` }],
24 zoneId: id,
25 zoneType: 'Z',
26 }
27}
28
29/** Chat-table header: model, tier, input, audio, cache storage, cache hit, audio cache, output. */
30const CHAT_HEADERS = [
31 'Model ID',
32 'Pricing tiers (K tokens)',
33 'Input (non-audio) (USD/M tokens)',
34 'Input (audio) (USD/M tokens)',
35 'Cache-storage (USD/M tokens/Hour)',
36 'Cache-hit input (non-audio) (USD/M tokens)',
37 'Cache-hit input (audio) (USD/M tokens)',
38 'Output (USD/M tokens)',
39]
40
41/** Page document of `tables`, each a header row then body rows. */
42function doc(...tables: Array<Array<Array<string>>>): ByteplusDoc {
43 const data: ByteplusDoc['data'] = { '0': { ops: [] } }
44 tables.forEach((body, t) => {
45 data['0']?.ops?.push({
46 insert: '*',
47 attributes: { aceTable: `rows${t} cols${t}` },
48 })
49 data[`rows${t}`] = {
50 ops: body.map((_, index) => ({ insert: { id: `t${t}r${index}` } })),
51 zoneType: 'R',
52 }
53 data[`cols${t}`] = {
54 ops: (body[0] ?? []).map((_, index) => ({
55 insert: { id: `t${t}c${index}` },
56 })),
57 zoneType: 'C',
58 }
59 body.forEach((cells, row) => {
60 cells.forEach((text, column) => {
61 const id = `xt${t}r${row}xt${t}c${column}`
62 data[id] = cell(id, text)
63 })
64 })
65 })
66 return { data }
67}
68
69describe('byteplus pricing page', () => {
70 it('reads standard token rates, tiers, and a dated catalog suffix', () => {
71 const rates = parseByteplusPricing(
72 doc([
73 CHAT_HEADERS,
74 [
75 'dola-seed-2-1-turbo',
76 'Prompt length [0, 256]',
77 '0.5',
78 '-',
79 '0.0083',
80 '0.1',
81 '-',
82 '2.5',
83 ],
84 [
85 'seed-2-0-pro-260328',
86 'Prompt length [0, 128]',
87 '0.50',
88 '-',
89 '0.0083',
90 '0.10',
91 '-',
92 '3.00',
93 ],
94 [
95 '',
96 'Prompt length (128, 256]',
97 '1.00',
98 '-',
99 '0.0083',
100 '0.20',
101 '-',
102 '6.00',
103 ],
104 [
105 'seed-2-0-lite-260428',
106 'Prompt length [0, 128]',
107 '0.25',
108 '3.75',
109 '0.0083',
110 '0.05',
111 '0.75',
112 '2.00',
113 ],
114 [
115 'deepseek-v4-1-flash-260910',
116 'Off-peak hours',
117 '0.15',
118 '-',
119 '0.0083',
120 '0.003',
121 '-',
122 '0.60',
123 ],
124 ['', 'Peak hours', '0.30', '-', '0.0083', '0.006', '-', '1.20'],
125 ['glm-5-2-260617', '-', '1.4', '-', '0.0083', '0.26', '-', '4.4'],
126 ]),
127 )
128 expect(rates.get('glm-5-2-260617')).toEqual({
129 base: {
130 input_tokens: 1.4e-6,
131 cache_read_tokens: 0.26e-6,
132 output_tokens: 4.4e-6,
133 },
134 tiers: [],
135 })
136 expect(rates.get('seed-2-0-lite-260428')?.base.audio_tokens).toBe(3.75e-6)
137 expect(rates.get('seed-2-0-pro-260328')?.tiers).toEqual([
138 {
139 minPromptTokens: 128_000,
140 rates: {
141 input_tokens: 1 / 1e6,
142 cache_read_tokens: 0.2 / 1e6,
143 output_tokens: 6 / 1e6,
144 },
145 },
146 ])
147 // Cache storage is per hour, so it is not a lever.
148 expect(rates.get('glm-5-2-260617')?.base).not.toHaveProperty(
149 'cache_storage',
150 )
151 // Peak and off-peak have no time lever.
152 expect(rates.has('deepseek-v4-1-flash-260910')).toBe(false)
153 expect(
154 byteplusRatesFor('dola-seed-2-1-turbo-260628', rates)?.base.input_tokens,
155 ).toBe(0.5e-6)
156 expect(byteplusRatesFor('seed-translation-250915', rates)).toBeUndefined()
157 // Only a dated suffix reaches an undated row, never a sibling model.
158 expect(
159 byteplusRatesFor('dola-seed-2-1-turbo-flash-260628', rates),
160 ).toBeUndefined()
161 })
162})
163
164const SOURCE = {
165 url: 'https://docs.byteplus.com/en/docs/ModelArk/1544106',
166 hash: 'a'.repeat(64),
167 extractedAt: '2026-10-02T00:00:00Z',
168}
169
170/** Rate cells as the live page words them (read 2026-10-02). */
171const VIDEO_TABLE = [
172 [
173 'Model ID',
174 'Online inference (USD / M tokens)',
175 'Offline inference (USD / M tokens)',
176 ],
177 [
178 'dreamina-seedance-2-5-260628 Pricing varies based on output video resolution and whether the input includes video.',
179 'For 480p and 720p outputs: Input without video: 10.70 Input with video: 6.40 For 1080p outputs: Input without video: 11.7 Input with video: 7.0',
180 'Not supported yet',
181 ],
182 [
183 'dreamina-seedance-2-0-fast-260128 Pricing varies based on whether the input includes video.',
184 'For 480p and 720p outputs: Input without video: (Original) 5.6 Time limited 25% off Input with video: (Original) 3.3 Time limited 25% off',
185 'Not supported yet',
186 ],
187 [
188 'seedance-1-5-pro-251215 Pricing varies based on whether the output includes audio',
189 'Video with audio: 2.4 Video without audio: 1.2',
190 'Video with audio: 1.2 Video without audio: 0.6',
191 ],
192 ['seedance-1-0-pro-250528', '2.5', '1.25'],
193 ['seedance-9-unknown-261231', 'Contact sales', 'Not supported yet'],
194 // Promo text with no "(Original)" may be the discounted rate: refuse.
195 ['seedance-9-promo-261231', '4.2 Time limited 25% off', 'Not supported yet'],
196]
197
198const IMAGE_TABLE = [
199 [
200 'Model ID',
201 'Input image price (USD / image)',
202 'Output image price (USD / image)',
203 ],
204 [
205 'dola-seedream-5-0-pro-260628 Pricing varies by image generation scenario.',
206 'First image: Free From the 2nd image: 0.003',
207 'Single image generation: ≤ 2.61 million pixels (1.5K or lower): 0.045 > 2.61 million pixels (higher than 1.5K): 0.09 Layer decomposition: ≤ 2.61 million pixels (1.5K or lower): 0.0225 > 2.61 million pixels (higher than 1.5K): 0.045',
208 ],
209 ['seedream-5-0-lite-260128', 'Free', '0.035'],
210 ['dola-seedream-5-0-flash-260915', 'Free', '0.018'],
211 ['seedream-4-5-251128', 'Free', '0.04'],
212 ['seedream-4-0-250828', 'Free', '0.03'],
213]
214
215describe('byteplus video and image tables', () => {
216 const page = doc(VIDEO_TABLE, IMAGE_TABLE)
217 const video = parseByteplusVideo(page)
218
219 it('reads list prices per tier, resolution, and variant', () => {
220 expect(video.get('dreamina-seedance-2-0-fast-260128')).toEqual({
221 default: {
222 '480p': { no_video: 5.6, video: 3.3 },
223 '720p': { no_video: 5.6, video: 3.3 },
224 },
225 })
226 // No "For … outputs": one rate whatever the resolution.
227 expect(video.get('seedance-1-0-pro-250528')).toEqual({
228 default: { '*': { all: 2.5 } },
229 flex: { '*': { all: 1.25 } },
230 })
231 expect(video.has('seedance-9-unknown-261231')).toBe(false)
232 expect(video.has('seedance-9-promo-261231')).toBe(false)
233 expect(parseByteplusImages(page)).toEqual(
234 new Map([
235 ['seedream-5-0-lite-260128', 0.035],
236 ['dola-seedream-5-0-flash-260915', 0.018],
237 ['seedream-4-5-251128', 0.04],
238 ['seedream-4-0-250828', 0.03],
239 ]),
240 )
241 })
242
243 it('copies a flat image price onto the model list alias, not onto chat', () => {
244 const images = parseByteplusImages(page)
245 const listed = doc([
246 [
247 'seedream-5-0-260128 (also supports: seedream-5-0-lite-260128)',
248 'seedream-5-0-260128 (also supports: seedream-9-other-260128)',
249 ],
250 ])
251 // Two different aliases for one id: not one price.
252 expect(parseByteplusAliases(listed).size).toBe(0)
253 const once = doc([
254 ['seedream-5-0-260128\n(also supports: seedream-5-0-lite-260128)'],
255 ])
256 const aliases = parseByteplusAliases(once)
257 sharePublishedAliases(images, aliases)
258 expect(images.get('seedream-5-0-260128')).toBe(0.035)
259 expect(images.get('seedream-5-0-lite-260128')).toBe(0.035)
260 // No speech table on this page, and no price for an unlisted snapshot.
261 expect(images.has('seed-asr')).toBe(false)
262 expect(images.has('seed-audio-1.0')).toBe(false)
263 expect(images.has('seedream-4-0-20260415')).toBe(false)
264 })
265
266 it('prices billed completion_tokens and refuses what it cannot know', () => {
267 const usd = (
268 id: string,
269 request: Record<string, unknown>,
270 usage?: Record<string, unknown>,
271 ) => {
272 const rates = video.get(id)
273 const card = rates && compileSeedanceCard(rates, SOURCE)
274 if (!card) throw new Error(`no card for ${id}`)
275 return Number(price(card, request, usage).toFixed(4))
276 }
277 const v25 = 'dreamina-seedance-2-5-260628'
278 expect(
279 usd(
280 v25,
281 { resolution: '1080p' },
282 { completion_tokens: 1e6, input_video: true },
283 ),
284 ).toBe(7)
285 // Seedance 1.0 Pro usage table: 489600 tokens → 1.22.
286 expect(
287 usd('seedance-1-0-pro-250528', {}, { completion_tokens: 489_600 }),
288 ).toBe(1.224)
289 expect(
290 usd(
291 'seedance-1-5-pro-251215',
292 { generate_audio: true, service_tier: 'flex' },
293 { completion_tokens: 1e6 },
294 ),
295 ).toBe(1.2)
296 const billed = { completion_tokens: 1e6, input_video: false }
297 // No billed count, no stated video input, no audio choice: refuse.
298 expect(() => usd(v25, { resolution: '720p' }, {})).toThrow(
299 /completion_tokens/,
300 )
301 expect(() =>
302 usd(v25, { resolution: '720p' }, { completion_tokens: 1e6 }),
303 ).toThrow(/input_video.*required/)
304 expect(() =>
305 usd('seedance-1-5-pro-251215', {}, { completion_tokens: 1 }),
306 ).toThrow(/generate_audio.*required/)
307 // Draft bills at another resolution; flex has no offline column.
308 expect(() =>
309 usd(v25, { resolution: '1080p', draft: true }, billed),
310 ).toThrow(/draft/)
311 expect(() =>
312 usd(v25, { resolution: '720p', service_tier: 'flex' }, billed),
313 ).toThrow(/flex/)
314 })
315
316 it('prices Seedream 5.0 pro by size tier and extra input images', () => {
317 const tiers = parseByteplusPixelTiers(page).get(
318 'dola-seedream-5-0-pro-260628',
319 )
320 const card = tiers && compileSeedreamProCard(tiers, SOURCE)
321 if (!card) throw new Error('no Seedream 5.0 pro card')
322 const usd = (request: Record<string, unknown>, inputImages = 0) =>
323 Number(
324 price(card, request, {
325 generated_images: 1,
326 input_images: inputImages,
327 }).toFixed(4),
328 )
329 // Omitted size is Ark's default 2K, the high tier.
330 expect(usd({})).toBe(0.09)
331 expect(usd({ size: '1K' })).toBe(0.045)
332 expect(usd({ size: '1.5K' })).toBe(0.045)
333 // WxH by pixel count: 1536² = 2.36 MP ≤ 2.61 MP; 2048² is above.
334 expect(usd({ size: '1536x1536' })).toBe(0.045)
335 expect(usd({ size: '2048x2048' })).toBe(0.09)
336 // First input image free, each further one 0.003 (usage.input_images).
337 expect(usd({ size: '1K' }, 1)).toBe(0.045)
338 expect(usd({ size: '1K' }, 3)).toBe(0.051)
339 // Layers mix tiers; 4K/auto are not generation sizes; usage is required.
340 expect(() => usd({ layer_decomposition: true })).toThrow(/layer/)
341 expect(() => usd({ size: '4K' })).toThrow(/unknown size/)
342 expect(() => usd({ size: 'auto' })).toThrow(/unknown size/)
343 expect(() => price(card, {}, { input_images: 0 })).toThrow(
344 /generated_images/,
345 )
346 expect(() => price(card, {}, { generated_images: 1 })).toThrow(
347 /input_images/,
348 )
349 })
350})
351
352/** The tutorial's model and pixel tables as the live page words them. */
353const GUIDE = doc(
354 [
355 [
356 'Model name',
357 '',
358 'Dreamina Seedance 2.0',
359 'Dreamina Seedance 2.0 Fast',
360 'Seedance 1.0 Pro',
361 ],
362 [
363 'Model ID',
364 '',
365 'dreamina-seedance-2-0-260128',
366 'dreamina-seedance-2-0-fast-260128',
367 'seedance-1-0-pro-250528',
368 ],
369 ['', 'Frame rate', '24 fps', '24 fps', '24 fps'],
370 ],
371 [
372 [
373 'Resolution',
374 'Aspect ratio',
375 'Dreamina Seedance 2.0 series',
376 'Seedance 1.0 series',
377 ],
378 ['720p', '16:9', '1280×720', '1248×704'],
379 ['', '4:3', '1112×834', '1120×832'],
380 [
381 '1080p Dreamina Seedance 2.0 Fast and Dreamina Seedance 2.0 Mini do not support 1080p',
382 '16:9',
383 '1920×1080',
384 '1920×1088',
385 ],
386 ['4k Only Dreamina Seedance 2.0 supports 4K', '16:9', '3840×2160', ''],
387 ['', '4:3', '3326×2494', '-'],
388 ['', '1:1', '2880×2880', '-'],
389 ['8k Contact sales for 8K', '16:9', '7680×4320', '7680×4320'],
390 ],
391)
392
393describe('byteplus video generation tutorial', () => {
394 const geometry = parseSeedanceGeometry(GUIDE)
395
396 it('reads frame rate and sizes per model, series columns included', () => {
397 expect(geometry.get('seedance-1-0-pro-250528')).toEqual({
398 fps: 24,
399 dims: {
400 '720p': {
401 '16:9': { w: 1248, h: 704 },
402 '4:3': { w: 1120, h: 832 },
403 },
404 '1080p': { '16:9': { w: 1920, h: 1088 } },
405 },
406 })
407 expect(
408 geometry.get('dreamina-seedance-2-0-260128')?.dims['4k']?.['4:3'],
409 ).toEqual({ w: 3326, h: 2494 })
410 })
411
412 it('labels the estimate, and keeps sizes to the resolutions priced', () => {
413 const id = 'dreamina-seedance-2-0-fast-260128'
414 const model = geometry.get(id)
415 if (!model) throw new Error('no geometry')
416 const card = compileSeedanceCard(
417 {
418 default: {
419 '480p': { no_video: 5.6, video: 3.3 },
420 '720p': { no_video: 5.6, video: 3.3 },
421 },
422 },
423 SOURCE,
424 { model, url: 'https://example.test/guide', hash: 'b'.repeat(64) },
425 )
426 if (!card) throw new Error('no card')
427 // The series column lists 1080p and 4K; Fast prices neither.
428 expect(Object.keys(card.tables.pixels ?? {})).toEqual(['720p'])
429 // Page: "Dreamina Seedance 2.0 Fast (USD) 0.60 per video" (720p 16:9 5 s).
430 const request = { resolution: '720p', ratio: '16:9', duration: 5 }
431 const result = priceDetailed(card, request, { input_video: false })
432 expect(result.estimated).toEqual(['completion_tokens'])
433 expect(result.amount.toFixed(2)).toBe('0.60')
434 // Video input carries a minimum-token floor the method does not cover
435 // unless the Lark range was supplied.
436 expect(() => priceDetailed(card, request, { input_video: true })).toThrow(
437 /estimate_supported/,
438 )
439 })
440
441 it('bills a short input video at the Lark minimum for that output', async () => {
442 const card = compileSeedanceCard(
443 {
444 default: {
445 '480p': { no_video: 10.7, video: 6.4 },
446 '720p': { no_video: 10.7, video: 6.4 },
447 '1080p': { no_video: 11.7, video: 7 },
448 },
449 },
450 SOURCE,
451 {
452 model: {
453 fps: 24,
454 dims: {
455 '480p': { '16:9': { w: 854, h: 480 } },
456 '720p': { '16:9': { w: 1280, h: 720 } },
457 '1080p': { '16:9': { w: 1920, h: 1080 } },
458 },
459 },
460 url: 'https://example.test/guide',
461 hash: 'b'.repeat(64),
462 videoMinimumsThrough: 30,
463 },
464 )
465 if (!card) throw new Error('no card')
466 const video = (duration: number, input = 0, resolution = '720p') =>
467 priceDetailed(
468 card,
469 { resolution, ratio: '16:9', duration, input_video_duration: input },
470 { input_video: true },
471 )
472 // Page: 720p 16:9, 5s out, 2–4s in → $1.244. 480p → $0.553.
473 expect(video(5, 2).amount.toFixed(3)).toBe('1.244')
474 expect(video(5, 2, '480p').amount.toFixed(3)).toBe('0.553')
475 // 30s out floors a 2s input at 20s in: 480,375 tokens × $6.40.
476 expect(video(30, 2, '480p').amount).toBeCloseTo((480_375 * 6.4) / 1e6, 6)
477 // Past the minimum, the real input length wins.
478 expect(video(30, 30, '480p').amount).toBeCloseTo((576_450 * 6.4) / 1e6, 6)
479 expect(() => video(31, 2)).toThrow(/min_input_seconds/)
480 // The generation schema has duration and ratio, not input seconds.
481 // That lever must still store; refusing it used to null the card.
482 const stored = await storeListedPricing(card, {
483 sourceUrl: 'https://docs.byteplus.com/en/docs/ModelArk/1544106',
484 now: 1_790_000_000,
485 requestProperties: new Set([
486 'service_tier',
487 'draft',
488 'resolution',
489 'duration',
490 'ratio',
491 ]),
492 })
493 expect(stored.refused).toBeUndefined()
494 expect(stored.card?.inputs.completion_tokens).toMatchObject({
495 kind: 'number',
496 })
497 })
498})
499
500describe('byteplus tutorial notes and columns', () => {
501 it('applies resolution notes, and drops rows whose note it cannot read', () => {
502 const geometry = parseSeedanceGeometry(GUIDE)
503 // "2.0 Fast and Mini do not support 1080p"; "Only 2.0 supports 4K".
504 const fast = geometry.get('dreamina-seedance-2-0-fast-260128')?.dims
505 expect(Object.keys(fast ?? {})).toEqual(['720p'])
506 expect(
507 geometry.get('dreamina-seedance-2-0-260128')?.dims['4k']?.['1:1'],
508 ).toEqual({ w: 2880, h: 2880 })
509 // "Contact sales for 8K" names no rule: nobody gets 8K.
510 for (const model of geometry.values()) {
511 expect(model.dims).not.toHaveProperty('8k')
512 }
513 })
514
515 it("prefers a model's own column, and drops a model whose sizes conflict", () => {
516 const geometry = parseSeedanceGeometry(
517 doc(
518 [
519 ['Model name', '', 'Seedance 1.0 Pro', 'Seedance 1.0 Pro Fast'],
520 [
521 'Model ID',
522 '',
523 'seedance-1-0-pro-250528',
524 'seedance-1-0-pro-fast-251015',
525 ],
526 ['', 'Frame rate', '24 fps', '24 fps'],
527 ],
528 [
529 [
530 'Resolution',
531 'Aspect ratio',
532 'Seedance 1.0 series',
533 'Seedance 1.0 Pro Fast',
534 'Seedance 1.0 Pro',
535 ],
536 ['720p', '16:9', '1248×704', '1280×720', '1248×704'],
537 ['', '4:3', '1120×832', '1120×832', '1112×834'],
538 ],
539 ),
540 )
541 expect(
542 geometry.get('seedance-1-0-pro-fast-251015')?.dims['720p']?.['16:9'],
543 ).toEqual({ w: 1280, h: 720 })
544 // Pro's own column agrees at 16:9 but the series disagrees at 4:3 —
545 // own beats series, so Pro keeps its own 1112×834.
546 expect(
547 geometry.get('seedance-1-0-pro-250528')?.dims['720p']?.['4:3'],
548 ).toEqual({ w: 1112, h: 834 })
549 const twice = parseSeedanceGeometry(
550 doc(
551 [
552 ['Model name', '', 'Seedance 1.0 Pro'],
553 ['Model ID', '', 'seedance-1-0-pro-250528'],
554 ['', 'Frame rate', '24 fps'],
555 ],
556 [
557 [
558 'Resolution',
559 'Aspect ratio',
560 'Seedance 1.0 Pro',
561 'Seedance 1.0 Pro',
562 ],
563 ['720p', '16:9', '1248×704', '1280×720'],
564 ],
565 ),
566 )
567 expect(twice.has('seedance-1-0-pro-250528')).toBe(false)
568 })
569
570 it('refuses to estimate a draft', () => {
571 const model = parseSeedanceGeometry(GUIDE).get('seedance-1-0-pro-250528')
572 if (!model) throw new Error('no geometry')
573 const card = compileSeedanceCard(
574 { default: { '*': { all: 2.5 } } },
575 SOURCE,
576 { model, url: 'https://example.test/guide', hash: 'b'.repeat(64) },
577 )
578 if (!card) throw new Error('no card')
579 const request = { resolution: '720p', ratio: '16:9', duration: 5 }
580 expect(priceDetailed(card, request).estimated).toEqual([
581 'completion_tokens',
582 ])
583 expect(() => priceDetailed(card, { ...request, draft: true })).toThrow(
584 /cannot be estimated.*draft/,
585 )
586 // Billed tokens price a 1.0 draft: its rate does not split on resolution.
587 expect(
588 priceDetailed(card, { draft: true }, { completion_tokens: 1e6 }),
589 ).toEqual({ amount: 2.5, currency: 'USD', usd: 2.5, estimated: [] })
590 })
591})