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 compilePeriodCard,
10 compileSeedanceCard,
11 compileSeedreamProCard,
12 parseByteplusAliases,
13 parseByteplusImages,
14 parseByteplusModelPage,
15 parseByteplusPixelTiers,
16 parseByteplusPricing,
17 parseByteplusVideo,
18 parseSeedanceGeometry,
19 sharePublishedAliases,
20} from './byteplus-pricing.ts'
21import type { ByteplusDoc } from './byteplus-pricing.ts'
22import liveImages from './fixtures/byteplus-pricing-images.json'
23import { pricingDoc } from './fixtures/byteplus-pricing-doc.ts'
24import type { PricingTable } from './fixtures/byteplus-pricing-doc.ts'
25import { overlayModelFacts } from './reasoning-config.ts'
26import type { ModelInfo } from './types.ts'
27
28function cell(id: string, text: string) {
29 return {
30 ops: [{ insert: '*', attributes: { lmkr: '1' } }, { insert: `${text}\n` }],
31 zoneId: id,
32 zoneType: 'Z',
33 }
34}
35
36/** Chat-table header as the live page words it (read 2026-10-23). */
37const CHAT_HEADERS = [
38 'Provider',
39 'Model ID',
40 'Prompt length (K tokens)',
41 'Input',
42 'Cached input',
43 'Cache storage',
44 'Output',
45]
46
47/** "Audio input" table: no output column (the chat table quotes it). */
48const AUDIO_HEADERS = [
49 'Model ID',
50 'Prompt length (K tokens)',
51 'Input',
52 'Cached input',
53]
54
55/** Page document of `tables`, each a header row then body rows. */
56function doc(...tables: Array<Array<Array<string>>>): ByteplusDoc {
57 const data: ByteplusDoc['data'] = { '0': { ops: [] } }
58 tables.forEach((body, t) => {
59 data['0']?.ops?.push({
60 insert: '*',
61 attributes: { aceTable: `rows${t} cols${t}` },
62 })
63 data[`rows${t}`] = {
64 ops: body.map((_, index) => ({ insert: { id: `t${t}r${index}` } })),
65 zoneType: 'R',
66 }
67 data[`cols${t}`] = {
68 ops: (body[0] ?? []).map((_, index) => ({
69 insert: { id: `t${t}c${index}` },
70 })),
71 zoneType: 'C',
72 }
73 body.forEach((cells, row) => {
74 cells.forEach((text, column) => {
75 const id = `xt${t}r${row}xt${t}c${column}`
76 data[id] = cell(id, text)
77 })
78 })
79 })
80 return { data }
81}
82
83describe('byteplus pricing page', () => {
84 it('reads standard token rates, tiers, and a dated catalog suffix', () => {
85 const rates = parseByteplusPricing(
86 pricingDoc([
87 // Flex is not a lever, even first and with every Standard column.
88 {
89 tab: 'Flex',
90 rows: [
91 CHAT_HEADERS,
92 [
93 'Z.ai',
94 'glm-5-2-260617',
95 'Not applicable',
96 '$0.7',
97 '$0.26',
98 '$0.0083',
99 '$2.2',
100 ],
101 ],
102 },
103 {
104 tab: 'Flex',
105 rows: [
106 AUDIO_HEADERS,
107 ['seed-2-0-lite-260428', '[0, 128]', '$1.88', '$0.75'],
108 ['', '(128, 256]', '$3.75', '$1.50'],
109 ],
110 },
111 {
112 tab: 'Standard',
113 rows: [
114 CHAT_HEADERS,
115 [
116 'ByteDance',
117 'dola-seed-2-1-turbo',
118 '[0, 256]',
119 '$0.5',
120 '$0.1',
121 '$0.0083',
122 '$2.5',
123 ],
124 [
125 '',
126 'seed-2-0-pro-260328',
127 '[0, 128]',
128 '$0.50',
129 '$0.10',
130 '$0.0083',
131 '$3.00',
132 ],
133 ['', '', '(128, 256]', '$1.00', '$0.20', '$0.0083', '$6.00'],
134 [
135 '',
136 'seed-2-0-lite-260428',
137 '[0, 128]',
138 '$0.25',
139 '$0.05',
140 '$0.0083',
141 '$2.00',
142 ],
143 ['', '', '(128, 256]', '$0.50', '$0.10', '$0.0083', '$4.00'],
144 [
145 'DeepSeek',
146 'deepseek-v4-1-flash-260910',
147 'Off-peak hours',
148 '$0.15',
149 '$0.003',
150 '$0.0083',
151 '$0.60',
152 ],
153 ['', '', 'Peak hours', '$0.30', '$0.006', '$0.0083', '$1.20'],
154 [
155 'Z.ai',
156 'glm-5-2-260617',
157 'Not applicable',
158 '$1.4',
159 '$0.26',
160 '$0.0083',
161 '$4.4',
162 ],
163 ],
164 },
165 {
166 tab: 'Standard',
167 rows: [
168 AUDIO_HEADERS,
169 ['seed-2-0-lite-260428', '[0, 128]', '$3.75', '$0.75'],
170 ['', '(128, 256]', '$7.50', '$1.50'],
171 ],
172 },
173 {
174 tab: 'Standard',
175 folded: true,
176 rows: [
177 ['Model ID', 'Recommended replacement', ...CHAT_HEADERS.slice(2)],
178 [
179 'seed-1-8-251228',
180 'dola-seed-2-0-lite-260428',
181 'Not applicable',
182 '$0.25',
183 '$0.05',
184 '$0.0083',
185 '$2.00',
186 ],
187 ],
188 },
189 ]),
190 )
191 expect(rates.get('glm-5-2-260617')).toEqual({
192 base: {
193 input_tokens: 1.4e-6,
194 cache_read_tokens: 0.26e-6,
195 output_tokens: 4.4e-6,
196 },
197 tiers: [],
198 })
199 // Standard audio joins each chat bracket; the Flex audio table is not read.
200 expect(rates.get('seed-2-0-lite-260428')).toEqual({
201 base: {
202 input_tokens: 0.25e-6,
203 cache_read_tokens: 0.05 / 1e6,
204 output_tokens: 2e-6,
205 audio_tokens: 3.75e-6,
206 audio_cache_tokens: 0.75e-6,
207 },
208 tiers: [
209 {
210 minPromptTokens: 128_000,
211 rates: {
212 input_tokens: 0.5e-6,
213 cache_read_tokens: 0.1 / 1e6,
214 output_tokens: 4e-6,
215 audio_tokens: 7.5e-6,
216 audio_cache_tokens: 1.5e-6,
217 },
218 },
219 ],
220 })
221 // The folded "Retiring models" Standard table is read too.
222 expect(rates.get('seed-1-8-251228')).toMatchObject({
223 base: { input_tokens: 0.25e-6, output_tokens: 2e-6 },
224 })
225 expect(rates.get('seed-2-0-pro-260328')).toMatchObject({
226 tiers: [
227 {
228 minPromptTokens: 128_000,
229 rates: {
230 input_tokens: 1 / 1e6,
231 cache_read_tokens: 0.2 / 1e6,
232 output_tokens: 6 / 1e6,
233 },
234 },
235 ],
236 })
237 // Cache storage is per hour, so it is not a lever.
238 expect(rates.get('glm-5-2-260617')).not.toHaveProperty('base.cache_storage')
239 // Peak and off-peak rows are kept apart, never folded into one price.
240 expect(rates.get('deepseek-v4-1-flash-260910')).toEqual({
241 periods: {
242 off_peak: {
243 input_tokens: 0.15e-6,
244 cache_read_tokens: 0.003e-6,
245 output_tokens: 0.6e-6,
246 },
247 peak: {
248 input_tokens: 0.3e-6,
249 cache_read_tokens: 0.006e-6,
250 output_tokens: 1.2e-6,
251 },
252 },
253 })
254 expect(byteplusRatesFor('dola-seed-2-1-turbo-260628', rates)).toMatchObject(
255 { base: { input_tokens: 0.5e-6 } },
256 )
257 expect(byteplusRatesFor('seed-translation-250915', rates)).toBeUndefined()
258 // Only a dated suffix reaches an undated row, never a sibling model.
259 expect(
260 byteplusRatesFor('dola-seed-2-1-turbo-flash-260628', rates),
261 ).toBeUndefined()
262 })
263
264 it('refuses a period group that is not one off-peak and one peak row', () => {
265 const offPeak = [
266 'DeepSeek',
267 'deepseek-v4-1-flash-261017',
268 'Off-peak hours',
269 '$0.15',
270 '$0.003',
271 '$0.0083',
272 '$0.60',
273 ]
274 const standard = (...rows: Array<Array<string>>): Array<PricingTable> => [
275 { tab: 'Standard', rows: [CHAT_HEADERS, ...rows] },
276 ]
277 const twoOffPeak = parseByteplusPricing(
278 pricingDoc(standard(offPeak, ['', '', ...offPeak.slice(2)])),
279 )
280 expect(twoOffPeak.has('deepseek-v4-1-flash-261017')).toBe(false)
281 const mixed = parseByteplusPricing(
282 pricingDoc(
283 standard(offPeak, ['', '', '(128, 256]', '$1', '-', '-', '$2']),
284 ),
285 )
286 expect(mixed.has('deepseek-v4-1-flash-261017')).toBe(false)
287 })
288
289 it('refuses audio rates it cannot fold into the chat brackets', () => {
290 const rates = parseByteplusPricing(
291 pricingDoc([
292 {
293 tab: 'Standard',
294 rows: [
295 CHAT_HEADERS,
296 [
297 'ByteDance',
298 'seed-2-0-mini-260428',
299 '[0, 128]',
300 '$0.10',
301 '$0.02',
302 '$0.0083',
303 '$0.40',
304 ],
305 ['', '', '(128, 256]', '$0.20', '$0.04', '$0.0083', '$0.80'],
306 [
307 '',
308 'dola-seed-2-1-turbo',
309 '[0, 256]',
310 '$0.5',
311 '$0.1',
312 '$0.0083',
313 '$2.5',
314 ],
315 ],
316 },
317 {
318 tab: 'Standard',
319 rows: [
320 AUDIO_HEADERS,
321 ['seed-2-0-mini-260428', '[0, 128]', '$1.50', '$0.30'],
322 // An unreadable audio row refuses the card rather than leave
323 // audio input unpriced on a text-only one.
324 ['dola-seed-2-1-turbo', '[0, 256]', 'TBD', '$0.30'],
325 ],
326 },
327 ]),
328 )
329 expect(rates.has('seed-2-0-mini-260428')).toBe(false)
330 expect(rates.has('dola-seed-2-1-turbo')).toBe(false)
331 })
332
333 it('prices a period card only for a stated pricing_period', async () => {
334 const card = compilePeriodCard(
335 {
336 periods: {
337 off_peak: {
338 input_tokens: 0.12e-6,
339 cache_read_tokens: 0.0024e-6,
340 output_tokens: 0.48e-6,
341 },
342 peak: {
343 input_tokens: 0.24e-6,
344 cache_read_tokens: 0.0048e-6,
345 output_tokens: 0.96e-6,
346 },
347 },
348 },
349 SOURCE,
350 )
351 const usage = { input_tokens: 1_000_000, output_tokens: 1_000_000 }
352 expect(price(card, {}, { ...usage, pricing_period: 'off_peak' })).toBe(0.6)
353 expect(
354 price(
355 card,
356 {},
357 { ...usage, cache_read_tokens: 1_000_000, pricing_period: 'peak' },
358 ),
359 ).toBeCloseTo(1.2048, 10)
360 expect(() => price(card, {}, usage)).toThrow(/pricing_period/)
361 expect(() =>
362 price(card, {}, { ...usage, pricing_period: 'night' }),
363 ).toThrow(/pricing_period/)
364 // Usage-bound levers only, so the chat schema accepts the card as stored.
365 const stored = await storeListedPricing(card, {
366 sourceUrl: SOURCE.url,
367 now: 1_790_000_000,
368 requestProperties: new Set(['model', 'messages']),
369 })
370 expect(stored).toEqual({ card })
371 })
372
373 it('keeps each patch’s absent facts when overlaying', () => {
374 const model = { rawId: 'seed-translation-250915', activity: 'chat' }
375 const merged = overlayModelFacts(
376 model as ModelInfo,
377 { absent: { pricing: 'unavailable' } },
378 { absent: { reasoning: 'unavailable' } },
379 )
380 expect(merged.absent).toEqual({
381 pricing: 'unavailable',
382 reasoning: 'unavailable',
383 })
384 })
385
386 it("reads a model page's single price row (seed-translation)", () => {
387 const headers = [
388 'Input USD/M Tokens',
389 'Input Hits Cache USD/M Tokens',
390 'Output Unit Price USD/M Tokens',
391 'Cache Storage USD/M Tokens/Hour',
392 ]
393 expect(
394 parseByteplusModelPage(doc([headers, ['0.20', '-', '0.80', '-']])),
395 ).toEqual({ input_tokens: 0.2 / 1e6, output_tokens: 0.8 / 1e6 })
396 expect(() =>
397 parseByteplusModelPage(
398 doc([headers, ['0.20', '-', '0.80', '-'], ['0.30', '-', '1', '-']]),
399 ),
400 ).toThrow(/one price table row/)
401 expect(() =>
402 parseByteplusModelPage(doc([headers, ['0.20', '-', 'TBD', '-']])),
403 ).toThrow(/unreadable/)
404 expect(() => parseByteplusModelPage(doc([CHAT_HEADERS]))).toThrow()
405 })
406
407 it("reads gpt-oss-120b's model page headers, Standard columns only", () => {
408 const headers = [
409 'Input unit price USD/M Tokens',
410 'Input cache hits USD/M Tokens',
411 'Output unit price USD/M Tokens',
412 'Cache Storage USD/M Tokens/Hour',
413 'Input unit price [Batch] USD/M Tokens',
414 'Input cache-hit unit price [Batch] USD/M Tokens',
415 'Output unit price [Batch] USD/M Tokens',
416 ]
417 expect(
418 parseByteplusModelPage(
419 doc([
420 headers,
421 ['0.10', '0.02', '0.50', '0.0083', '0.05', '0.02', '0.25'],
422 ]),
423 ),
424 ).toEqual({
425 input_tokens: 0.1 / 1e6,
426 cache_read_tokens: 0.02 / 1e6,
427 output_tokens: 0.5 / 1e6,
428 })
429 // Both input spellings in one table: refused, not the first one picked.
430 expect(() =>
431 parseByteplusModelPage(
432 doc([
433 ['Input USD/M Tokens', ...headers],
434 ['0.20', '0.10', '0.02', '0.50', '0.0083', '0.05', '0.02', '0.25'],
435 ]),
436 ),
437 ).toThrow(/one price table row/)
438 })
439})
440
441const SOURCE = {
442 url: 'https://docs.byteplus.com/en/docs/ModelArk/1544106',
443 hash: 'a'.repeat(64),
444 extractedAt: '2026-10-02T00:00:00Z',
445}
446
447const VIDEO_HEADER = [
448 ['Model', 'Online inference', '', '', 'Offline inference'],
449 ['', '480p and 720p', '1080p', '4K', ''],
450]
451
452/** Video and image tables as the live page words them (read 2026-10-23). */
453const VIDEO_TABLES: Array<PricingTable> = [
454 {
455 tab: 'Input without video',
456 rows: [
457 ...VIDEO_HEADER,
458 [
459 'dreamina-seedance-2-5-260628',
460 '$10.70',
461 '$11.7',
462 'Not supported',
463 'Not supported',
464 ],
465 [
466 'dreamina-seedance-2-0-fast-260128',
467 '$5.6',
468 'Not supported',
469 'Not supported',
470 'Not supported',
471 ],
472 // One price merged over every online resolution column.
473 ['seedance-1-0-pro-250528', '$2.5', '', '', '$1.25'],
474 ['seedance-9-unknown-261231', 'Contact sales', '$1', '$1', '$1'],
475 // A blank cell that is not part of a merge is unread, not free.
476 ['seedance-9-gap-261231', '$1', '', '$1', 'Not supported'],
477
478 ['dreamina-seedance-2-0-260128', '$7.0', '$7.7', '$4.0', 'Not supported'],
479 [
480 'seedance-9-noted-261231',
481 '$2',
482 'Not supported',
483 'Not supported',
484 'Not supported',
485 ],
486 [
487 'seedance-9-no-video-input-261231',
488 '$2',
489 'Not supported',
490 'Not supported',
491 'Not supported',
492 ],
493 // Two prices for one slot: neither is the price.
494 [
495 'seedance-9-twice-261231',
496 '$2',
497 'Not supported',
498 'Not supported',
499 'Not supported',
500 ],
501 [
502 'seedance-9-twice-261231',
503 '$3',
504 'Not supported',
505 'Not supported',
506 'Not supported',
507 ],
508 ],
509 merges: [
510 [[0], [1, 2, 3]],
511 [[4], [1, 2, 3]],
512 ],
513 },
514 {
515 tab: 'Input with video',
516 rows: [
517 ...VIDEO_HEADER,
518 [
519 'dreamina-seedance-2-5-260628',
520 '$6.40',
521 '$7.0',
522 'Not supported',
523 'Not supported',
524 ],
525 [
526 'dreamina-seedance-2-0-fast-260128',
527 '$3.3',
528 'Not supported',
529 'Not supported',
530 'Not supported',
531 ],
532 // No price without video input: no rate the card could fall back to.
533 [
534 'seedance-9-video-only-261231',
535 '$1',
536 'Not supported',
537 'Not supported',
538 'Not supported',
539 ],
540
541 ['dreamina-seedance-2-0-260128', '$4.3', '$4.7', '$2.4', 'Not supported'],
542 // The id cell may carry a note after the id.
543 [
544 'seedance-9-noted-261231 (New)',
545 '$1',
546 'Not supported',
547 'Not supported',
548 'Not supported',
549 ],
550 // Listed with video but priced nowhere: video input is not one rate.
551 [
552 'seedance-9-no-video-input-261231',
553 'Not supported',
554 'Not supported',
555 'Not supported',
556 'Not supported',
557 ],
558 ],
559 merges: [[[0], [1, 2, 3]]],
560 },
561 {
562 folded: true,
563 rows: [
564 ['Model', 'Online inference', '', 'Offline inference', ''],
565 [
566 '',
567 'Video with audio',
568 'Video without audio',
569 'Video with audio',
570 'Video without audio',
571 ],
572 ['seedance-1-5-pro-251215', '$2.4', '$1.2', '$1.2', '$0.6'],
573 ],
574 merges: [
575 [[0], [1, 2]],
576 [[0], [3, 4]],
577 ],
578 },
579]
580
581const IMAGE_TABLE: PricingTable = {
582 rows: [
583 ['Model ID', 'Input image', 'Output image'],
584 [
585 'dola-seedream-5-0-pro-260628',
586 'First image: Free From the second image: $0.003 Pricing varies by image generation scenario.',
587 'Single-image generation: P ≤ 2.61 million (1.5K or lower): $0.045 P > 2.61 million (higher than 1.5K): $0.09 Layer decomposition: P ≤ 2.61 million (1.5K or lower): $0.0225 P > 2.61 million (higher than 1.5K): $0.045',
588 ],
589 ['seedream-5-0-lite-260128', 'Free', '$0.035'],
590 ['dola-seedream-5-0-flash-260915', 'Free', '$0.018'],
591 ['seedream-4-5-251128', 'Free', '$0.04'],
592 ['seedream-4-0-250828', 'Free', '$0.03'],
593 ],
594}
595
596describe('byteplus video and image tables', () => {
597 const page = pricingDoc([...VIDEO_TABLES, IMAGE_TABLE])
598 const video = parseByteplusVideo(page)
599
600 it('reads list prices per tier, resolution, and variant', () => {
601 expect(video.get('dreamina-seedance-2-0-fast-260128')).toEqual({
602 default: {
603 '480p': { no_video: 5.6, video: 3.3 },
604 '720p': { no_video: 5.6, video: 3.3 },
605 },
606 })
607 // One merged online price, and listed without video input only: one
608 // rate whatever the resolution.
609 expect(video.get('seedance-1-0-pro-250528')).toEqual({
610 default: { '*': { all: 2.5 } },
611 flex: { '*': { all: 1.25 } },
612 })
613 expect(video.get('seedance-1-5-pro-251215')).toEqual({
614 default: { '*': { audio: 2.4, silent: 1.2 } },
615 flex: { '*': { audio: 1.2, silent: 0.6 } },
616 })
617 expect(video.has('seedance-9-unknown-261231')).toBe(false)
618 expect(video.has('seedance-9-gap-261231')).toBe(false)
619 expect(video.has('seedance-9-video-only-261231')).toBe(false)
620 expect(video.get('dreamina-seedance-2-0-260128')?.default?.['4k']).toEqual({
621 no_video: 4,
622 video: 2.4,
623 })
624 expect(video.get('seedance-9-noted-261231')).toEqual({
625 default: {
626 '480p': { no_video: 2, video: 1 },
627 '720p': { no_video: 2, video: 1 },
628 },
629 })
630 expect(video.has('seedance-9-no-video-input-261231')).toBe(false)
631 expect(video.has('seedance-9-twice-261231')).toBe(false)
632 expect(parseByteplusImages(page)).toEqual(
633 new Map([
634 ['seedream-5-0-lite-260128', 0.035],
635 ['dola-seedream-5-0-flash-260915', 0.018],
636 ['seedream-4-5-251128', 0.04],
637 ['seedream-4-0-250828', 0.03],
638 ]),
639 )
640 })
641
642 it('copies a flat image price onto the model list alias, not onto chat', () => {
643 const images = parseByteplusImages(page)
644 const listed = doc([
645 [
646 'seedream-5-0-260128 (also supports: seedream-5-0-lite-260128)',
647 'seedream-5-0-260128 (also supports: seedream-9-other-260128)',
648 ],
649 ])
650 // Two different aliases for one id: not one price.
651 expect(parseByteplusAliases(listed).size).toBe(0)
652 const once = doc([
653 ['seedream-5-0-260128\n(also supports: seedream-5-0-lite-260128)'],
654 ])
655 const aliases = parseByteplusAliases(once)
656 sharePublishedAliases(images, aliases)
657 expect(images.get('seedream-5-0-260128')).toBe(0.035)
658 expect(images.get('seedream-5-0-lite-260128')).toBe(0.035)
659 // No speech table on this page, and no price for an unlisted snapshot.
660 expect(images.has('seed-asr')).toBe(false)
661 expect(images.has('seed-audio-1.0')).toBe(false)
662 expect(images.has('seedream-4-0-20260415')).toBe(false)
663 })
664
665 it('reads the model list note on its own "Also supports" line (#468)', () => {
666 // The live cell as of 2026-10-23: two list lines, no parentheses.
667 const listed = doc([
668 ['seedream-5-0-260128\n*Also supports seedream-5-0-lite-260128'],
669 ['seedream-4-5-251128', 'Also supports seedream-9-other-260128'],
670 ['seedream-4-0-250828 Also supports seedream-9-other-260128Pro'],
671 ])
672 // The second row's note sits in the next cell, and a cut-off alias
673 // is not an id: neither is a pair.
674 expect(parseByteplusAliases(listed)).toEqual(
675 new Map([['seedream-5-0-260128', 'seedream-5-0-lite-260128']]),
676 )
677 const images = parseByteplusImages(page)
678 sharePublishedAliases(images, parseByteplusAliases(listed))
679 expect(images.get('seedream-5-0-260128')).toBe(0.035)
680 })
681
682 it('prices billed completion_tokens and refuses what it cannot know', () => {
683 const usd = (
684 id: string,
685 request: Record<string, unknown>,
686 usage?: Record<string, unknown>,
687 ) => {
688 const rates = video.get(id)
689 const card = rates && compileSeedanceCard(rates, SOURCE)
690 if (!card) throw new Error(`no card for ${id}`)
691 return Number(price(card, request, usage).toFixed(4))
692 }
693 const v25 = 'dreamina-seedance-2-5-260628'
694 expect(
695 usd(
696 v25,
697 { resolution: '1080p' },
698 { completion_tokens: 1e6, input_video: true },
699 ),
700 ).toBe(7)
701 // Seedance 1.0 Pro usage table: 489600 tokens → 1.22.
702 expect(
703 usd('seedance-1-0-pro-250528', {}, { completion_tokens: 489_600 }),
704 ).toBe(1.224)
705 expect(
706 usd(
707 'seedance-1-5-pro-251215',
708 { generate_audio: true, service_tier: 'flex' },
709 { completion_tokens: 1e6 },
710 ),
711 ).toBe(1.2)
712 const billed = { completion_tokens: 1e6, input_video: false }
713 // No billed count, no stated video input, no audio choice: refuse.
714 expect(() => usd(v25, { resolution: '720p' }, {})).toThrow(
715 /completion_tokens/,
716 )
717 expect(() =>
718 usd(v25, { resolution: '720p' }, { completion_tokens: 1e6 }),
719 ).toThrow(/input_video.*required/)
720 expect(() =>
721 usd('seedance-1-5-pro-251215', {}, { completion_tokens: 1 }),
722 ).toThrow(/generate_audio.*required/)
723 // Draft bills at another resolution; flex has no offline column.
724 expect(() =>
725 usd(v25, { resolution: '1080p', draft: true }, billed),
726 ).toThrow(/draft/)
727 expect(() =>
728 usd(v25, { resolution: '720p', service_tier: 'flex' }, billed),
729 ).toThrow(/flex/)
730 })
731
732 it('prices Seedream 5.0 pro by size tier and extra input images', () => {
733 const tiers = parseByteplusPixelTiers(page).get(
734 'dola-seedream-5-0-pro-260628',
735 )
736 const card = tiers && compileSeedreamProCard(tiers, SOURCE)
737 if (!card) throw new Error('no Seedream 5.0 pro card')
738 const usd = (request: Record<string, unknown>, inputImages = 0) =>
739 Number(
740 price(card, request, {
741 generated_images: 1,
742 input_images: inputImages,
743 }).toFixed(4),
744 )
745 // Omitted size is Ark's default 2K, the high tier.
746 expect(usd({})).toBe(0.09)
747 expect(usd({ size: '1K' })).toBe(0.045)
748 expect(usd({ size: '1.5K' })).toBe(0.045)
749 // WxH by pixel count: 1536² = 2.36 MP ≤ 2.61 MP; 2048² is above.
750 expect(usd({ size: '1536x1536' })).toBe(0.045)
751 expect(usd({ size: '2048x2048' })).toBe(0.09)
752 // First input image free, each further one 0.003 (usage.input_images).
753 expect(usd({ size: '1K' }, 1)).toBe(0.045)
754 expect(usd({ size: '1K' }, 3)).toBe(0.051)
755 // Layers mix tiers; 4K/auto are not generation sizes; usage is required.
756 expect(() => usd({ layer_decomposition: true })).toThrow(/layer/)
757 expect(() => usd({ size: '4K' })).toThrow(/unknown size/)
758 expect(() => usd({ size: 'auto' })).toThrow(/unknown size/)
759 expect(() => price(card, {}, { input_images: 0 })).toThrow(
760 /generated_images/,
761 )
762 expect(() => price(card, {}, { generated_images: 1 })).toThrow(
763 /input_images/,
764 )
765 })
766})
767
768describe('byteplus image table as published 2026-11-13 (#640)', () => {
769 // The image table cut verbatim from the live doc: the "Output image"
770 // header now carries a note line, and Seedream 5.0 pro's tiers read
771 // "P ≤ 2.61 million".
772 const page: ByteplusDoc = liveImages
773
774 it('reads the flat rows under the annotated header', () => {
775 expect(parseByteplusImages(page)).toEqual(
776 new Map([
777 ['dola-seedream-5-0-flash-260915', 0.018],
778 ['seedream-5-0-lite-260128', 0.035],
779 ['seedream-4-5-251128', 0.04],
780 ['seedream-4-0-250828', 0.03],
781 ['seededit-3-0-i2i-250628', 0.03],
782 ]),
783 )
784 })
785
786 it('reads Seedream 5.0 pro tiers and leaves Seedream 5.5 unpriced', () => {
787 expect(parseByteplusPixelTiers(page)).toEqual(
788 new Map([
789 [
790 'dola-seedream-5-0-pro-260628',
791 {
792 extraInput: 0.003,
793 maxLowPixels: 2.61e6,
794 lowLevel: '1.5K',
795 low: 0.045,
796 high: 0.09,
797 },
798 ],
799 ]),
800 )
801 })
802
803 it('still parses nothing from a table with no output column', () => {
804 const none = pricingDoc([
805 {
806 rows: [
807 ['Model ID', 'Input image'],
808 ['seedream-4-0-250828', 'Free'],
809 ],
810 },
811 ])
812 expect(parseByteplusImages(none).size).toBe(0)
813 expect(parseByteplusPixelTiers(none).size).toBe(0)
814 })
815})
816
817/** The tutorial's model and pixel tables as the live page words them. */
818const GUIDE = doc(
819 [
820 [
821 'Model name',
822 '',
823 'Dreamina Seedance 2.0',
824 'Dreamina Seedance 2.0 Fast',
825 'Seedance 1.0 Pro',
826 ],
827 [
828 'Model ID',
829 '',
830 'dreamina-seedance-2-0-260128',
831 'dreamina-seedance-2-0-fast-260128',
832 'seedance-1-0-pro-250528',
833 ],
834 ['', 'Frame rate', '24 fps', '24 fps', '24 fps'],
835 ],
836 [
837 [
838 'Resolution',
839 'Aspect ratio',
840 'Dreamina Seedance 2.0 series',
841 'Seedance 1.0 series',
842 ],
843 ['720p', '16:9', '1280×720', '1248×704'],
844 ['', '4:3', '1112×834', '1120×832'],
845 [
846 '1080p Dreamina Seedance 2.0 Fast and Dreamina Seedance 2.0 Mini do not support 1080p',
847 '16:9',
848 '1920×1080',
849 '1920×1088',
850 ],
851 ['4k Only Dreamina Seedance 2.0 supports 4K', '16:9', '3840×2160', ''],
852 ['', '4:3', '3326×2494', '-'],
853 ['', '1:1', '2880×2880', '-'],
854 ['8k Contact sales for 8K', '16:9', '7680×4320', '7680×4320'],
855 ],
856)
857
858describe('byteplus video generation tutorial', () => {
859 const geometry = parseSeedanceGeometry(GUIDE)
860
861 it('reads frame rate and sizes per model, series columns included', () => {
862 expect(geometry.get('seedance-1-0-pro-250528')).toEqual({
863 fps: 24,
864 dims: {
865 '720p': {
866 '16:9': { w: 1248, h: 704 },
867 '4:3': { w: 1120, h: 832 },
868 },
869 '1080p': { '16:9': { w: 1920, h: 1088 } },
870 },
871 })
872 expect(
873 geometry.get('dreamina-seedance-2-0-260128')?.dims['4k']?.['4:3'],
874 ).toEqual({ w: 3326, h: 2494 })
875 })
876
877 it('labels the estimate, and keeps sizes to the resolutions priced', () => {
878 const id = 'dreamina-seedance-2-0-fast-260128'
879 const model = geometry.get(id)
880 if (!model) throw new Error('no geometry')
881 const card = compileSeedanceCard(
882 {
883 default: {
884 '480p': { no_video: 5.6, video: 3.3 },
885 '720p': { no_video: 5.6, video: 3.3 },
886 },
887 },
888 SOURCE,
889 { model, url: 'https://example.test/guide', hash: 'b'.repeat(64) },
890 )
891 if (!card) throw new Error('no card')
892 // The series column lists 1080p and 4K; Fast prices neither.
893 expect(Object.keys(card.tables.pixels ?? {})).toEqual(['720p'])
894 // Page: "Dreamina Seedance 2.0 Fast (USD) 0.60 per video" (720p 16:9 5 s).
895 const request = { resolution: '720p', ratio: '16:9', duration: 5 }
896 const result = priceDetailed(card, request, { input_video: false })
897 expect(result.estimated).toEqual(['completion_tokens'])
898 expect(result.amount.toFixed(2)).toBe('0.60')
899 // Video input carries a minimum-token floor the method does not cover
900 // unless the Lark range was supplied.
901 expect(() => priceDetailed(card, request, { input_video: true })).toThrow(
902 /estimate_supported/,
903 )
904 })
905
906 it('bills a short input video at the Lark minimum for that output', async () => {
907 const card = compileSeedanceCard(
908 {
909 default: {
910 '480p': { no_video: 10.7, video: 6.4 },
911 '720p': { no_video: 10.7, video: 6.4 },
912 '1080p': { no_video: 11.7, video: 7 },
913 },
914 },
915 SOURCE,
916 {
917 model: {
918 fps: 24,
919 dims: {
920 '480p': { '16:9': { w: 854, h: 480 } },
921 '720p': { '16:9': { w: 1280, h: 720 } },
922 '1080p': { '16:9': { w: 1920, h: 1080 } },
923 },
924 },
925 url: 'https://example.test/guide',
926 hash: 'b'.repeat(64),
927 videoMinimumsThrough: 30,
928 },
929 )
930 if (!card) throw new Error('no card')
931 const video = (duration: number, input = 0, resolution = '720p') =>
932 priceDetailed(
933 card,
934 { resolution, ratio: '16:9', duration, input_video_duration: input },
935 { input_video: true },
936 )
937 // Page: 720p 16:9, 5s out, 2–4s in → $1.244. 480p → $0.553.
938 expect(video(5, 2).amount.toFixed(3)).toBe('1.244')
939 expect(video(5, 2, '480p').amount.toFixed(3)).toBe('0.553')
940 // 30s out floors a 2s input at 20s in: 480,375 tokens × $6.40.
941 expect(video(30, 2, '480p').amount).toBeCloseTo((480_375 * 6.4) / 1e6, 6)
942 // Past the minimum, the real input length wins.
943 expect(video(30, 30, '480p').amount).toBeCloseTo((576_450 * 6.4) / 1e6, 6)
944 expect(() => video(31, 2)).toThrow(/min_input_seconds/)
945 // The generation schema has duration and ratio, not input seconds.
946 // That lever must still store; refusing it used to null the card.
947 const stored = await storeListedPricing(card, {
948 sourceUrl: 'https://docs.byteplus.com/en/docs/ModelArk/1544106',
949 now: 1_790_000_000,
950 requestProperties: new Set([
951 'service_tier',
952 'draft',
953 'resolution',
954 'duration',
955 'ratio',
956 ]),
957 })
958 expect(stored.refused).toBeUndefined()
959 expect(stored.card?.inputs.completion_tokens).toMatchObject({
960 kind: 'number',
961 })
962 })
963})
964
965describe('byteplus tutorial notes and columns', () => {
966 it('applies resolution notes, and drops rows whose note it cannot read', () => {
967 const geometry = parseSeedanceGeometry(GUIDE)
968 // "2.0 Fast and Mini do not support 1080p"; "Only 2.0 supports 4K".
969 const fast = geometry.get('dreamina-seedance-2-0-fast-260128')?.dims
970 expect(Object.keys(fast ?? {})).toEqual(['720p'])
971 expect(
972 geometry.get('dreamina-seedance-2-0-260128')?.dims['4k']?.['1:1'],
973 ).toEqual({ w: 2880, h: 2880 })
974 // "Contact sales for 8K" names no rule: nobody gets 8K.
975 for (const model of geometry.values()) {
976 expect(model.dims).not.toHaveProperty('8k')
977 }
978 })
979
980 it("prefers a model's own column, and drops a model whose sizes conflict", () => {
981 const geometry = parseSeedanceGeometry(
982 doc(
983 [
984 ['Model name', '', 'Seedance 1.0 Pro', 'Seedance 1.0 Pro Fast'],
985 [
986 'Model ID',
987 '',
988 'seedance-1-0-pro-250528',
989 'seedance-1-0-pro-fast-251015',
990 ],
991 ['', 'Frame rate', '24 fps', '24 fps'],
992 ],
993 [
994 [
995 'Resolution',
996 'Aspect ratio',
997 'Seedance 1.0 series',
998 'Seedance 1.0 Pro Fast',
999 'Seedance 1.0 Pro',
1000 ],
1001 ['720p', '16:9', '1248×704', '1280×720', '1248×704'],
1002 ['', '4:3', '1120×832', '1120×832', '1112×834'],
1003 ],
1004 ),
1005 )
1006 expect(
1007 geometry.get('seedance-1-0-pro-fast-251015')?.dims['720p']?.['16:9'],
1008 ).toEqual({ w: 1280, h: 720 })
1009 // Pro's own column agrees at 16:9 but the series disagrees at 4:3 —
1010 // own beats series, so Pro keeps its own 1112×834.
1011 expect(
1012 geometry.get('seedance-1-0-pro-250528')?.dims['720p']?.['4:3'],
1013 ).toEqual({ w: 1112, h: 834 })
1014 const twice = parseSeedanceGeometry(
1015 doc(
1016 [
1017 ['Model name', '', 'Seedance 1.0 Pro'],
1018 ['Model ID', '', 'seedance-1-0-pro-250528'],
1019 ['', 'Frame rate', '24 fps'],
1020 ],
1021 [
1022 [
1023 'Resolution',
1024 'Aspect ratio',
1025 'Seedance 1.0 Pro',
1026 'Seedance 1.0 Pro',
1027 ],
1028 ['720p', '16:9', '1248×704', '1280×720'],
1029 ],
1030 ),
1031 )
1032 expect(twice.has('seedance-1-0-pro-250528')).toBe(false)
1033 })
1034
1035 it('refuses to estimate a draft', () => {
1036 const model = parseSeedanceGeometry(GUIDE).get('seedance-1-0-pro-250528')
1037 if (!model) throw new Error('no geometry')
1038 const card = compileSeedanceCard(
1039 { default: { '*': { all: 2.5 } } },
1040 SOURCE,
1041 { model, url: 'https://example.test/guide', hash: 'b'.repeat(64) },
1042 )
1043 if (!card) throw new Error('no card')
1044 const request = { resolution: '720p', ratio: '16:9', duration: 5 }
1045 expect(priceDetailed(card, request).estimated).toEqual([
1046 'completion_tokens',
1047 ])
1048 expect(() => priceDetailed(card, { ...request, draft: true })).toThrow(
1049 /cannot be estimated.*draft/,
1050 )
1051 // Billed tokens price a 1.0 draft: its rate does not split on resolution.
1052 expect(
1053 priceDetailed(card, { draft: true }, { completion_tokens: 1e6 }),
1054 ).toEqual({
1055 amount: 2.5,
1056 currency: 'USD',
1057 usd: 2.5,
1058 estimated: [],
1059 defaulted: ['service_tier'],
1060 ignored: [],
1061 })
1062 })
1063})