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