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

minimax-docs.ts

627 lines23.7 KB

1/**
2 * MiniMax chat facts from platform.minimax.io. The Anthropic SDK page has
3 * the context-window, thinking, and content-type tables. The chat spec
4 * states the output cap. The pricing overview page has the token prices,
5 * USD per 1M tokens. A parse that finds no rows throws.
6 *
7 * The pricing section is read from the HTML page's compiled MDX
8 * (`minimax-pricing-mdx.ts`): the `.md` export (#379) and, since
9 * 2026-10-21, `llms-full.txt` (#399) render `<Tab>` titles as bold lines,
10 * which leaves no tab boundary to tell the tiers apart.
11 *
12 * The China platform (platform.minimaxi.com) publishes the same pages in
13 * Chinese: `MINIMAX_CN` holds its URLs and wording. Its prices are yuan
14 * per 1M tokens, stored as CNY cards.
15 */
16import { compileTokenCard } from '@modelschemas/rate-card'
17import type { TokenRateTier } from '@modelschemas/rate-card'
18​
19import { tagDocsFacts } from './fact-sources.ts'
20import {
21 assertParsed,
22 cachedDocs,
23 markdownSection,
24 markdownTableRows,
25 tokenCount,
26} from './model-facts.ts'
27import type { ModelFacts } from './model-facts.ts'
28import { minimaxPricingSection } from './minimax-pricing-mdx.ts'
29import { sha256Text } from './types.ts'
30import type { ModelReasoning } from './types.ts'
31​
32const DOCS = 'https://platform.minimax.io/docs'
33export const MINIMAX_SDK_URL = `${DOCS}/api-reference/text-anthropic-api.md`
34export const MINIMAX_PRICING_URL = `${DOCS}/pricing/overview`
35export const MINIMAX_CHAT_SPEC_URL = `${DOCS}/api-reference/text/api/openapi-chat-openai.json`
36export const MINIMAX_MESSAGES_SPEC_URL = `${DOCS}/api-reference/text/api/openapi-chat-anthropic.json`
37​
38const ID_PREFIX = 'MiniMax-'
39​
40/** One platform's page URLs and the wording its tables and spec use. */
41export interface MinimaxPlatform {
42 /** Names the platform in a zero-row parse error. */
43 label: string
44 /** Hosts allowed to answer a page fetch, redirects included. */
45 hosts: Array<string>
46 sdkUrl: string
47 chatSpecUrl: string
48 /** The pricing overview HTML page, whose compiled MDX holds the prices. */
49 pricingUrl: string
50 /** ISO-4217 code of the pricing page's amounts; absent for USD. */
51 currency?: string
52 /** `## <heading>` of the token-price tables. */
53 priceSection: string
54 /** Title of the standard-tier `<Tab>`; every other tab is dropped. */
55 standardTab: string
56 /**
57 * Title of the only `<Accordion>` whose rows are standard prices. One
58 * with any other title is ignored when it holds no price row, and
59 * refuses the section when it does.
60 */
61 legacyAccordion: string
62 /** First header cell of a price table. */
63 modelHeader: string
64 /** Price-table header cell → the usage lever it prices. */
65 priceLevers: Record<string, string>
66 /** A billed price cell, whole: group 1 is the amount per 1M tokens. */
67 price: RegExp
68 /** The badge that makes a struck price the standing one. */
69 permanent: RegExp
70 /** A model cell's tier bound: group 1 is `≤` or `>`, group 2 the count. */
71 inputBound: RegExp
72 /** Header of the context-window column. */
73 contextWindow: string
74 /** `Messages Field Support` status: every model. */
75 allModels: RegExp
76 /**
77 * Status naming the only models that take the type: group 1 is the
78 * `M3.1-Flash-Preview / M3` list and nothing else may follow it.
79 */
80 onlyModels: RegExp
81 /** `Thinking Control` cells, each anchored to the end of the cell. */
82 thinkingOn: RegExp
83 cannotDisable: RegExp
84 thinkingOff: RegExp
85 /** Group 1 is the effort list in the `output_config.effort` row. */
86 efforts: RegExp
87 /** Splits the `max_completion_tokens` description into clauses. */
88 clause: RegExp
89 /** Group 1 is a clause's maximum, a plain token count. */
90 maximum: RegExp
91 otherModels: RegExp
93​
94export const MINIMAX: MinimaxPlatform = {
95 label: 'minimax',
96 hosts: ['platform.minimax.io'],
97 sdkUrl: MINIMAX_SDK_URL,
98 chatSpecUrl: MINIMAX_CHAT_SPEC_URL,
99 pricingUrl: MINIMAX_PRICING_URL,
100 priceSection: 'LLM',
101 standardTab: 'Standard',
102 legacyAccordion: 'Legacy Models',
103 modelHeader: '**Model**',
104 // The header carries the unit, so a reworded unit prices nothing.
105 priceLevers: {
106 '**Input**<br />$ / M tokens': 'input_tokens',
107 '**Output**<br />$ / M tokens': 'output_tokens',
108 '**Prompt caching Read**<br />$ / M tokens': 'cache_read_tokens',
109 '**Prompt caching Write**<br />$ / M tokens': 'cache_write_tokens',
110 },
111 price: /^\$(\d+(?:\.\d+)?)$/,
112 permanent: /<span[^>]*>\s*Permanent\b/,
113 inputBound: /([≤>])\s*([\d.]+[kKmM]?) input tokens/,
114 contextWindow: 'Context Window',
115 allModels: /^fully supported$/i,
116 onlyModels: /^(M\d[\w.-]*(?:\s*\/\s*M\d[\w.-]*)*) only$/i,
117 thinkingOn: /^thinking on$/i,
118 cannotDisable: /(?:^|[—;,] )thinking (?:cannot be disabled|remains on)$/i,
119 thinkingOff: /^thinking stays off$/i,
120 efforts: /Accepts ([^;.]+)/,
121 clause: /;|\.\s/,
122 maximum: /the maximum is ([\d,]+)/i,
123 otherModels: /other models/i,
125​
126const DOCS_CN = 'https://platform.minimaxi.com/docs'
127export const MINIMAX_CN_MESSAGES_SPEC_URL = `${DOCS_CN}/api-reference/text/api/openapi-chat-anthropic.json`
128​
129export const MINIMAX_CN: MinimaxPlatform = {
130 label: 'minimax-cn',
131 // platform.minimaxi.com answers 302 to the same path on platform.minimax.cn.
132 hosts: ['platform.minimaxi.com', 'platform.minimax.cn'],
133 sdkUrl: `${DOCS_CN}/api-reference/text-anthropic-api.md`,
134 chatSpecUrl: `${DOCS_CN}/api-reference/text/api/openapi-chat-openai.json`,
135 pricingUrl: `${DOCS_CN}/pricing/overview`,
136 currency: 'CNY',
137 priceSection: '语言模型',
138 standardTab: '标准',
139 legacyAccordion: '历史模型',
140 modelHeader: '**模型**',
141 // The header carries the unit, so a reworded unit prices nothing.
142 priceLevers: {
143 '**输入价格**<br /> 元/百万 tokens': 'input_tokens',
144 '**输出价格**<br /> 元/百万 tokens': 'output_tokens',
145 '**缓存读取**<br /> 元/百万 tokens': 'cache_read_tokens',
146 '**缓存写入**<br /> 元/百万 tokens': 'cache_write_tokens',
147 },
148 price: /^(\d+(?:\.\d+)?)$/,
149 permanent: /<span[^>]*>\s*永久/,
150 inputBound: /([≤>])\s*([\d.]+[kKmM]?) 输入 tokens/,
151 contextWindow: '上下文窗口',
152 allModels: /^完全支持$/,
153 onlyModels: /^仅\s*(M\d[\w.-]*(?:\s*\/\s*M\d[\w.-]*)*)$/,
154 thinkingOn: /^开启 thinking$/,
155 cannotDisable: /(?:^|,)thinking (?:无法关闭|仍保持开启)$/,
156 thinkingOff: /^保持 thinking 关闭$/,
157 efforts: /可取([^;。]+)/,
158 clause: /;|。/,
159 // `推荐值上限为` is a cap on the recommended value, not on output.
160 maximum: /(?<!推荐值)上限为\s*([\d,]+)/,
161 otherModels: /其他模型/,
163​
164/**
165 * The pages indent what sits inside a `<section>` or `<Accordion>` (the
166 * legacy models' table), and `markdownTableRows` reads only lines that
167 * start with `|`: every page parser reads the page dedented.
168 */
169function dedent(markdown: string): string {
170 return markdown
171 .split('\n')
172 .map((line) => line.trim())
173 .join('\n')
175​
176/** `MiniMax-M3` must not match inside `MiniMax-M3.1-Flash-Preview`. */
177function names(text: string, id: string): boolean {
178 const escaped = id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
179 return new RegExp(`(?<![\\w.-])${escaped}(?![\\w-]|\\.\\w)`).test(text)
181​
182/** The `Model Name | Context Window` table. */
183export function parseMinimaxContextWindows(
184 markdown: string,
185 platform: MinimaxPlatform = MINIMAX,
186): Map<string, number> {
187 const out = new Map<string, number>()
188 let column = -1
189 for (const cells of markdownTableRows(dedent(markdown))) {
190 const header = cells.indexOf(platform.contextWindow)
191 if (header >= 0) {
192 column = header
193 continue
194 }
195 const id = (cells[0] ?? '').replace(/<[^>]+>/g, '').trim()
196 const window = cells[column] ?? ''
197 if (!id.startsWith(ID_PREFIX) || !/^[\d,]+$/.test(window)) continue
198 const tokens = tokenCount(window)
199 if (tokens !== null) out.set(id, tokens)
200 }
201 return out
203​
204const INPUT_TYPES = new Set(['text', 'image', 'video', 'audio'])
205​
206/**
207 * The `Messages Field Support` table. A `type="image"` row is every model
208 * when its status is `Fully supported`, and otherwise only the models the
209 * status names (`M3.1-Flash-Preview / M3 only`). Empty when a status reads
210 * as neither or names a model the page does not list, so a reworded row
211 * (`M2.x not supported`) cannot move a type between models.
212 */
213export function parseMinimaxInputModalities(
214 markdown: string,
215 ids: Array<string>,
216 platform: MinimaxPlatform = MINIMAX,
217): Map<string, Array<string>> {
218 const out = new Map<string, Array<string>>()
219 for (const cells of markdownTableRows(dedent(markdown))) {
220 const type = cells[0]?.match(/^`type="(\w+)"`$/)?.[1]
221 const status = cells[1] ?? ''
222 if (!type || !INPUT_TYPES.has(type)) continue
223 const everyModel = platform.allModels.test(status)
224 const only = status.match(platform.onlyModels)?.[1]
225 if (!everyModel && only === undefined) return new Map()
226 const named = everyModel
227 ? ids
228 : [...(only ?? '').matchAll(/\bM\d[\w.-]*/g)].map(
229 (match) => `${ID_PREFIX}${match[0]}`,
230 )
231 if (named.some((id) => !ids.includes(id))) return new Map()
232 for (const id of named) {
233 out.set(id, [...(out.get(id) ?? []), type])
234 }
235 }
236 return out
238​
239/**
240 * The `Thinking Control` table: every model takes `thinking.type: adaptive`,
241 * and the `disabled` column says whether thinking can be turned off. A
242 * `M2.x` row covers the listed `MiniMax-M2…` ids that have no row of their
243 * own. Effort names come from the `output_config.effort` parameter row,
244 * for the models that row names.
245 */
246export function parseMinimaxReasoning(
247 markdown: string,
248 ids: Array<string>,
249 platform: MinimaxPlatform = MINIMAX,
250): Map<string, ModelReasoning> {
251 const out = new Map<string, ModelReasoning>()
252 const families: Array<[string, ModelReasoning]> = []
253 const rows = markdownTableRows(dedent(markdown))
254 let adaptive = -1
255 let disabled = -1
256 for (const cells of rows) {
257 if (cells.includes('`{"type": "disabled"}`')) {
258 adaptive = cells.indexOf('`{"type": "adaptive"}`')
259 disabled = cells.indexOf('`{"type": "disabled"}`')
260 continue
261 }
262 if (adaptive < 0 || !platform.thinkingOn.test(cells[adaptive] ?? ''))
263 continue
264 const off = cells[disabled] ?? ''
265 const mandatory = platform.cannotDisable.test(off)
266 if (!mandatory && !platform.thinkingOff.test(off)) continue
267 const reasoning: ModelReasoning = { mode: 'adaptive', mandatory }
268 const model = cells[0] ?? ''
269 const id = model.match(/^`([^`]+)`$/)?.[1]
270 const family = model.match(/^(M\d+)\.x$/)?.[1]
271 if (id && ids.includes(id)) out.set(id, reasoning)
272 else if (family) families.push([`${ID_PREFIX}${family}`, reasoning])
273 }
274 for (const [prefix, reasoning] of families) {
275 for (const id of ids) {
276 const rest = id.startsWith(prefix) ? id.slice(prefix.length) : null
277 if (rest === null || out.has(id)) continue
278 if (rest === '' || /^[.-]/.test(rest)) out.set(id, reasoning)
279 }
280 }
281 const effort = rows.find((cells) => cells[0] === '`output_config.effort`')
282 const description = effort?.[2] ?? ''
283 const efforts = [
284 ...(description.match(platform.efforts)?.[1] ?? '').matchAll(/`([a-z]+)`/g),
285 ].flatMap((match) => (match[1] ? [match[1]] : []))
286 if (efforts.length > 0) {
287 for (const [id, reasoning] of out) {
288 if (names(description, id)) out.set(id, { ...reasoning, efforts })
289 }
290 }
291 return out
293​
294/**
295 * The spec's `max_completion_tokens` description: `For A and B … the
296 * maximum is N; for other models … the maximum is M`. The `other models`
297 * number goes only to ids the description never names. Empty unless every
298 * id it does name got a maximum from its own clause, so a reworded clause
299 * cannot hand a named model the catch-all. Also empty when one clause
300 * holds two maximums or names ids beside `other models` (the clauses ran
301 * together), or when a maximum carries a unit (`512K`) or a decimal.
302 */
303export function parseMinimaxMaxOutput(
304 description: string,
305 ids: Array<string>,
306 platform: MinimaxPlatform = MINIMAX,
307): Map<string, number> {
308 const out = new Map<string, number>()
309 let others: number | null = null
310 for (const clause of description.split(platform.clause)) {
311 const maximums = [...clause.matchAll(new RegExp(platform.maximum, 'g'))]
312 const [found] = maximums
313 if (!found) continue
314 const after = clause.slice(found.index + found[0].length)
315 if (maximums.length > 1 || /^(?:\.\d|\s*[kKmM万千亿])/.test(after)) {
316 return new Map()
317 }
318 const tokens = tokenCount(found[1])
319 if (tokens === null) continue
320 const named = ids.filter((id) => names(clause, id))
321 if (named.length > 0 && platform.otherModels.test(clause)) return new Map()
322 for (const id of named) out.set(id, tokens)
323 if (named.length === 0 && platform.otherModels.test(clause)) others = tokens
324 }
325 const named = ids.filter((id) => names(description, id))
326 if (named.length === 0 || named.some((id) => !out.has(id))) return new Map()
327 if (others !== null) {
328 for (const id of ids) if (!out.has(id)) out.set(id, others)
329 }
330 return out
332​
333function maxCompletionTokensDescription(spec: unknown): string {
334 let found = ''
335 const walk = (node: unknown) => {
336 if (found || typeof node !== 'object' || node === null) return
337 const cap = (node as Record<string, unknown>).max_completion_tokens
338 const description =
339 typeof cap === 'object' && cap !== null
340 ? (cap as Record<string, unknown>).description
341 : undefined
342 if (typeof description === 'string') found = description
343 else for (const value of Object.values(node)) walk(value)
344 }
345 walk(spec)
346 return found
348​
349/**
350 * `~~$0.60~~ $0.30` → 0.30: the struck list price is not
351 * billed. The caller takes a struck row only under a `Permanent` badge.
352 */
353function perMillion(cell: string, price: RegExp): number | null {
354 const billed = cell.replace(/~~[^~]*~~/g, '').trim()
355 const amount = billed.match(price)?.[1]
356 return amount ? Number(amount) : null
358​
359/** A price row's first cell: the bold id, then any bound or badge. */
360const MODEL_CELL = /^\*\*([A-Za-z0-9][\w.-]*)\*\*(.*)$/
361​
362/** A Mintlify callout: group 2 is its body, to the close or the end. */
363const CALLOUT =
364 /<(Note|Info|Tip|Warning|Check|Danger|Callout)\b[^>]*>([\s\S]*?)(?:<\/\1>|$)/g
365​
366export interface MinimaxRates {
367 base: Record<string, number>
368 tiers: Array<TokenRateTier>
370​
371/**
372 * The `## LLM` tables, standard tier only: the `Priority` tab is dropped.
373 * A `> 512k input tokens` row is a tier over the same model's base row.
374 * Rates are per token, in the platform's currency.
375 *
376 * What it cannot attribute it refuses. Nothing is priced when a `<Tab`
377 * other than the standard one survives, a tab or accordion nests another,
378 * a price row sits in a callout (`<Note>`, `<Info>`, …), or the section
379 * holds a heading of its own: markdown, `<h1>`–`<h6>`, or a line that is
380 * bold text alone (`**Batch API**`). A model gets no price when a
381 * row of its has text beside the id that is not a bound or the permanent
382 * badge, a price cell that does not read, a second base row, or a
383 * repeated tier threshold.
384 */
385export function parseMinimaxPricing(
386 markdown: string,
387 platform: MinimaxPlatform = MINIMAX,
388): Map<string, MinimaxRates> {
389 // MDX text nests each `## ` section in a `<section>` element, which
390 // closes the section even when the next heading is not `## `.
391 // `minimaxPricingSection` output already ends where the section does.
392 const tabbed = markdownSection(dedent(markdown), platform.priceSection)
393 .replace(/<\/section>[\s\S]*/i, '')
394 .replace(
395 new RegExp(
396 `<Tab title="(?!${platform.standardTab}")[^"]*">[\\s\\S]*?</Tab>`,
397 'g',
398 ),
399 '',
400 )
401 const out = new Map<string, MinimaxRates>()
402 // A tab the strip did not recognise, or a sub-heading, may hold another
403 // tier's table under the same headers. A tab nested in a dropped one
404 // ends the strip early and leaves a `</Tab>` with no standard opening.
405 const standard = `<Tab title="${platform.standardTab}">`
406 const content = tabbed.slice(tabbed.indexOf('\n'))
407 if (
408 /<Tab(?!s>)/.test(tabbed.replaceAll(standard, '')) ||
409 tabbed.split(standard).length !== tabbed.split('</Tab>').length ||
410 /^#{1,6} /m.test(content) ||
411 /^\*\*[^*\n]+\*\*:?$/m.test(content) ||
412 /<h[1-6]\b/i.test(tabbed)
413 ) {
414 return out
415 }
416 // So may an accordion that is not the legacy models, or a callout. One
417 // with no price row (a FAQ, a note) is dropped; one with a price row
418 // cannot be attributed. A nested accordion ends the match early, so the
419 // outer body holds the inner opening and its own `</Accordion>` is left.
420 const priceRow = (cells: Array<string>) =>
421 cells[0] === platform.modelHeader || MODEL_CELL.test(cells[0] ?? '')
422 const foreign: Array<string> = []
423 const section = tabbed.replace(
424 /<Accordion\b([^>]*)>([\s\S]*?)<\/Accordion>/g,
425 (whole, attributes: string, body: string) => {
426 const title = /\btitle="([^"]*)"/.exec(attributes)?.[1]
427 if (/<Accordion\b/.test(body)) foreign.push(whole)
428 if (title === platform.legacyAccordion) return whole
429 if (markdownTableRows(body).some(priceRow)) foreign.push(whole)
430 return ''
431 },
432 )
433 for (const [, , body = ''] of section.matchAll(CALLOUT)) {
434 if (markdownTableRows(body).some(priceRow)) return out
435 }
436 // An accordion the section cut left open was never checked at all.
437 const unclosed = section.replace(
438 /<Accordion\b[^>]*>[\s\S]*?<\/Accordion>/g,
439 '',
440 )
441 if (foreign.length > 0 || /<\/?Accordion\b/.test(unclosed)) return out
442 const refused = new Set<string>()
443 const based = new Set<string>()
444 /** A base row's `≤ N` bound; the first tier must start at the same N. */
445 const baseBound = new Map<string, number | null>()
446 let header: Array<string> = []
447 for (const cells of markdownTableRows(section)) {
448 if (cells[0] === platform.modelHeader) {
449 header = cells
450 continue
451 }
452 const model = cells[0]?.match(MODEL_CELL)
453 const id = model?.[1]
454 if (!id) continue
455 // A struck price without a `Permanent` badge may be a promotion that
456 // ends: the model gets no card.
457 const struck = cells.some((cell) => cell.includes('~~'))
458 if (struck && !platform.permanent.test(model[2] ?? '')) {
459 refused.add(id)
460 continue
461 }
462 const rates: Record<string, number> = {}
463 // Every column beside the model is a price this must read: an unknown
464 // header or a cell that does not parse refuses the model, so a lever
465 // is never dropped from a card that still prices the rest.
466 let unread = cells.length !== header.length
467 header.slice(1).forEach((name, index) => {
468 const lever = platform.priceLevers[name]
469 const amount = lever
470 ? perMillion(cells[index + 1] ?? '', platform.price)
471 : null
472 if (lever && amount !== null) rates[lever] = amount / 1e6
473 else unread = true
474 })
475 const bound = model[2]?.match(platform.inputBound)
476 const above = bound?.[1] === '>' ? tokenCount(bound[2]) : null
477 // Beside the id: a bound, the permanent badge, a footnote mark. Any
478 // other text qualifies the price in a way this does not read.
479 const qualifier = (model[2] ?? '')
480 .replace(/<span[^>]*>[^<]*<\/span>/g, (span) =>
481 platform.permanent.test(span) ? '' : span,
482 )
483 .replace(bound?.[0] ?? '', '')
484 .replace(/<br \/>|\\\*/g, '')
485 .trim()
486 const entry = out.get(id) ?? { base: {}, tiers: [] }
487 const repeated =
488 above === null
489 ? based.has(id)
490 : entry.tiers.some((tier) => tier.minPromptTokens === above)
491 if (
492 unread ||
493 rates.input_tokens === undefined ||
494 rates.output_tokens === undefined ||
495 qualifier !== '' ||
496 (bound && bound[1] === '>' && above === null) ||
497 repeated
498 ) {
499 refused.add(id)
500 continue
501 }
502 if (above !== null) entry.tiers.push({ minPromptTokens: above, rates })
503 else {
504 entry.base = rates
505 based.add(id)
506 if (bound) baseBound.set(id, tokenCount(bound[2]))
507 }
508 out.set(id, entry)
509 }
510 for (const [id, entry] of out) {
511 // `≤ 256k` beside `> 512k` leaves 256k–512k unpriced, and a bounded
512 // base with no tier leaves everything above it: neither is a card.
513 const tiers = entry.tiers.map((tier) => tier.minPromptTokens)
514 const first = tiers.length > 0 ? Math.min(...tiers) : undefined
515 if (baseBound.has(id) ? baseBound.get(id) !== first : first !== undefined) {
516 refused.add(id)
517 }
518 }
519 for (const id of refused) out.delete(id)
520 return out
522​
523const FETCH_TIMEOUT_MS = 30_000
524​
525/**
526 * One docs page. Throws when a redirect lands on a host that is not the
527 * platform's own: the two platforms publish the same paths, so a redirect
528 * across them would hand one platform the other's document.
529 */
530export async function fetchMinimaxPage(
531 url: string,
532 platform: MinimaxPlatform,
533): Promise<string> {
534 const response = await fetch(url, {
535 signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
536 })
537 if (!response.ok) {
538 throw new Error(
539 `fetch failed: ${url} → ${String(response.status)} ${response.statusText}`,
540 )
541 }
542 const host = new URL(response.url || url).host
543 if (!platform.hosts.includes(host)) {
544 throw new Error(`${platform.label}: ${url} was answered by ${host}`)
545 }
546 return response.text()
548​
549/** Facts for one chat id; `{}` when the docs do not name it. */
550export async function minimaxModelFacts(
551 kv?: KVNamespace,
552 platform: MinimaxPlatform = MINIMAX,
553): Promise<(rawId: string) => Partial<ModelFacts>> {
554 const { label, sdkUrl, chatSpecUrl, pricingUrl } = platform
555 const fetchPage = (url: string) => fetchMinimaxPage(url, platform)
556 const doc = await cachedDocs(kv, sdkUrl, async () => {
557 const [sdk, pricingHtml, specText] = await Promise.all([
558 fetchPage(sdkUrl),
559 fetchPage(pricingUrl),
560 fetchPage(chatSpecUrl),
561 ])
562 // Hashed as the rendered section: the HTML around it changes with
563 // every docs deploy.
564 const pricingPage = minimaxPricingSection(
565 pricingHtml,
566 platform.priceSection,
567 `${label} pricing page`,
568 )
569 const windows = parseMinimaxContextWindows(sdk, platform)
570 assertParsed(windows, `${label} context windows`)
571 const ids = [...windows.keys()]
572 const inputs = parseMinimaxInputModalities(sdk, ids, platform)
573 assertParsed(inputs, `${label} input modalities`)
574 const reasoning = parseMinimaxReasoning(sdk, ids, platform)
575 assertParsed(reasoning, `${label} thinking table`)
576 const caps = parseMinimaxMaxOutput(
577 maxCompletionTokensDescription(JSON.parse(specText) as unknown),
578 ids,
579 platform,
580 )
581 assertParsed(caps, `${label} max output`)
582 const prices = parseMinimaxPricing(pricingPage, platform)
583 assertParsed(prices, `${label} pricing page`)
584​
585 const [sdkHash, pricingHash, specHash] = await Promise.all([
586 sha256Text(sdk),
587 sha256Text(pricingPage),
588 sha256Text(specText),
589 ])
590 const extractedAt = new Date().toISOString()
591 const facts: Record<string, Partial<ModelFacts>> = {}
592 for (const id of ids) {
593 const input = inputs.get(id)
594 const fromSdk = {
595 contextWindow: windows.get(id) ?? null,
596 modalities: input ? { input, output: ['text'] } : null,
597 reasoning: reasoning.get(id) ?? null,
598 }
599 // A maximum equal to the model's whole context window is the context
600 // bound, not an output cap: nothing is stored for it.
601 const cap = caps.get(id)
602 const maxOutput =
603 cap === undefined || cap === fromSdk.contextWindow ? null : cap
604 const rates = prices.get(id)
605 const pricing = rates
606 ? compileTokenCard(
607 rates.base,
608 rates.tiers,
609 { url: pricingUrl, hash: pricingHash, extractedAt },
610 { currency: platform.currency },
611 )
612 : null
613 facts[id] = {
614 ...fromSdk,
615 maxOutput,
616 pricing,
617 factSources: {
618 ...tagDocsFacts(fromSdk, sdkUrl, sdkHash),
619 ...tagDocsFacts({ maxOutput }, chatSpecUrl, specHash),
620 ...tagDocsFacts({ pricing }, pricingUrl, pricingHash),
621 },
622 }
623 }
624 return { facts }
625 })
626 return (rawId) => doc.facts[rawId] ?? {}