Open History to see the last commit
1import { afterEach, describe, expect, it } from 'vitest'
2
3import {
4 MINIMAX_CN_MAX_COMPLETION_TOKENS,
5 MINIMAX_CN_PRICING_OVERVIEW_PAGE,
6 MINIMAX_CN_PRICING_PAGE,
7 MINIMAX_CN_SDK_PAGE,
8 MINIMAX_MAX_COMPLETION_TOKENS,
9 MINIMAX_PRICING_OVERVIEW_PAGE,
10 MINIMAX_PRICING_PAGE,
11 MINIMAX_SDK_PAGE,
12 MINIMAX_CN_PRICING_LLM_MDX,
13 MINIMAX_PRICING_LLM_MDX,
14 minimaxPricingHtml,
15} from './fixtures/minimax-docs.ts'
16import {
17 fetchMinimaxPage,
18 MINIMAX,
19 MINIMAX_CN,
20 minimaxModelFacts,
21 parseMinimaxContextWindows,
22 parseMinimaxInputModalities,
23 parseMinimaxMaxOutput,
24 parseMinimaxPricing,
25 parseMinimaxReasoning,
26} from './minimax-docs.ts'
27
28const IDS = [
29 'MiniMax-M3.1-Flash-Preview',
30 'MiniMax-M3',
31 'MiniMax-M2.7',
32 'MiniMax-M2.7-highspeed',
33 'MiniMax-M2.5',
34 'MiniMax-M2.5-highspeed',
35 'MiniMax-M2.1',
36 'MiniMax-M2.1-highspeed',
37 'MiniMax-M2',
38]
39
40describe('minimax docs', () => {
41 it('reads every context window from the Supported Models table', () => {
42 const windows = parseMinimaxContextWindows(MINIMAX_SDK_PAGE)
43 expect([...windows.keys()]).toEqual(IDS)
44 expect(windows.get('MiniMax-M3.1-Flash-Preview')).toBe(1_000_000)
45 expect(windows.get('MiniMax-M2')).toBe(204_800)
46 })
47
48 it('gives image and video input only to the models the table names', () => {
49 const inputs = parseMinimaxInputModalities(MINIMAX_SDK_PAGE, IDS)
50 expect(inputs.get('MiniMax-M3.1-Flash-Preview')).toEqual([
51 'text',
52 'image',
53 'video',
54 ])
55 expect(inputs.get('MiniMax-M3')).toEqual(['text', 'image', 'video'])
56 expect(inputs.get('MiniMax-M2.7-highspeed')).toEqual(['text'])
57 expect(inputs.size).toBe(IDS.length)
58 })
59
60 it('reads thinking from the control table and efforts for M3.1 only', () => {
61 const reasoning = parseMinimaxReasoning(MINIMAX_SDK_PAGE, IDS)
62 expect(reasoning.get('MiniMax-M3.1-Flash-Preview')).toEqual({
63 mode: 'adaptive',
64 mandatory: true,
65 efforts: ['low', 'medium', 'high', 'xhigh', 'max'],
66 })
67 expect(reasoning.get('MiniMax-M3')).toEqual({
68 mode: 'adaptive',
69 mandatory: false,
70 })
71 for (const id of IDS.slice(2)) {
72 expect(reasoning.get(id)).toEqual({ mode: 'adaptive', mandatory: true })
73 }
74 })
75
76 it('reads the legacy rows the page indents inside an accordion', () => {
77 // The live page (Oct 2026) moved the M2.x rows into an indented
78 // `<Accordion title="Legacy Models">` under the M3 table. The other
79 // tables take their ids from this one, as `minimaxModelFacts` does.
80 const lines = MINIMAX_SDK_PAGE.split('\n')
81 const first = lines.findIndex((line) => line.startsWith('| MiniMax-M2.7 '))
82 const last = lines.findIndex((line) => line.startsWith('| MiniMax-M2 '))
83 expect(first).toBeGreaterThan(0)
84 expect(last).toBeGreaterThan(first)
85 const page = [
86 ...lines.slice(0, first),
87 '',
88 '<Accordion title="Legacy Models">',
89 ' | Model Name | Context Window | Description |',
90 ' | :- | :- | :- |',
91 ...lines.slice(first, last + 1).map((line) => ` ${line}`),
92 '</Accordion>',
93 ...lines.slice(last + 1),
94 ].join('\n')
95 const windows = parseMinimaxContextWindows(page)
96 const ids = [...windows.keys()]
97 expect(ids).toEqual(IDS)
98 expect(windows.get('MiniMax-M2')).toBe(204_800)
99 expect(parseMinimaxInputModalities(page, ids).get('MiniMax-M2')).toEqual([
100 'text',
101 ])
102 expect(parseMinimaxReasoning(page, ids).get('MiniMax-M2')).toEqual({
103 mode: 'adaptive',
104 mandatory: true,
105 })
106 })
107
108 it('reads the output cap for the named models and for the rest', () => {
109 const caps = parseMinimaxMaxOutput(MINIMAX_MAX_COMPLETION_TOKENS, IDS)
110 expect(caps.get('MiniMax-M3.1-Flash-Preview')).toBe(524_288)
111 expect(caps.get('MiniMax-M3')).toBe(524_288)
112 expect(caps.get('MiniMax-M2.7')).toBe(204_800)
113 expect(caps.size).toBe(IDS.length)
114 })
115
116 it('leaves the output cap empty when the sentence changes shape', () => {
117 expect(
118 parseMinimaxMaxOutput('Upper limit for generated tokens.', IDS).size,
119 ).toBe(0)
120 })
121
122 it('stores no output cap when the clause naming a model is reworded', () => {
123 // Only the M3 clause changes; `other models` still parses and must not
124 // be handed to the models the sentence names.
125 const reworded = MINIMAX_MAX_COMPLETION_TOKENS.replace(
126 'the maximum is 524288',
127 'the upper bound is 524288',
128 )
129 expect(reworded).not.toBe(MINIMAX_MAX_COMPLETION_TOKENS)
130 expect(parseMinimaxMaxOutput(reworded, IDS).size).toBe(0)
131 })
132
133 it('never gives a named model the other-models cap, whatever the clause order', () => {
134 const swapped =
135 'For other models the recommended value is 65536 (64K) and the maximum is 204800 (200K); for MiniMax-M3.1-Flash-Preview and MiniMax-M3 the recommended value is 131072 (128K) and the maximum is 524288 (512K).'
136 const caps = parseMinimaxMaxOutput(swapped, IDS)
137 expect(caps.get('MiniMax-M3')).toBe(524_288)
138 expect(caps.get('MiniMax-M3.1-Flash-Preview')).toBe(524_288)
139 expect(caps.get('MiniMax-M2')).toBe(204_800)
140
141 const othersOnly =
142 'For other models the maximum is 204800 (200K); MiniMax-M3 has a higher limit.'
143 expect(parseMinimaxMaxOutput(othersOnly, IDS).size).toBe(0)
144 expect(
145 parseMinimaxMaxOutput('For other models the maximum is 204800.', IDS)
146 .size,
147 ).toBe(0)
148 })
149
150 it('refuses a struck price whose badge is not permanent', () => {
151 const promo = MINIMAX_PRICING_PAGE.replaceAll(
152 'Permanent 50% off',
153 '50% off until Dec 31',
154 )
155 expect(promo).not.toBe(MINIMAX_PRICING_PAGE)
156 const prices = parseMinimaxPricing(promo)
157 expect(prices.has('MiniMax-M3')).toBe(false)
158 expect(prices.size).toBe(7)
159
160 // One row losing its badge refuses the whole model, not just that tier.
161 const half = MINIMAX_PRICING_PAGE.replace(
162 'Permanent 50% off',
163 'Limited offer',
164 )
165 expect(parseMinimaxPricing(half).has('MiniMax-M3')).toBe(false)
166 })
167
168 it('prices the standard tier at the billed amount, with the long-context tier', () => {
169 const prices = parseMinimaxPricing(MINIMAX_PRICING_PAGE)
170 // The Priority tab ($0.45) and the struck list price ($0.60) are not used.
171 expect(prices.get('MiniMax-M3')).toEqual({
172 base: {
173 input_tokens: 0.3 / 1e6,
174 output_tokens: 1.2 / 1e6,
175 cache_read_tokens: 0.06 / 1e6,
176 },
177 tiers: [
178 {
179 minPromptTokens: 512_000,
180 rates: {
181 input_tokens: 0.6 / 1e6,
182 output_tokens: 2.4 / 1e6,
183 cache_read_tokens: 0.12 / 1e6,
184 },
185 },
186 ],
187 })
188 expect(prices.get('MiniMax-M2.7-highspeed')).toEqual({
189 base: {
190 input_tokens: 0.6 / 1e6,
191 output_tokens: 2.4 / 1e6,
192 cache_read_tokens: 0.06 / 1e6,
193 cache_write_tokens: 0.375 / 1e6,
194 },
195 tiers: [],
196 })
197 expect(prices.get('MiniMax-M2')?.base.cache_read_tokens).toBe(0.03 / 1e6)
198 // No pay-as-you-go price is published for the M Plan preview model.
199 expect(prices.has('MiniMax-M3.1-Flash-Preview')).toBe(false)
200 expect(prices.size).toBe(8)
201 })
202})
203
204describe('minimax-cn pricing', () => {
205 const cn = (page: string) => parseMinimaxPricing(page, MINIMAX_CN)
206
207 it('prices the 标准 tier in yuan at the billed amount, with the long-context tier', () => {
208 const prices = cn(MINIMAX_CN_PRICING_PAGE)
209 // The 优先 tab (3.15) and the struck list price (4.20) are not used.
210 expect(prices.get('MiniMax-M3')).toEqual({
211 base: {
212 input_tokens: 2.1 / 1e6,
213 output_tokens: 8.4 / 1e6,
214 cache_read_tokens: 0.42 / 1e6,
215 },
216 tiers: [
217 {
218 minPromptTokens: 512_000,
219 rates: {
220 input_tokens: 4.2 / 1e6,
221 output_tokens: 16.8 / 1e6,
222 cache_read_tokens: 0.84 / 1e6,
223 },
224 },
225 ],
226 })
227 expect(prices.get('MiniMax-M2.7-highspeed')).toEqual({
228 base: {
229 input_tokens: 4.2 / 1e6,
230 output_tokens: 16.8 / 1e6,
231 cache_read_tokens: 0.42 / 1e6,
232 cache_write_tokens: 2.625 / 1e6,
233 },
234 tiers: [],
235 })
236 expect(prices.get('MiniMax-M2')?.base.cache_read_tokens).toBe(0.21 / 1e6)
237 // No pay-as-you-go price is published for the M Plan preview model.
238 expect(prices.has('MiniMax-M3.1-Flash-Preview')).toBe(false)
239 expect(prices.size).toBe(8)
240 })
241
242 it('reads nothing across platforms', () => {
243 expect(parseMinimaxPricing(MINIMAX_CN_PRICING_PAGE).size).toBe(0)
244 expect(cn(MINIMAX_PRICING_PAGE).size).toBe(0)
245 })
246
247 it('refuses a struck price whose badge is not permanent', () => {
248 const promo = MINIMAX_CN_PRICING_PAGE.replaceAll('永久五折', '限时五折')
249 expect(promo).not.toBe(MINIMAX_CN_PRICING_PAGE)
250 expect(cn(promo).has('MiniMax-M3')).toBe(false)
251 expect(cn(promo).size).toBe(7)
252 // One row losing its badge refuses the whole model, not just that tier.
253 const half = MINIMAX_CN_PRICING_PAGE.replace('永久五折', '限时五折')
254 expect(cn(half).has('MiniMax-M3')).toBe(false)
255 })
256
257 it.each([
258 [
259 'a unit in the cell',
260 '| 2.1 | 8.4 | 0.42 | 2.625 |',
261 '| 2.1 元 | 8.4 | 0.42 | 2.625 |',
262 ],
263 [
264 'a 万 suffix',
265 '| 2.1 | 8.4 | 0.42 | 2.625 |',
266 '| 2.1万 | 8.4 | 0.42 | 2.625 |',
267 ],
268 [
269 'a range',
270 '| 2.1 | 8.4 | 0.42 | 2.625 |',
271 '| 2.1 | 8.4-16.8 | 0.42 | 2.625 |',
272 ],
273 ['a reworded unit', '元/百万 tokens', '元/千 tokens'],
274 ['a renamed section', '## 语言模型', '## 文本模型'],
275 ])('stores no price for %s', (_name, from, to) => {
276 const page = MINIMAX_CN_PRICING_PAGE.replaceAll(from, to)
277 expect(page).not.toBe(MINIMAX_CN_PRICING_PAGE)
278 expect(cn(page).has('MiniMax-M2.7')).toBe(false)
279 })
280})
281
282describe.each([
283 {
284 platform: MINIMAX,
285 page: MINIMAX_PRICING_PAGE,
286 overview: MINIMAX_PRICING_OVERVIEW_PAGE,
287 next: '## Audio',
288 table: [
289 '| **Model** | **Input**<br />$ / M tokens | **Output**<br />$ / M tokens |',
290 '| :- | :- | :- |',
291 '| **MiniMax-M4** | $0.1 | $0.5 |',
292 ],
293 },
294 {
295 platform: MINIMAX_CN,
296 page: MINIMAX_CN_PRICING_PAGE,
297 overview: MINIMAX_CN_PRICING_OVERVIEW_PAGE,
298 next: '## 语音',
299 table: [
300 '| **模型** | **输入价格**<br /> 元/百万 tokens | **输出价格**<br /> 元/百万 tokens |',
301 '| :- | :-: | :-: |',
302 '| **MiniMax-M4** | 0.7 | 3.5 |',
303 ],
304 },
305])(
306 '$platform.label pricing overview page',
307 ({ platform, page, overview, next, table }) => {
308 it('reads the LLM section nested in an indented <section>', () => {
309 const prices = parseMinimaxPricing(overview, platform)
310 expect(prices.size).toBe(8)
311 expect(prices).toEqual(parseMinimaxPricing(page, platform))
312 })
313
314 it('still refuses a sub-heading inside the nested section', () => {
315 const headed = overview.replace(
316 ' <Accordion title=',
317 ' ### Batch\n\n <Accordion title=',
318 )
319 expect(headed).not.toBe(overview)
320 expect(parseMinimaxPricing(headed, platform).size).toBe(0)
321 })
322
323 it('refuses an HTML sub-heading inside the nested section', () => {
324 const headed = overview.replace(
325 ' <Accordion title=',
326 ' <h3 id="batch">Batch</h3>\n\n <Accordion title=',
327 )
328 expect(headed).not.toBe(overview)
329 expect(parseMinimaxPricing(headed, platform).size).toBe(0)
330 })
331
332 it('stops at the closing </section> when the next heading is HTML', () => {
333 const html = overview.replace(next, '<h2>Audio</h2>')
334 expect(html).not.toBe(overview)
335 const tail = [
336 '<section id="models/text-batch">',
337 ...table,
338 '</section>',
339 ].join('\n')
340 const prices = parseMinimaxPricing(`${html}\n${tail}`, platform)
341 expect(prices.has('MiniMax-M4')).toBe(false)
342 expect(prices).toEqual(parseMinimaxPricing(page, platform))
343 })
344 },
345)
346
347/**
348 * Page shapes that once stored a wrong number with no throw. Each must
349 * leave the model unpriced (or the page empty) on both platforms.
350 */
351describe.each([
352 {
353 name: 'minimax',
354 platform: MINIMAX,
355 page: MINIMAX_PRICING_PAGE,
356 tier: '> 512k input tokens',
357 tierRewordings: [
358 'over 512k input tokens',
359 '512k+ input tokens',
360 '> 512k input tokens',
361 '> 51.2万 input tokens',
362 ],
363 priority: '<Tab title="Priority*">',
364 row: '| **MiniMax-M2.7** | $0.3 | $1.2 | $0.06 | $0.375 |',
365 batchRow: '| **MiniMax-M2.7** | $0.15 | $0.6 | $0.03 | $0.1875 |',
366 header:
367 '| **Model** | **Input**<br />$ / M tokens | **Output**<br />$ / M tokens | **Prompt caching Read**<br />$ / M tokens | **Prompt caching Write**<br />$ / M tokens |',
368 cacheHeader: '**Prompt caching Read**<br />$ / M tokens',
369 cacheCell: ['$0.06 | $0.375', 'free | $0.375'],
370 base: { input_tokens: 0.3 / 1e6, output_tokens: 1.2 / 1e6 },
371 },
372 {
373 name: 'minimax-cn',
374 platform: MINIMAX_CN,
375 page: MINIMAX_CN_PRICING_PAGE,
376 tier: '> 512k 输入 tokens',
377 tierRewordings: [
378 '超过 512k 输入 tokens',
379 '512k 以上',
380 '> 512k 输入 tokens',
381 '> 51.2万 输入 tokens',
382 ],
383 priority: '<Tab title="优先*">',
384 row: '| **MiniMax-M2.7** | 2.1 | 8.4 | 0.42 | 2.625 |',
385 batchRow: '| **MiniMax-M2.7** | 1.05 | 4.2 | 0.21 | 1.3125 |',
386 header:
387 '| **模型** | **输入价格**<br /> 元/百万 tokens | **输出价格**<br /> 元/百万 tokens | **缓存读取**<br /> 元/百万 tokens | **缓存写入**<br /> 元/百万 tokens |',
388 cacheHeader: '**缓存读取**<br /> 元/百万 tokens',
389 cacheCell: ['| 2.1 | 8.4 | 0.42 |', '| 2.1 | 8.4 | 免费 |'],
390 base: { input_tokens: 2.1 / 1e6, output_tokens: 8.4 / 1e6 },
391 },
392])('$name pricing refuses what it cannot attribute', (c) => {
393 const parse = (page: string) => parseMinimaxPricing(page, c.platform)
394 /** A price table for a model the published page does not list. */
395 const unlistedTable = [
396 c.header,
397 '| :- | :- | :- | :- | :- |',
398 c.batchRow.replace('MiniMax-M2.7', 'MiniMax-B1'),
399 ]
400 const edit = (from: string, to: string, all = true) => {
401 const page = all ? c.page.replaceAll(from, to) : c.page.replace(from, to)
402 expect(page).not.toBe(c.page)
403 return parse(page)
404 }
405
406 it('reads the page as published', () => {
407 const prices = parse(c.page)
408 expect(prices.size).toBe(8)
409 expect(prices.get('MiniMax-M3')?.tiers).toHaveLength(1)
410 expect(prices.get('MiniMax-M2.7')?.base).toMatchObject(c.base)
411 })
412
413 it.each(c.tierRewordings)(
414 'a tier bound reworded to %j is never the base price',
415 (reworded) => {
416 const prices = edit(c.tier, reworded)
417 expect(prices.has('MiniMax-M3')).toBe(false)
418 expect(prices.size).toBe(7)
419 },
420 )
421
422 it.each([
423 ['an extra attribute', (tag: string) => tag.replace('>', ' icon="bolt">')],
424 ['single quotes', (tag: string) => tag.replaceAll('"', "'")],
425 ])('prices nothing when the priority tab tag has %s', (_name, mutate) => {
426 expect(edit(c.priority, mutate(c.priority)).size).toBe(0)
427 })
428
429 it('refuses the model when tabs become labels and both tiers show', () => {
430 const untabbed = (label: string) =>
431 c.page.replace(/<Tab title="[^"]*">/g, label).replaceAll('</Tab>', '')
432 const prices = parse(untabbed('tier'))
433 expect(prices.has('MiniMax-M3')).toBe(false)
434 expect(prices.size).toBe(7)
435 expect(parse(untabbed('**tier**')).size).toBe(0)
436 })
437
438 it('prices nothing under a sub-heading it cannot attribute', () => {
439 expect(edit(c.header, `### Batch\n\n${c.header}`, false).size).toBe(0)
440 })
441
442 it.each([
443 ['a nested </section>', '<section>', '</section>'],
444 ['an indented ## heading', ' ## Notes', ''],
445 ])(
446 'prices nothing when %s cuts a foreign accordion open',
447 (_name, before, after) => {
448 const legacy = `<Accordion title="${c.platform.legacyAccordion}">`
449 const batch = [c.header, '| :- | :- | :- | :- | :- |', c.batchRow]
450 const foreign = [
451 '<Accordion title="Batch">',
452 before,
453 ...batch,
454 after,
455 '</Accordion>',
456 '',
457 legacy,
458 ].join('\n')
459 expect(edit(legacy, foreign, false).size).toBe(0)
460 },
461 )
462
463 it('refuses a model a second table prices again', () => {
464 const batch = [c.header, '| :- | :- | :- | :- | :- |', c.batchRow].join(
465 '\n',
466 )
467 const prices = edit(c.row, `${c.row}\n\n${batch}`, false)
468 expect(prices.has('MiniMax-M2.7')).toBe(false)
469 expect(prices.size).toBe(7)
470 })
471
472 it.each(['**Batch API**', ' **Batch API**:'])(
473 'prices nothing under a bold sub-heading %j',
474 (bold) => {
475 const batch = [bold, '', ...unlistedTable].join('\n')
476 expect(edit(c.row, `${c.row}\n\n${batch}`, false).size).toBe(0)
477 },
478 )
479
480 it('prices nothing when a standard tab nests in the priority tab', () => {
481 const nested = [
482 c.priority,
483 `<Tab title="${c.platform.standardTab}">`,
484 'Same as standard.',
485 '</Tab>',
486 ].join('\n')
487 expect(edit(c.priority, nested, false).size).toBe(0)
488 })
489
490 it.each(['Note', 'Info', 'Callout'])(
491 'prices nothing when a <%s> holds a price row',
492 (tag) => {
493 const batch = [`<${tag}>`, ...unlistedTable, `</${tag}>`].join('\n')
494 expect(edit(c.row, `${c.row}\n\n${batch}`, false).size).toBe(0)
495 expect(edit(c.row, `${c.row}\n\n<${tag}>`, false).size).toBe(0)
496 },
497 )
498
499 it('refuses a model whose tier threshold repeats', () => {
500 const tierRow = c.page.split('\n').find((line) => line.includes(c.tier))
501 if (!tierRow) throw new Error('no tier row')
502 const prices = edit(tierRow, `${tierRow}\n${tierRow}`, false)
503 expect(prices.has('MiniMax-M3')).toBe(false)
504 })
505
506 it('refuses a row with a qualifier beside the id', () => {
507 const prices = edit(
508 '**MiniMax-M2.7** |',
509 '**MiniMax-M2.7** (batch) |',
510 false,
511 )
512 expect(prices.has('MiniMax-M2.7')).toBe(false)
513 })
514
515 it('refuses a row whose cache cell does not read, rather than drop the lever', () => {
516 const prices = edit(c.cacheCell[0] ?? '', c.cacheCell[1] ?? '', false)
517 expect(prices.has('MiniMax-M2.7')).toBe(false)
518 expect(prices.size).toBe(7)
519 })
520
521 describe('accordions', () => {
522 const legacy = `<Accordion title="${c.platform.legacyAccordion}">`
523 const published = JSON.stringify([...parse(c.page)])
524 const same = (page: string) => {
525 expect(page).not.toBe(c.page)
526 expect(JSON.stringify([...parse(page)])).toBe(published)
527 }
528
529 it('ignores a text-only accordion, whatever its title or attributes', () => {
530 const faq =
531 '<Accordion title="FAQ" icon="circle-question">\n Prices exclude tax.\n\n | Tier | Note |\n | :- | :- |\n | Standard | default |\n</Accordion>\n\n'
532 same(c.page.replace(legacy, faq + legacy))
533 same(c.page.replace('<Tabs>', `${faq}<Tabs>`))
534 })
535
536 it('still reads the legacy accordion when it gains an attribute', () => {
537 same(c.page.replace(legacy, legacy.replace('>', ' defaultOpen>')))
538 same(
539 c.page.replace(
540 legacy,
541 legacy.replace('<Accordion ', '<Accordion icon="clock" '),
542 ),
543 )
544 })
545
546 it('prices nothing when an accordion nests in the legacy accordion', () => {
547 const nested = [
548 legacy,
549 '<Accordion title="Batch">',
550 ...unlistedTable,
551 '</Accordion>',
552 ].join('\n')
553 expect(edit(legacy, nested).size).toBe(0)
554 })
555
556 it('prices nothing when an </Accordion> has no opening', () => {
557 expect(edit(c.row, `${c.row}\n</Accordion>`, false).size).toBe(0)
558 })
559
560 it('prices nothing when the legacy accordion is retitled', () => {
561 expect(edit(legacy, '<Accordion title="Batch">').size).toBe(0)
562 })
563
564 it('prices nothing when an unknown accordion holds a price table', () => {
565 const batch = [
566 '<Accordion title="Batch">',
567 ...unlistedTable,
568 '</Accordion>',
569 '',
570 legacy,
571 ].join('\n')
572 expect(edit(legacy, batch).size).toBe(0)
573 })
574 })
575
576 it('refuses a base bound that does not meet the tier', () => {
577 const prices = edit('≤ 512k', '≤ 256k')
578 expect(prices.has('MiniMax-M3')).toBe(false)
579 expect(prices.size).toBe(7)
580 // A bounded base with no tier above it, and a tier over an open base.
581 const tierRow = c.page.split('\n').find((line) => line.includes(c.tier))
582 if (!tierRow) throw new Error('no tier row')
583 expect(edit(`${tierRow}\n`, '', false).has('MiniMax-M3')).toBe(false)
584 expect(edit(c.tier.replace('>', '≤'), '').has('MiniMax-M3')).toBe(false)
585 })
586
587 it('prices nothing under a header it does not know', () => {
588 expect(edit(c.cacheHeader, `${c.cacheHeader} (peak)`).size).toBe(0)
589 })
590})
591
592describe('minimax-cn docs', () => {
593 it('reads every context window from the 支持的模型 table', () => {
594 const windows = parseMinimaxContextWindows(MINIMAX_CN_SDK_PAGE, MINIMAX_CN)
595 expect([...windows.keys()]).toEqual(IDS)
596 expect(windows.get('MiniMax-M3.1-Flash-Preview')).toBe(1_000_000)
597 expect(windows.get('MiniMax-M2')).toBe(204_800)
598 // The English wording reads nothing off the Chinese page, and back.
599 expect(parseMinimaxContextWindows(MINIMAX_CN_SDK_PAGE).size).toBe(0)
600 expect(parseMinimaxContextWindows(MINIMAX_SDK_PAGE, MINIMAX_CN).size).toBe(
601 0,
602 )
603 })
604
605 it('gives image and video input only to the models the table names', () => {
606 const inputs = parseMinimaxInputModalities(
607 MINIMAX_CN_SDK_PAGE,
608 IDS,
609 MINIMAX_CN,
610 )
611 expect(inputs.get('MiniMax-M3.1-Flash-Preview')).toEqual([
612 'text',
613 'image',
614 'video',
615 ])
616 expect(inputs.get('MiniMax-M3')).toEqual(['text', 'image', 'video'])
617 for (const id of IDS.slice(2)) expect(inputs.get(id)).toEqual(['text'])
618 })
619
620 it('stores no modalities when a support status is reworded', () => {
621 // `M3 不支持` names M3 as the one model without video: it must not
622 // read as the one model with it, nor leave every model text-only.
623 for (const status of ['M3 不支持', '部分支持', 'M3.1-Flash-Preview / M3']) {
624 const reworded = MINIMAX_CN_SDK_PAGE.replace(
625 '| `type="video"` | 仅 M3.1-Flash-Preview / M3 |',
626 `| \`type="video"\` | ${status} |`,
627 )
628 expect(reworded).not.toBe(MINIMAX_CN_SDK_PAGE)
629 expect(parseMinimaxInputModalities(reworded, IDS, MINIMAX_CN).size).toBe(
630 0,
631 )
632 }
633 })
634
635 it('reads thinking from the control table and efforts for M3.1 only', () => {
636 const reasoning = parseMinimaxReasoning(
637 MINIMAX_CN_SDK_PAGE,
638 IDS,
639 MINIMAX_CN,
640 )
641 expect(reasoning.get('MiniMax-M3.1-Flash-Preview')).toEqual({
642 mode: 'adaptive',
643 mandatory: true,
644 efforts: ['low', 'medium', 'high', 'xhigh', 'max'],
645 })
646 expect(reasoning.get('MiniMax-M3')).toEqual({
647 mode: 'adaptive',
648 mandatory: false,
649 })
650 for (const id of IDS.slice(2)) {
651 expect(reasoning.get(id)).toEqual({ mode: 'adaptive', mandatory: true })
652 }
653 })
654
655 it('stores no reasoning for a row whose disabled cell is reworded', () => {
656 const reworded = MINIMAX_CN_SDK_PAGE.replace(
657 '保持 thinking 关闭',
658 '可能保持 thinking 关闭',
659 ).replace('thinking 仍保持开启', 'thinking 行为不变')
660 const reasoning = parseMinimaxReasoning(reworded, IDS, MINIMAX_CN)
661 expect([...reasoning.keys()]).toEqual(['MiniMax-M3.1-Flash-Preview'])
662 })
663
664 it('reads the output cap for the named models and for the rest', () => {
665 const caps = parseMinimaxMaxOutput(
666 MINIMAX_CN_MAX_COMPLETION_TOKENS,
667 IDS,
668 MINIMAX_CN,
669 )
670 // 131072 and 65536 are the recommended values, not the caps.
671 expect(caps.get('MiniMax-M3.1-Flash-Preview')).toBe(524_288)
672 expect(caps.get('MiniMax-M3')).toBe(524_288)
673 for (const id of IDS.slice(2)) expect(caps.get(id)).toBe(204_800)
674 })
675
676 it('stores no output cap when the clause naming a model is reworded', () => {
677 const reworded = MINIMAX_CN_MAX_COMPLETION_TOKENS.replace(
678 '上限为 524288',
679 '最多 524288',
680 )
681 expect(reworded).not.toBe(MINIMAX_CN_MAX_COMPLETION_TOKENS)
682 expect(parseMinimaxMaxOutput(reworded, IDS, MINIMAX_CN).size).toBe(0)
683 expect(
684 parseMinimaxMaxOutput('其他模型上限为 204800。', IDS, MINIMAX_CN).size,
685 ).toBe(0)
686 })
687})
688
689// Each rewording below once stored a wrong value. All must store nothing.
690describe('minimax docs rewordings that must not store a value', () => {
691 const EN_M3 =
692 'for MiniMax-M3.1-Flash-Preview and MiniMax-M3 the recommended value is 131072 (128K) and the maximum is 524288 (512K)'
693 const EN_REST =
694 'for other models the recommended value is 65536 (64K) and the maximum is 204800 (200K)'
695 const CN_M3 =
696 'MiniMax-M3.1-Flash-Preview 和 MiniMax-M3 推荐值为 131072(128K),上限为 524288(512K)'
697 const CN_REST = '其他模型推荐值为 65536(64K),上限为 204800(200K)'
698
699 it('keeps the fixtures in step with the clauses these tests rebuild', () => {
700 expect(MINIMAX_MAX_COMPLETION_TOKENS.toLowerCase()).toContain(
701 `${EN_M3}; ${EN_REST}.`.toLowerCase(),
702 )
703 expect(MINIMAX_CN_MAX_COMPLETION_TOKENS).toContain(`${CN_M3};${CN_REST}。`)
704 })
705
706 it('refuses a catch-all clause run together with the clause naming ids', () => {
707 for (const text of [
708 `${EN_REST}, ${EN_M3}.`,
709 `${EN_REST} and ${EN_M3}.`,
710 `${EN_M3}, ${EN_REST}.`,
711 ]) {
712 expect(parseMinimaxMaxOutput(text, IDS).size).toBe(0)
713 }
714 for (const text of [
715 `${CN_REST},${CN_M3}。`,
716 `${CN_REST};${CN_M3}。`,
717 `${CN_M3},${CN_REST}。`,
718 ]) {
719 expect(parseMinimaxMaxOutput(text, IDS, MINIMAX_CN).size).toBe(0)
720 }
721 // Reordered with the separator kept, both still parse.
722 expect(
723 parseMinimaxMaxOutput(`${EN_REST}; ${EN_M3}.`, IDS).get('MiniMax-M3'),
724 ).toBe(524_288)
725 expect(
726 parseMinimaxMaxOutput(`${CN_REST};${CN_M3}。`, IDS, MINIMAX_CN).get(
727 'MiniMax-M3',
728 ),
729 ).toBe(524_288)
730 })
731
732 it('refuses a clause with two maximums', () => {
733 expect(
734 parseMinimaxMaxOutput(
735 'For MiniMax-M3 the maximum is 524288 and for MiniMax-M3.1-Flash-Preview the maximum is 262144; for other models the maximum is 204800.',
736 IDS,
737 ).size,
738 ).toBe(0)
739 expect(
740 parseMinimaxMaxOutput(
741 'MiniMax-M3 上限为 524288,MiniMax-M3.1-Flash-Preview 上限为 262144;其他模型上限为 204800。',
742 IDS,
743 MINIMAX_CN,
744 ).size,
745 ).toBe(0)
746 })
747
748 it('refuses a maximum written with a unit or a decimal', () => {
749 for (const [m3, rest] of [
750 ['512K', '200K'],
751 ['512k', '200k'],
752 ['512 K', '200 K'],
753 ['0.5M', '0.2M'],
754 ['1M', '200K'],
755 ]) {
756 expect(
757 parseMinimaxMaxOutput(
758 `For MiniMax-M3.1-Flash-Preview and MiniMax-M3 the maximum is ${m3}; for other models the maximum is ${rest}.`,
759 IDS,
760 ).size,
761 ).toBe(0)
762 expect(
763 parseMinimaxMaxOutput(
764 `MiniMax-M3.1-Flash-Preview 和 MiniMax-M3 推荐值为 128K,上限为 ${m3};其他模型推荐值为 64K,上限为 ${rest}。`,
765 IDS,
766 MINIMAX_CN,
767 ).size,
768 ).toBe(0)
769 }
770 expect(
771 parseMinimaxMaxOutput(
772 'MiniMax-M3.1-Flash-Preview 和 MiniMax-M3 上限为 52 万;其他模型上限为 20 万。',
773 IDS,
774 MINIMAX_CN,
775 ).size,
776 ).toBe(0)
777 // One clause with a unit refuses the rest too.
778 expect(
779 parseMinimaxMaxOutput(`${CN_M3};其他模型上限为 200K。`, IDS, MINIMAX_CN)
780 .size,
781 ).toBe(0)
782 })
783
784 it('does not read a cap on the recommended value as the output cap', () => {
785 expect(
786 parseMinimaxMaxOutput(
787 'MiniMax-M3.1-Flash-Preview 和 MiniMax-M3 推荐值上限为 131072,最高 524288;其他模型推荐值上限为 65536,最高 204800。',
788 IDS,
789 MINIMAX_CN,
790 ).size,
791 ).toBe(0)
792 })
793
794 it('refuses an input status that names models but is not an only-list', () => {
795 const en = (status: string) => {
796 const page = MINIMAX_SDK_PAGE.replace(
797 '| `type="image"` | M3.1-Flash-Preview / M3 only |',
798 `| \`type="image"\` | ${status} |`,
799 )
800 expect(page).not.toBe(MINIMAX_SDK_PAGE)
801 return parseMinimaxInputModalities(page, IDS)
802 }
803 for (const status of [
804 'Not supported on M2.x',
805 'M2.7 not supported',
806 'All models except M2.7',
807 'M3.1-Flash-Preview / M3',
808 'M2.x only',
809 'M9 only',
810 'Partial support',
811 ]) {
812 expect(en(status).size).toBe(0)
813 }
814 expect(en('M3 only').get('MiniMax-M3.1-Flash-Preview')).toEqual([
815 'text',
816 'video',
817 ])
818
819 const cn = (status: string) => {
820 const page = MINIMAX_CN_SDK_PAGE.replace(
821 '| `type="image"` | 仅 M3.1-Flash-Preview / M3 |',
822 `| \`type="image"\` | ${status} |`,
823 )
824 expect(page).not.toBe(MINIMAX_CN_SDK_PAGE)
825 return parseMinimaxInputModalities(page, IDS, MINIMAX_CN)
826 }
827 for (const status of [
828 '仅 M2.x 不支持',
829 '仅 M2.7 不支持',
830 '仅 M2.x',
831 '仅 M9',
832 '只支持 M3.1-Flash-Preview / M3',
833 'M3.1-Flash-Preview / M3 专属',
834 ]) {
835 expect(cn(status).size).toBe(0)
836 }
837 expect(cn('仅 M3').get('MiniMax-M3.1-Flash-Preview')).toEqual([
838 'text',
839 'video',
840 ])
841 })
842
843 it('stores no reasoning for a disabled cell that only mentions the phrase', () => {
844 const en = MINIMAX_SDK_PAGE.replace(
845 '| Thinking stays off |',
846 '| Can be turned off (unlike M2.x, where thinking cannot be disabled) |',
847 ).replace(
848 '| Accepted but ignored; thinking remains on |',
849 '| Thinking can be switched off |',
850 )
851 expect([...parseMinimaxReasoning(en, IDS).keys()]).toEqual([
852 'MiniMax-M3.1-Flash-Preview',
853 ])
854 const cn = MINIMAX_CN_SDK_PAGE.replace(
855 '| 保持 thinking 关闭 |',
856 '| 可关闭(不同于 M2.x 的 thinking 无法关闭) |',
857 ).replace(
858 '| 被接收但不生效,thinking 仍保持开启 |',
859 '| 可以关闭 thinking |',
860 )
861 expect([...parseMinimaxReasoning(cn, IDS, MINIMAX_CN).keys()]).toEqual([
862 'MiniMax-M3.1-Flash-Preview',
863 ])
864 })
865})
866
867describe('fetchMinimaxPage', () => {
868 const originalFetch = globalThis.fetch
869 afterEach(() => {
870 globalThis.fetch = originalFetch
871 })
872
873 function answerFrom(finalUrl: string): void {
874 globalThis.fetch = () => {
875 const response = new Response('{}')
876 Object.defineProperty(response, 'url', { value: finalUrl })
877 return Promise.resolve(response)
878 }
879 }
880
881 it('follows the China redirect and refuses any other host', async () => {
882 const url = MINIMAX_CN.chatSpecUrl
883 answerFrom(url.replace('platform.minimaxi.com', 'platform.minimax.cn'))
884 await expect(fetchMinimaxPage(url, MINIMAX_CN)).resolves.toBe('{}')
885 answerFrom(url)
886 await expect(fetchMinimaxPage(url, MINIMAX_CN)).resolves.toBe('{}')
887
888 // The international platform publishes the same path.
889 answerFrom(MINIMAX.chatSpecUrl)
890 await expect(fetchMinimaxPage(url, MINIMAX_CN)).rejects.toThrow(
891 'minimax-cn: https://platform.minimaxi.com/docs/api-reference/text/api/openapi-chat-openai.json was answered by platform.minimax.io',
892 )
893 answerFrom('https://platform.minimax.cn.example.com/docs/x.json')
894 await expect(fetchMinimaxPage(url, MINIMAX_CN)).rejects.toThrow(
895 'was answered by platform.minimax.cn.example.com',
896 )
897 answerFrom(url)
898 await expect(
899 fetchMinimaxPage(MINIMAX.chatSpecUrl, MINIMAX),
900 ).rejects.toThrow('minimax: ')
901 })
902})
903
904describe('a maximum equal to the context window is not an output cap', () => {
905 const originalFetch = globalThis.fetch
906 afterEach(() => {
907 globalThis.fetch = originalFetch
908 })
909
910 const PLATFORMS = [
911 {
912 platform: MINIMAX,
913 sdk: MINIMAX_SDK_PAGE,
914 pricing: MINIMAX_PRICING_LLM_MDX,
915 description: MINIMAX_MAX_COMPLETION_TOKENS,
916 },
917 {
918 platform: MINIMAX_CN,
919 sdk: MINIMAX_CN_SDK_PAGE,
920 pricing: MINIMAX_CN_PRICING_LLM_MDX,
921 description: MINIMAX_CN_MAX_COMPLETION_TOKENS,
922 },
923 ]
924
925 for (const { platform, sdk, pricing, description } of PLATFORMS) {
926 const facts = (text: string) => {
927 const pages: Record<string, string> = {
928 [platform.sdkUrl]: sdk,
929 [platform.pricingUrl]: minimaxPricingHtml(pricing),
930 [platform.chatSpecUrl]: JSON.stringify({
931 max_completion_tokens: { description: text },
932 }),
933 }
934 globalThis.fetch = ((url: string) =>
935 Promise.resolve(new Response(pages[String(url)]))) as typeof fetch
936 return minimaxModelFacts(undefined, platform)
937 }
938
939 it(`${platform.label}: stores no cap for the M2 rows, 524288 for M3`, async () => {
940 const of = await facts(description)
941 for (const id of IDS.slice(0, 2)) {
942 expect(of(id).contextWindow).toBe(1_000_000)
943 expect(of(id).maxOutput).toBe(524_288)
944 expect(of(id).factSources?.maxOutput?.sourceUrl).toBe(
945 platform.chatSpecUrl,
946 )
947 }
948 expect(IDS.slice(2)).toHaveLength(7)
949 for (const id of IDS.slice(2)) {
950 expect(of(id).contextWindow).toBe(204_800)
951 expect(of(id).maxOutput).toBeNull()
952 expect(of(id).factSources?.maxOutput).toBeUndefined()
953 }
954 })
955
956 it(`${platform.label}: stores an M2 cap that differs from the window`, async () => {
957 const of = await facts(description.replace('204800', '131072'))
958 for (const id of IDS.slice(2)) {
959 expect(of(id).maxOutput).toBe(131_072)
960 expect(of(id).factSources?.maxOutput?.sourceUrl).toBe(
961 platform.chatSpecUrl,
962 )
963 }
964 expect(of('MiniMax-M3').maxOutput).toBe(524_288)
965 })
966 }
967})