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

mistral-pricing.test.ts

1,040 lines34.9 KB

1import { price } from '@modelschemas/rate-card'
2import type { RateCard } from '@modelschemas/rate-card'
3import { describe, expect, it } from 'vitest'
4​
5import {
6 MISTRAL_WEBSEARCH_GUIDE,
7 mistralModelPage,
8 tip,
9} from './fixtures/mistral-model-page.ts'
10import {
11 copyMistralAliasFacts,
12 indexMistralApiIds,
13 indexMistralModalities,
14 mistralConversationTools,
15 mistralIndexSlugFor,
16 mistralModelPricing,
17 mistralRateCard,
18 parseMistralApiIds,
19 parseMistralApiSlugs,
20 parseMistralMarkdownPrice,
21 parseMistralModelIndex,
22 parseMistralPageMaxOutput,
23 parseMistralPageFeatures,
24 parseMistralPageModalities,
25 parseMistralPagePrice,
26 parseMistralPricing,
27 parseMistralSamePrice,
28 parseMistralWebSearchTools,
29 withDocumentInput,
30} from './mistral-pricing.ts'
31​
32const PAGE = `<h2>Flagship models</h2>
33<p>Prices /M Tokens</p>
34<table>
35<tr><td><a href="/models/mistral-large-3-25-12">Mistral Large 3</a></td><td>$0.5</td><td>$0.05</td><td>$1.5</td></tr>
36<tr><td><a href="/models/codestral-embed-25-05">Codestral Embed</a></td><td>$0.15</td><td>$0.015</td><td>—</td></tr>
37</table>
38<h2>Specialized models</h2>
39<p>Prices as marked</p>
40<table>
41<tr><td><a href="/models/ocr-4-1">OCR 4.1</a></td><td>$4 /1000 Pages</td><td>$0.4 /1000 Pages</td><td>—</td></tr>
42<tr><td><a href="/models/voxtral-mini-transcribe-26-02">Voxtral</a></td><td>$0.003 /Min</td><td>—</td><td>—</td></tr>
43<tr><td><a href="/models/voxtral-tts-26-03">TTS</a></td><td>$0 /M Chars</td><td>$0 /M Chars</td><td>$16 /M Chars</td></tr>
44<tr><td><a href="/models/mixed-units">Mixed</a></td><td>$1 /Min</td><td>—</td><td>$2 /M Chars</td></tr>
45<tr><td><a href="/models/leanstral-1-5">Leanstral</a></td><td>Free</td><td>Free</td><td>Free</td></tr>
46</table>
47<h2>Code models</h2>
48<p>Prices /M Tokens</p>
49<table>
50<tr><td><a href="/models/codestral-25-08">Codestral</a></td><td>$0.3</td><td>$0.03</td><td>$0.9</td></tr>
51</table>`
52​
53describe('mistral pricing page', () => {
54 it('reads per-million tables and unit rows, and skips free or mixed units', () => {
55 const rates = parseMistralPricing(PAGE)
56 expect(rates.get('mistral-large-3-25-12')).toEqual({
57 kind: 'tokens',
58 rates: {
59 input_tokens: 0.5 / 1e6,
60 cache_read_tokens: 0.05 / 1e6,
61 output_tokens: 1.5 / 1e6,
62 },
63 })
64 const codestral = rates.get('codestral-25-08')
65 expect(codestral?.kind === 'tokens' && codestral.rates.output_tokens).toBe(
66 0.9 / 1e6,
67 )
68 expect(rates.get('codestral-embed-25-05')).toEqual({
69 kind: 'tokens',
70 rates: {
71 input_tokens: 0.15 / 1e6,
72 cache_read_tokens: 0.015 / 1e6,
73 },
74 })
75 expect(rates.get('ocr-4-1')).toEqual({
76 kind: 'unit',
77 meters: [
78 { param: 'pages', rate: 4 / 1000 },
79 { param: 'cached_pages', rate: 0.4 / 1000, default: 0 },
80 ],
81 })
82 expect(rates.get('voxtral-mini-transcribe-26-02')).toEqual({
83 kind: 'unit',
84 meters: [{ param: 'audio_minutes', rate: 0.003 }],
85 })
86 expect(rates.get('voxtral-tts-26-03')).toEqual({
87 kind: 'unit',
88 meters: [{ param: 'output_characters', rate: 16 / 1e6 }],
89 })
90 expect(rates.has('mixed-units')).toBe(false)
91 expect(rates.has('leanstral-1-5')).toBe(false)
92 expect(rates.has('mistral-embed')).toBe(false)
93 })
94​
95 it('uses the current sale amount, including an unreadable historical quote', () => {
96 const sale = `<h2>Flagship</h2><p>Prices /M Tokens</p><table>
97<tr><td><a href="/models/synthetic-sale">Sale</a></td>
98<td><del><span>Original price: </span>$9</del><ins><span>Sale price: </span>$3</ins></td>
99<td><del>unknown historical amount</del><ins>$0.2</ins></td>
100<td><del>$12</del><ins>$4</ins></td></tr></table>`
101 expect(parseMistralPricing(sale).get('synthetic-sale')).toEqual({
102 kind: 'tokens',
103 rates: {
104 input_tokens: 3 / 1e6,
105 cache_read_tokens: 0.2 / 1e6,
106 output_tokens: 4 / 1e6,
107 },
108 })
109 })
110​
111 it.each([
112 '<del>$9</del>',
113 '<del>$9</del><ins>unknown</ins>',
114 '<del>$9</del><ins>$3</ins><ins>$2</ins>',
115 ])(
116 'fails unreadable current sale markup instead of using the old rate: %s',
117 (cell) => {
118 const html = `<h2>Flagship</h2><p>Prices /M Tokens</p><table>
119<tr><td><a href="/models/synthetic-sale">Sale</a></td><td>${cell}</td><td>$1</td><td>$4</td></tr></table>`
120 expect(() => parseMistralPricing(html)).toThrow(/current sale price/)
121 },
122 )
123​
124 it('gives bare cells the unit their section header states', () => {
125 const html = `<h2>OCR models</h2>
126<div>Prices /1000 Pages</div>
127<table>
128<tr><td><a href="/models/ocr-4-1">OCR 4.1</a></td><td>$4</td><td>$0.4</td><td>—</td></tr>
129</table>
130<h2>Other models</h2>
131<div>Prices /Furlongs</div>
132<table>
133<tr><td><a href="/models/unknown-unit">Odd</a></td><td>$1</td><td>—</td><td>—</td></tr>
134</table>`
135 const rates = parseMistralPricing(html)
136 expect(rates.get('ocr-4-1')).toEqual(
137 parseMistralPricing(PAGE).get('ocr-4-1'),
138 )
139 expect(rates.has('unknown-unit')).toBe(false)
140 })
141​
142 it('compiles a unit card from the parsed meters', () => {
143 const row = parseMistralPricing(PAGE).get('ocr-4-1')
144 expect(row?.kind).toBe('unit')
145 if (row?.kind !== 'unit') return
146 const card = mistralRateCard(row, {
147 url: 'https://docs.mistral.ai/inference/pricing',
148 hash: 'a'.repeat(64),
149 extractedAt: '2026-10-03T00:00:00.000Z',
150 })
151 expect(card).not.toBeNull()
152 if (!card) return
153 expect(price(card, {}, { pages: 1000 })).toBeCloseTo(4, 9)
154 expect(price(card, {}, { pages: 1000, cached_pages: 1000 })).toBeCloseTo(
155 4.4,
156 9,
157 )
158 const audio = parseMistralPricing(PAGE).get('voxtral-mini-transcribe-26-02')
159 if (audio?.kind !== 'unit') throw new Error('expected an audio unit row')
160 const audioCard = mistralRateCard(audio, {
161 url: 'https://docs.mistral.ai/inference/pricing',
162 hash: 'b'.repeat(64),
163 extractedAt: '2026-10-03T00:00:00.000Z',
164 })
165 if (!audioCard) throw new Error('expected an audio card')
166 expect(price(audioCard, {}, { audio_minutes: 10 })).toBeCloseTo(0.03, 9)
167 })
168​
169 it('refuses a priced slug whose model page named no API ids', () => {
170 const rates = parseMistralPricing(PAGE)
171 expect(() =>
172 indexMistralApiIds(rates, [
173 {
174 slug: 'mistral-large-3-25-12',
175 ids: ['mistral-large-2512'],
176 hash: 'a',
177 },
178 ]),
179 ).toThrow(
180 'mistral model pages: no API ids for codestral-embed-25-05, ocr-4-1, voxtral-mini-transcribe-26-02, voxtral-tts-26-03, codestral-25-08',
181 )
182 })
183​
184 it('copies a changelog same-price chat id and skips unpriced rows', () => {
185 const rates = parseMistralPricing(PAGE)
186 const byId = indexMistralApiIds(rates, [
187 {
188 slug: 'mistral-large-3-25-12',
189 ids: ['mistral-large-2512'],
190 hash: 'a',
191 },
192 { slug: 'codestral-embed-25-05', ids: ['codestral-embed'], hash: 'b' },
193 { slug: 'codestral-25-08', ids: ['zai-glm-5-3'], hash: 'c' },
194 {
195 slug: 'ocr-4-1',
196 ids: ['mistral-ocr-4-1', 'mistral-ocr-latest'],
197 hash: 'd',
198 },
199 {
200 slug: 'voxtral-mini-transcribe-26-02',
201 ids: ['voxtral-mini-2602'],
202 hash: 'e',
203 },
204 { slug: 'voxtral-tts-26-03', ids: ['voxtral-mini-tts-2603'], hash: 'f' },
205 ])
206 const changelog = `
207 Z.ai GLM 5.2 ( zai-glm-5-2 ) is deprecated and retires on October 31, 2026.
208 Use Z.ai GLM 5.3 ( zai-glm-5-3 ) instead, at the same price.
209 OCR 4.0 ( mistral-ocr-4-0 ) is deprecated. Use OCR 4.1 ( mistral-ocr-4-1 ) instead, at the same price.
210 Leanstral 1.5 ( labs-leanstral-1-5 ) is deprecated and retires on September 30, 2026.
211 `
212 for (const [from, to] of parseMistralSamePrice(changelog)) {
213 const row = byId.get(to)
214 if (!row || byId.has(from)) continue
215 byId.set(from, row)
216 }
217 const glm = byId.get('zai-glm-5-2')
218 expect(glm?.kind === 'tokens' && glm.rates.output_tokens).toBe(0.9 / 1e6)
219 expect(byId.get('mistral-ocr-latest')?.kind).toBe('unit')
220 expect(byId.get('voxtral-mini-2602')?.kind).toBe('unit')
221 expect(byId.has('mistral-ocr-4-0')).toBe(false)
222 expect(byId.has('voxtral-mini-realtime-2602')).toBe(false)
223 expect(byId.has('labs-leanstral-1-5')).toBe(false)
224 expect(byId.has('magistral-medium-latest')).toBe(false)
225 })
226​
227 it('reads the API ids a model page lists for the slug', () => {
228 const html =
229 'other "names":["docs","agents"] payload names\\":[\\"mistral-large-2512\\",\\"mistral-large-latest\\"]'
230 expect(parseMistralApiIds(html, 'mistral-large-3-25-12')).toEqual([
231 'mistral-large-2512',
232 'mistral-large-latest',
233 ])
234 })
235})
236​
237describe('mistral model page modalities', () => {
238 const parse = (...blocks: Array<Array<unknown>>) =>
239 parseMistralPageModalities(mistralModelPage(['m-1'], blocks))
240 const base = [tip('Text input'), tip('Text output')]
241​
242 it('reads the tooltips of the Modalities block', () => {
243 expect(
244 parse([tip('Image input'), tip('Text input'), tip('Text output')]),
245 ).toEqual({ input: ['text', 'image'], output: ['text'] })
246 expect(parse([tip('Audio input'), tip('Text output')])).toEqual({
247 input: ['audio'],
248 output: ['text'],
249 })
250 // The side is matched whatever its case.
251 expect(
252 parse([tip('Text Input'), tip('Image input'), tip('Text OUTPUT')]),
253 ).toEqual({ input: ['text', 'image'], output: ['text'] })
254 // A reasoning marker is not a medium; the page's "Max output" span is
255 // outside the block.
256 expect(parse([...base, tip('Reasoning output')])).toEqual({
257 input: ['text'],
258 output: ['text'],
259 })
260 // A label served as its own lazy row.
261 expect(
262 parseMistralPageModalities(
263 mistralModelPage(
264 ['m-1'],
265 [
266 [
267 tip('Text input'),
268 [
269 '$',
270 '$L4f',
271 'k',
272 {
273 children: [['$', '$L50', null, { asChild: true }], '$Lc0'],
274 },
275 ],
276 ],
277 ],
278 { c0: ['$', '$L51', null, { children: 'Text output' }] },
279 ),
280 ),
281 ).toEqual({ input: ['text'], output: ['text'] })
282 // A tooltip that gains a prop or a key is still a tooltip.
283 expect(
284 parse([
285 ...base,
286 tip('Image input', { side: 'top' }),
287 [
288 '$',
289 '$L4f',
290 'audio',
291 {
292 children: [
293 ['$', '$L50', null, { asChild: true }],
294 ['$', '$L51', 'k1', { children: 'Audio input' }],
295 ],
296 },
297 ],
298 ]),
299 ).toEqual({ input: ['text', 'image', 'audio'], output: ['text'] })
300 })
301​
302 it.each([
303 ['an unknown medium', tip('Hologram input')],
304 ['a two-word medium', tip('Point cloud input')],
305 ['a medium with a digit', tip('3D input')],
306 ['a hyphenated medium', tip('3D-mesh input')],
307 ['a plural', tip('Images input')],
308 ['a reworded label', tip('Input: Image')],
309 ['a label with no side', tip('Accepts images')],
310 ['an empty tooltip', tip('')],
311 ['a tooltip that is not text', tip(['$', 'b', null, { children: 'x' }])],
312 ['reasoning as an input', tip('Reasoning input')],
313 ])('reads nothing when the block holds %s', (_name, extra) => {
314 expect(parse([...base, extra])).toBeNull()
315 })
316​
317 // A tooltip the walk cannot reach must not be dropped and the rest kept.
318 const image = tip('Image input')
319 const el = (tag: string, props: object) => ['$', tag, null, props]
320 const trigger = (asChild: unknown) =>
321 el('$L4f', {
322 children: [
323 el('$L50', asChild === undefined ? {} : { asChild }),
324 el('$L51', { children: 'Image input' }),
325 ],
326 })
327 it.each([
328 ['a reference with no row', '$Lnope'],
329 ['a tooltip in a Suspense', el('$Sreact.suspense', { children: '$Lc1' })],
330 ['a tooltip under a `content` prop', el('$L60', { content: image })],
331 ['a tooltip under a `fallback` prop', el('div', { fallback: image })],
332 ['object-valued children', el('div', { children: { nested: image } })],
333 ['a trigger with no asChild', trigger(undefined)],
334 ['a trigger with asChild "true"', trigger('true')],
335 ['a lone icon', el('svg', { 'aria-label': 'Image input' })],
336 ['text', 'Image input'],
337 ])('reads nothing when the block holds %s', (_name, extra) => {
338 expect(
339 parseMistralPageModalities(
340 mistralModelPage(['m-1'], [[...base, extra]], { c1: image }),
341 ),
342 ).toBeNull()
343 })
344​
345 it('follows a reference to a tooltip, and reads through plain wrappers', () => {
346 const full = { input: ['text', 'image'], output: ['text'] }
347 for (const extra of ['$Lc1', [[image]], el('div', { children: [image] })]) {
348 expect(
349 parseMistralPageModalities(
350 mistralModelPage(['m-1'], [[...base, extra]], { c1: image }),
351 ),
352 ).toEqual(full)
353 }
354 // The arrows between the two sides are not tooltips.
355 const arrows = el('div', {
356 className: 'flex',
357 children: [el('svg', {}), el('svg', {})],
358 })
359 expect(
360 parse([tip('Text input'), image, arrows, tip('Text output')]),
361 ).toEqual(full)
362 })
363​
364 it('reads nothing from one side, no block, or blocks that differ', () => {
365 expect(parse([tip('Text input'), tip('Image input')])).toBeNull()
366 expect(parse([tip('Text input'), tip('Reasoning output')])).toBeNull()
367 expect(parse()).toBeNull()
368 expect(parseMistralPageModalities('<h1>Mistral Medium</h1>')).toBeNull()
369 // The page renders the block once per layout; both must agree, so a
370 // second model's block cannot be merged in.
371 expect(parse(base, base)).toEqual({ input: ['text'], output: ['text'] })
372 expect(parse(base, [tip('Audio input'), tip('Audio output')])).toBeNull()
373 // Tooltips outside a Modalities block are not read.
374 expect(
375 parseMistralPageModalities(
376 `<script>self.__next_f.push([1,${JSON.stringify(
377 `1:${JSON.stringify(base)}\n`,
378 )}])</script>`,
379 ),
380 ).toBeNull()
381 })
382​
383 it('refuses a poll in which no model page states modalities', async () => {
384 const original = globalThis.fetch
385 globalThis.fetch = ((url: string) => {
386 const href = String(url)
387 const body = href.endsWith('/pricing')
388 ? PAGE
389 : href.endsWith('/changelogs')
390 ? ''
391 : mistralModelPage([href.slice(href.lastIndexOf('/') + 1)], [])
392 return Promise.resolve(new Response(body))
393 }) as typeof fetch
394 try {
395 await expect(mistralModelPricing()).rejects.toThrow(
396 /mistral model pages: 0 of \d+ state modalities/,
397 )
398 } finally {
399 globalThis.fetch = original
400 }
401 })
402​
403 it('drops an API id two pages state differently', () => {
404 const text = { input: ['text'], output: ['text'] }
405 const vision = { input: ['text', 'image'], output: ['text'] }
406 const byId = indexMistralModalities([
407 { slug: 'a-1', ids: ['a-1', 'a-latest'], hash: 'h1', modalities: text },
408 { slug: 'a-2', ids: ['a-2', 'a-latest'], hash: 'h2', modalities: vision },
409 { slug: 'b-1', ids: ['b-1'], hash: 'h3', modalities: null },
410 ])
411 expect([...byId.keys()]).toEqual(['a-1', 'a-2'])
412 expect(byId.get('a-2')).toEqual({
413 modalities: vision,
414 url: 'https://docs.mistral.ai/models/a-2',
415 hash: 'h2',
416 })
417 })
418})
419​
420describe('mistral model page price and max output', () => {
421 const widget = {
422 type: 'custom',
423 free: false,
424 input: [
425 { type: 'range', price: 0.004, denominator: '/Min' },
426 { type: 'flat', price: 0.1, denominator: '/M Tokens' },
427 ],
428 output: [{ type: 'range', price: 0.4, denominator: '/M Tokens' }],
429 }
430 const page = (extra: Record<string, unknown>) =>
431 mistralModelPage(['voxtral-small-2507'], [[tip('Text input')]], extra)
432​
433 it('keeps native OCR annotated-page pricing distinct from ordinary pages', () => {
434 // OCR 4.1's source widget names both denominators; numbers here are synthetic.
435 const ocr = {
436 type: 'custom',
437 free: false,
438 input: [
439 { type: 'flat', price: 7, denominator: '/1000 Pages' },
440 { type: 'flat', price: 11, denominator: '/1000 Annotated Pages' },
441 ],
442 output: [],
443 }
444 expect(parseMistralPagePrice(page({ a1: ocr }))).toEqual({
445 kind: 'unit',
446 meters: [
447 { param: 'pages', rate: 7 / 1000 },
448 { param: 'annotated_pages', rate: 11 / 1000, default: 0 },
449 ],
450 })
451 expect(() =>
452 parseMistralPagePrice(
453 page({
454 a1: {
455 ...ocr,
456 input: [
457 ocr.input[0],
458 {
459 type: 'flat',
460 originalPrice: 11,
461 denominator: '/1000 Annotated Pages',
462 },
463 ],
464 },
465 }),
466 ),
467 ).toThrow('unreadable amount')
468 expect(() =>
469 parseMistralPagePrice(
470 page({
471 a1: {
472 ...ocr,
473 input: [
474 ocr.input[0],
475 { type: 'flat', price: -1, denominator: '/1000 Annotated Pages' },
476 ],
477 },
478 }),
479 ),
480 ).toThrow('negative amount')
481 })
482​
483 it('reads mixed units and uses the current widget price', () => {
484 expect(parseMistralPagePrice(page({ a1: widget }))).toEqual({
485 kind: 'tokens',
486 rates: {
487 audio_minutes: 0.004,
488 input_tokens: 0.1 / 1e6,
489 output_tokens: 0.4 / 1e6,
490 },
491 })
492 const card = mistralRateCard(
493 parseMistralPagePrice(page({ a1: widget })) ?? {
494 kind: 'tokens',
495 rates: {},
496 },
497 {
498 url: 'https://docs.mistral.ai/models/voxtral-small-25-07',
499 hash: 'c'.repeat(64),
500 extractedAt: '2026-10-08T00:00:00.000Z',
501 },
502 )
503 expect(card).not.toBeNull()
504 if (!card) return
505 expect(
506 price(card, {}, { input_tokens: 1_000_000, output_tokens: 1_000_000 }),
507 ).toBeCloseTo(0.5, 9)
508 expect(
509 price(
510 card,
511 {},
512 {
513 input_tokens: 1_000_000,
514 output_tokens: 1_000_000,
515 audio_minutes: 2,
516 },
517 ),
518 ).toBeCloseTo(0.508, 9)
519 expect(
520 parseMistralPagePrice(
521 page({
522 a3: {
523 type: 'custom',
524 free: false,
525 input: [
526 {
527 price: 0.68,
528 originalPrice: 1.36,
529 denominator: '/M Tokens',
530 label: 'Input',
531 },
532 {
533 price: 0.07,
534 originalPrice: 0.14,
535 denominator: '/M Tokens',
536 label: 'Cached input',
537 },
538 ],
539 output: [
540 {
541 price: 2.09,
542 originalPrice: 4.18,
543 denominator: '/M Tokens',
544 label: 'Output',
545 },
546 ],
547 },
548 }),
549 ),
550 ).toEqual({
551 kind: 'tokens',
552 rates: {
553 input_tokens: 0.68 / 1e6,
554 cache_read_tokens: 0.07 / 1e6,
555 output_tokens: 2.09 / 1e6,
556 },
557 })
558 })
559​
560 it('rejects a missing current widget price rather than using originalPrice', () => {
561 expect(() =>
562 parseMistralPagePrice(
563 page({
564 a1: {
565 type: 'custom',
566 free: false,
567 input: [{ originalPrice: 9, denominator: '/M Tokens' }],
568 output: [{ price: 4, denominator: '/M Tokens' }],
569 },
570 }),
571 ),
572 ).toThrow(/unreadable amount/)
573 })
574​
575 it('stores no card for a free widget and throws when widgets disagree', () => {
576 expect(
577 parseMistralPagePrice(
578 page({
579 a1: { type: 'flat', free: true, price: 0, denominator: '/M Tokens' },
580 }),
581 ),
582 ).toBeNull()
583 expect(() =>
584 parseMistralPagePrice(
585 page({
586 a1: widget,
587 a2: {
588 type: 'custom',
589 free: false,
590 input: [{ price: 1, denominator: '/M Tokens' }],
591 output: [{ price: 2, denominator: '/M Tokens' }],
592 },
593 }),
594 ),
595 ).toThrow(/widgets disagree/)
596 })
597​
598 it('reads the Max output stat as 1024-based tokens', () => {
599 const stat = (label: string, value: string) => [
600 [
601 '$',
602 'span',
603 null,
604 {
605 className: 'uppercase',
606 children: ['$undefined', label],
607 },
608 ],
609 [
610 '$',
611 'div',
612 null,
613 {
614 className: 'text-lg font-bold font-mono text-primary-soft',
615 children: value,
616 },
617 ],
618 ]
619 expect(
620 parseMistralPageMaxOutput(page({ aa: stat('Max output', '128k') })),
621 ).toBe(128 * 1024)
622 // The context stat is not a max-output cap.
623 expect(
624 parseMistralPageMaxOutput(page({ aa: stat('Context', '1M') })),
625 ).toBeNull()
626 expect(
627 parseMistralPageMaxOutput(
628 page({
629 aa: stat('Max output', '128k'),
630 ab: stat('Max output', '256k'),
631 }),
632 ),
633 ).toBeNull()
634 })
635​
636 it('matches one index slug and no more', () => {
637 const slugs = parseMistralModelIndex(
638 '<a href="/models/overview">o</a><a href="/models/voxtral-small-25-07">v</a><a href="/models/leanstral-1-5">l</a><a href="/models/zai-glm-5-2">g</a> /models/page-abc',
639 )
640 const set = new Set(slugs)
641 expect(slugs).toEqual([
642 'voxtral-small-25-07',
643 'leanstral-1-5',
644 'zai-glm-5-2',
645 ])
646 expect(mistralIndexSlugFor('voxtral-small-2507', set)).toBe(
647 'voxtral-small-25-07',
648 )
649 expect(mistralIndexSlugFor('labs-leanstral-1-5', set)).toBe('leanstral-1-5')
650 expect(mistralIndexSlugFor('zai-glm-5-2', set)).toBe('zai-glm-5-2')
651 expect(mistralIndexSlugFor('mistral-medium-2604', set)).toBeNull()
652 expect(mistralIndexSlugFor('magistral-medium-latest', set)).toBeNull()
653 })
654​
655 it('reads the markdown Pricing line the HTML widget no longer shows', () => {
656 expect(
657 parseMistralMarkdownPrice(
658 '- Pricing: Input $1.5 /M Tokens; Output $7.5 /M Tokens\n',
659 ),
660 ).toEqual({
661 kind: 'tokens',
662 rates: { input_tokens: 1.5 / 1e6, output_tokens: 7.5 / 1e6 },
663 })
664 expect(
665 parseMistralMarkdownPrice(
666 '- Pricing: Input $0.7 /M Tokens; Cached input $0.07 /M Tokens; Output $2.1 /M Tokens',
667 ),
668 ).toEqual({
669 kind: 'tokens',
670 rates: {
671 input_tokens: 0.7 / 1e6,
672 cache_read_tokens: 0.07 / 1e6,
673 output_tokens: 2.1 / 1e6,
674 },
675 })
676 expect(parseMistralMarkdownPrice('- Pricing: Input $0.003 /Min')).toEqual({
677 kind: 'unit',
678 meters: [{ param: 'audio_minutes', rate: 0.003 }],
679 })
680 const pages = parseMistralMarkdownPrice(
681 '- Pricing: Input $4 /1000 Pages; Input $5 /1000 Annotated Pages',
682 )
683 expect(pages?.kind).toBe('unit')
684 if (pages?.kind !== 'unit') return
685 expect(pages.meters.map((meter) => meter.param)).toEqual([
686 'pages',
687 'annotated_pages',
688 ])
689 expect(
690 parseMistralMarkdownPrice(
691 '- Pricing: Free; Input $0 /M Tokens; Output $0 /M Tokens',
692 ),
693 ).toBeNull()
694 // #584: mistral-moderation-26-03 states no side on its free meter.
695 expect(
696 parseMistralMarkdownPrice('- Pricing: Free; $0 /M Tokens'),
697 ).toBeNull()
698 expect(() =>
699 parseMistralMarkdownPrice('- Pricing: $0.1 /M Tokens'),
700 ).toThrow(/unreadable markdown meter/)
701 // No `Free`: a side-less $0 could be a placeholder, not a stated price.
702 expect(() => parseMistralMarkdownPrice('- Pricing: $0 /M Tokens')).toThrow(
703 /unreadable markdown meter/,
704 )
705 expect(() =>
706 parseMistralMarkdownPrice('- Pricing: Free; $0 /request'),
707 ).toThrow(/unknown denominator/)
708 expect(
709 parseMistralMarkdownPrice('# Model\n- Status: Deprecated'),
710 ).toBeNull()
711 expect(() =>
712 parseMistralMarkdownPrice('- Pricing: Input $1 /request'),
713 ).toThrow(/unknown denominator/)
714 })
715​
716 it('pairs one overview API name with one slug and drops a name used twice', () => {
717 const slugs = parseMistralApiSlugs(`
718| [Medium 3.5](/models/mistral-medium-3-5-26-04) | \`mistral-medium-3-5\` | Deprecated | 256k | x | 2026-10-31 | 2027-04-30 | [Large 4](/models/mistral-large-4-0) |
719| [Large 3](/models/mistral-large-3-25-12) | \`mistral-large-2512\` | Deprecated |
720| [Seven](/models/mistral-7b-0-3) | \`open-mistral-7b\` | Retired |
721| [Seven older](/models/mistral-7b-0-2) | \`open-mistral-7b\` | Retired |
722| [Next](/models/mistral-next) | | Retired |
723`)
724 expect(slugs.get('mistral-medium-3-5')).toBe('mistral-medium-3-5-26-04')
725 expect(slugs.get('mistral-large-2512')).toBe('mistral-large-3-25-12')
726 expect(slugs.has('open-mistral-7b')).toBe(false)
727 expect(slugs.has('mistral-large-4')).toBe(false)
728 expect(() => parseMistralApiSlugs('| no ids |')).toThrow(
729 /parsed 0 API slugs/,
730 )
731 })
732​
733 it('prices a dropped row from the model page markdown', async () => {
734 const original = globalThis.fetch
735 const docs: Record<string, string> = {
736 'https://docs.mistral.ai/inference/pricing': `<h2>Flagship models</h2>
737<p>Prices /M Tokens</p>
738<table>
739<tr><td><a href="/models/mistral-small-4-0-26-03">Small</a></td><td>$0.15</td><td>—</td><td>$0.6</td></tr>
740</table>`,
741 'https://docs.mistral.ai/resources/changelogs': '',
742 'https://docs.mistral.ai/models.md':
743 '| [Medium 3.5](/models/mistral-medium-3-5-26-04) | `mistral-medium-3-5` | Deprecated |',
744 'https://docs.mistral.ai/models':
745 '<a href="/models/not-a-listed-id">x</a>',
746 'https://docs.mistral.ai/models/mistral-small-4-0-26-03':
747 mistralModelPage(
748 ['mistral-small-2603'],
749 [[tip('Text input'), tip('Text output')]],
750 ),
751 'https://docs.mistral.ai/models/mistral-medium-3-5-26-04':
752 mistralModelPage(
753 ['mistral-medium-3-5', 'mistral-medium-latest'],
754 [[tip('Text input'), tip('Text output')]],
755 ),
756 'https://docs.mistral.ai/models/mistral-medium-3-5-26-04.md':
757 '- Pricing: Input $1.5 /M Tokens; Output $7.5 /M Tokens\n',
758 'https://docs.mistral.ai/studio/agents/agent-tools/websearch.md':
759 MISTRAL_WEBSEARCH_GUIDE,
760 }
761 globalThis.fetch = ((url: string) => {
762 const body = docs[String(url)]
763 return Promise.resolve(
764 body === undefined
765 ? new Response('missing', { status: 404 })
766 : new Response(body),
767 )
768 }) as typeof fetch
769 try {
770 const lookup = await mistralModelPricing(undefined, [
771 'mistral-small-2603',
772 'mistral-medium-3-5',
773 'mistral-medium-latest',
774 'mistral-medium',
775 ])
776 const medium = lookup('mistral-medium-3-5')
777 const card = medium.pricing
778 if (!card) throw new Error('expected a medium card')
779 expect(
780 price(
781 card as RateCard,
782 {},
783 {
784 input_tokens: 1_000_000,
785 output_tokens: 1_000_000,
786 },
787 ),
788 ).toBeCloseTo(9, 6)
789 expect(medium.factSources?.pricing).toMatchObject({
790 sourceUrl: 'https://docs.mistral.ai/models/mistral-medium-3-5-26-04.md',
791 })
792 expect(lookup('mistral-medium-latest').pricing).toEqual(card)
793 expect(lookup.seen.has('mistral-medium-3-5')).toBe(true)
794 expect(lookup.seen.has('mistral-medium-latest')).toBe(true)
795 // A listing alias the page does not name stays out of `seen`.
796 expect(lookup.seen.has('mistral-medium')).toBe(false)
797 expect(lookup('mistral-small-2603').factSources?.pricing?.sourceUrl).toBe(
798 'https://docs.mistral.ai/inference/pricing',
799 )
800 } finally {
801 globalThis.fetch = original
802 }
803 })
804​
805 it('keeps the card when the markdown twin 404s and clears a page that states no price', async () => {
806 const original = globalThis.fetch
807 const docs: Record<string, string> = {
808 'https://docs.mistral.ai/inference/pricing': `<h2>Flagship models</h2>
809<p>Prices /M Tokens</p>
810<table>
811<tr><td><a href="/models/mistral-small-4-0-26-03">Small</a></td><td>$0.15</td><td>—</td><td>$0.6</td></tr>
812</table>`,
813 'https://docs.mistral.ai/resources/changelogs': '',
814 'https://docs.mistral.ai/models.md': `| [TTS](/models/voxtral-tts-26-03) | \`voxtral-mini-tts-2603\` | Deprecated |
815| [Leanstral](/models/leanstral-1-5) | \`labs-leanstral-1-5\` | Deprecated |`,
816 'https://docs.mistral.ai/models':
817 '<a href="/models/not-a-listed-id">x</a>',
818 'https://docs.mistral.ai/models/mistral-small-4-0-26-03':
819 mistralModelPage(
820 ['mistral-small-2603'],
821 [[tip('Text input'), tip('Text output')]],
822 ),
823 'https://docs.mistral.ai/models/voxtral-tts-26-03': mistralModelPage(
824 ['voxtral-mini-tts-2603'],
825 [[tip('Text input'), tip('Text output')]],
826 ),
827 'https://docs.mistral.ai/models/leanstral-1-5': mistralModelPage(
828 ['labs-leanstral-1-5'],
829 [[tip('Text input'), tip('Text output')]],
830 ),
831 'https://docs.mistral.ai/models/leanstral-1-5.md':
832 '- Pricing: Free; Input $0 /M Tokens; Output $0 /M Tokens\n',
833 'https://docs.mistral.ai/studio/agents/agent-tools/websearch.md':
834 MISTRAL_WEBSEARCH_GUIDE,
835 }
836 globalThis.fetch = ((url: string) => {
837 const body = docs[String(url)]
838 return Promise.resolve(
839 body === undefined
840 ? new Response('missing', { status: 404 })
841 : new Response(body),
842 )
843 }) as typeof fetch
844 try {
845 const lookup = await mistralModelPricing(undefined, [
846 'mistral-small-2603',
847 'voxtral-mini-tts-2603',
848 'labs-leanstral-1-5',
849 ])
850 expect(lookup.seen.has('voxtral-mini-tts-2603')).toBe(false)
851 expect(lookup('voxtral-mini-tts-2603').pricing).toBeUndefined()
852 expect(lookup('voxtral-mini-tts-2603').absent).toEqual({
853 pricing: 'unavailable',
854 })
855 expect(lookup('voxtral-mini-tts-2603').modalities).toEqual({
856 input: ['text'],
857 output: ['text'],
858 })
859 expect(lookup.seen.has('labs-leanstral-1-5')).toBe(true)
860 expect(lookup('labs-leanstral-1-5').pricing).toBeUndefined()
861 expect(lookup('labs-leanstral-1-5').absent).toBeUndefined()
862 } finally {
863 globalThis.fetch = original
864 }
865 })
866})
867​
868describe('mistral alias facts', () => {
869 it('copies one agreed fact onto mutual aliases and skips a conflict', () => {
870 const source = {
871 derivation: 'docs-derived' as const,
872 sourceUrl: 'https://docs.mistral.ai/models/mistral-small-4-0-26-03',
873 }
874 const models = [
875 {
876 rawId: 'mistral-small-latest',
877 modalities: { input: ['text'], output: ['text'] },
878 maxOutput: 131072,
879 factSources: { modalities: source, maxOutput: source },
880 },
881 { rawId: 'mistral-vibe-cli-fast' },
882 {
883 rawId: 'left',
884 pricing: { price: 1 },
885 },
886 {
887 rawId: 'right',
888 pricing: { price: 2 },
889 },
890 { rawId: 'neither' },
891 ]
892 copyMistralAliasFacts(
893 models,
894 new Map([
895 ['mistral-small-latest', ['mistral-vibe-cli-fast']],
896 ['mistral-vibe-cli-fast', ['mistral-small-latest']],
897 ['left', ['right', 'neither']],
898 ['right', ['left']],
899 ['neither', ['left']],
900 ]),
901 )
902 expect(models[1]).toMatchObject({
903 modalities: { input: ['text'], output: ['text'] },
904 maxOutput: 131072,
905 factSources: { modalities: source, maxOutput: source },
906 })
907 expect(models[4]?.pricing).toBeUndefined()
908 })
909})
910​
911describe('usdExpr', () => {
912 it('throws rather than compose a non-USD card and drop its currency', async () => {
913 const { compileTokenCard } = await import('@modelschemas/rate-card')
914 const { usdExpr } = await import('./mistral-pricing.ts')
915 const source = {
916 url: 'https://example.test/pricing',
917 hash: 'a'.repeat(64),
918 extractedAt: '2026-10-07T00:00:00Z',
919 }
920 const usd = compileTokenCard({ input_tokens: 1e-6 }, [], source)
921 const yuan = compileTokenCard({ input_tokens: 1e-6 }, [], source, {
922 currency: 'CNY',
923 })
924 if (!usd || !yuan) throw new Error('did not compile')
925 expect(usdExpr(usd)).toBe(usd.price)
926 expect(() => usdExpr(yuan)).toThrow('cannot extend a CNY card')
927 })
928})
929​
930describe('mistral model page features', () => {
931 // The live shape (2026-10-22): a "Features" heading, then a grid of
932 // `div`s keyed by feature id; later ones arrive as lazy rows.
933 const feature = (id: string, disabled: unknown = '$undefined') => [
934 '$',
935 'div',
936 id,
937 { className: 'flex flex-col', 'aria-disabled': disabled, children: [] },
938 ]
939 const page = (grid: Array<unknown>, extra: Record<string, unknown> = {}) =>
940 mistralModelPage(['m-1'], [[tip('Text input'), tip('Text output')]], {
941 f: [
942 '$',
943 '$L5b',
944 null,
945 {
946 children: [
947 [
948 '$',
949 '$L1c',
950 null,
951 { children: ['$', '$L1d', null, { children: 'Features' }] },
952 ],
953 ['$', 'div', null, { className: 'grid', children: grid }],
954 ],
955 },
956 ],
957 ...extra,
958 })
959​
960 it('reads feature ids, lazy rows followed', () => {
961 const html = page([feature('function-calling'), '$Lf2'], {
962 f2: feature('document-qna'),
963 })
964 expect(parseMistralPageFeatures(html)).toEqual([
965 'function-calling',
966 'document-qna',
967 ])
968 })
969​
970 it('throws on a grid it cannot fully read or grids that disagree', () => {
971 expect(() =>
972 parseMistralPageFeatures(page([feature('x'), '$Lmissing'])),
973 ).toThrow('Features grid')
974 expect(() => parseMistralPageFeatures(page([feature('x', true)]))).toThrow(
975 'Features grid',
976 )
977 const twice = page([feature('x')], {
978 ab: [
979 '$',
980 'div',
981 null,
982 {
983 children: [
984 [
985 '$',
986 '$L1c',
987 null,
988 { children: ['$', '$L1d', null, { children: 'Features' }] },
989 ],
990 ['$', 'div', null, { children: [feature('y')] }],
991 ],
992 },
993 ],
994 })
995 expect(() => parseMistralPageFeatures(twice)).toThrow('Features grid')
996 })
997​
998 it('reads nothing from a page with no Features grid', () => {
999 expect(parseMistralPageFeatures('<h1>no payload</h1>')).toBeNull()
1000 })
1001​
1002 it('adds file input only for document-qna on stated modalities', () => {
1003 const text = { input: ['text', 'image'], output: ['text'] }
1004 expect(withDocumentInput(text, ['document-qna'])).toEqual({
1005 input: ['text', 'image', 'file'],
1006 output: ['text'],
1007 })
1008 expect(withDocumentInput(text, ['function-calling'])).toBe(text)
1009 expect(withDocumentInput(text, null)).toBe(text)
1010 expect(withDocumentInput(null, ['document-qna'])).toBeNull()
1011 })
1013​
1014describe('mistral web search tools', () => {
1015 it('reads the guide ids, or throws without its any-model statement', () => {
1016 expect(parseMistralWebSearchTools(MISTRAL_WEBSEARCH_GUIDE)).toEqual([
1017 'web_search',
1018 'web_search_premium',
1019 ])
1020 expect(() =>
1021 parseMistralWebSearchTools(
1022 MISTRAL_WEBSEARCH_GUIDE.replace('any of our models', 'some models'),
1023 ),
1024 ).toThrow('no any-model statement')
1025 expect(() =>
1026 parseMistralWebSearchTools(
1027 MISTRAL_WEBSEARCH_GUIDE.replace('There are two versions:', 'Versions'),
1028 ),
1029 ).toThrow('names no tool id')
1030 })
1031​
1032 it('gives them only to a page that lists agents-conversations', () => {
1033 const tools = ['web_search', 'web_search_premium']
1034 expect(mistralConversationTools(['agents-conversations'], tools)).toEqual(
1035 tools,
1037 expect(mistralConversationTools(['chat-completions'], tools)).toEqual([])
1038 expect(mistralConversationTools(null, tools)).toEqual([])
1039 })