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

minimax.test.ts

202 lines6.2 KB

1import { afterEach, describe, expect, it } from 'vitest'
2​
3import {
4 MINIMAX_MAX_COMPLETION_TOKENS,
5 MINIMAX_PRICING_LLM_MDX,
6 MINIMAX_SDK_PAGE,
7 minimaxPricingHtml,
8} from '../fixtures/minimax-docs.ts'
9import {
10 MINIMAX_CHAT_SPEC_URL,
11 MINIMAX_MESSAGES_SPEC_URL,
12 MINIMAX_PRICING_URL,
13 MINIMAX_SDK_URL,
14} from '../minimax-docs.ts'
15import { MINIMAX_MODELS_URL, provider } from './minimax.ts'
16​
17/** Excerpt of platform.minimax.io models-intro.md (2026-10-04). */
18const FIXTURE = `
19### Language
20​
21| **Models** | **Description** |
22| :- | :- |
23| [MiniMax-M2.7](/docs/api-reference/text-anthropic-api) | Beginning the journey |
24| <a href="/docs/api-reference/text-anthropic-api">MiniMax-M3</a> | Frontier |
25​
26### Video
27​
28| **Models** | **Description** |
29| :- | :- |
30| [MiniMax H3](/docs/api-reference/video-generation-v2-create) | Next-gen open general-purpose multimodal video model |
31| [MiniMax H3 Max](/docs/api-reference/video-generation-v2-create) | High-speed video model post-trained by [fal.ai](https://fal.ai/) on MiniMax H3 |
32​
33### Audio
34​
35| **Models** | **Description** |
36| :- | :- |
37| [speech-2.8-hd](/docs/api-reference/speech-t2a-http) | Ultra-realistic quality featuring sound tags |
38| [speech-2.8-turbo](/docs/api-reference/speech-t2a-http) | Seamless speed meets natural flow |
40​
41const CHAT_SPEC = {
42 openapi: '3.1.0',
43 paths: { '/v1/chat/completions': { post: {} } },
44 components: {
45 schemas: {
46 ChatCompletionReq: {
47 properties: {
48 max_completion_tokens: {
49 type: 'integer',
50 description: MINIMAX_MAX_COMPLETION_TOKENS,
51 },
52 },
53 },
54 },
55 },
57​
58const PAGES: Record<string, string> = {
59 [MINIMAX_MODELS_URL]: FIXTURE,
60 [MINIMAX_SDK_URL]: MINIMAX_SDK_PAGE,
61 [MINIMAX_PRICING_URL]: minimaxPricingHtml(MINIMAX_PRICING_LLM_MDX),
62 [MINIMAX_CHAT_SPEC_URL]: JSON.stringify(CHAT_SPEC),
63 [MINIMAX_MESSAGES_SPEC_URL]: JSON.stringify({
64 openapi: '3.1.0',
65 paths: { '/anthropic/v1/messages': { post: {} } },
66 }),
68​
69const originalFetch = globalThis.fetch
70​
71function mockFetch(pages: Record<string, string>): void {
72 globalThis.fetch = ((url: string) => {
73 const page = pages[String(url)]
74 return page === undefined
75 ? Promise.reject(new Error(`unexpected fetch: ${String(url)}`))
76 : Promise.resolve(new Response(page))
77 }) as typeof fetch
79​
80afterEach(() => {
81 globalThis.fetch = originalFetch
82})
83​
84describe('minimax', () => {
85 it('lists linked model ids and fills chat rows from the docs pages', async () => {
86 mockFetch(PAGES)
87​
88 const listed = await provider.listModels({})
89​
90 expect(listed.models.map((model) => [model.rawId, model.activity])).toEqual(
91 [
92 ['MiniMax-M2.7', 'chat'],
93 ['MiniMax-M3', 'chat'],
94 ['speech-2.8-hd', 'audio'],
95 ['speech-2.8-turbo', 'audio'],
96 ],
97 )
98 const m3 = listed.models.find((model) => model.rawId === 'MiniMax-M3')
99 expect(m3).toMatchObject({
100 contextWindow: 1_000_000,
101 maxOutput: 524_288,
102 modalities: { input: ['text', 'image', 'video'], output: ['text'] },
103 reasoning: { mode: 'adaptive', mandatory: false },
104 pricing: {
105 tables: { rate: { base: { input_tokens: 0.3 / 1e6 } } },
106 source: { url: MINIMAX_PRICING_URL },
107 },
108 factSources: {
109 contextWindow: {
110 derivation: 'docs-derived',
111 sourceUrl: MINIMAX_SDK_URL,
112 },
113 maxOutput: { sourceUrl: MINIMAX_CHAT_SPEC_URL },
114 modalities: { sourceUrl: MINIMAX_SDK_URL },
115 reasoning: { sourceUrl: MINIMAX_SDK_URL },
116 pricing: { sourceUrl: MINIMAX_PRICING_URL },
117 },
118 })
119 // Speech rows stay as listed: the chat pages say nothing about them.
120 expect(
121 listed.models.find((model) => model.rawId === 'speech-2.8-hd'),
122 ).toEqual({ rawId: 'speech-2.8-hd', activity: 'audio', pricing: null })
123 expect(listed.models.some((model) => model.rawId === 'fal.ai')).toBe(false)
124 expect(listed.models.some((model) => model.rawId === 'MiniMax H3')).toBe(
125 false,
126 )
127 })
128​
129 it('prices from the HTML page when llms-full.txt renders tabs as labels', async () => {
130 // platform.minimax.io/docs/llms-full.txt (2026-10-21): `<Tab>` titles
131 // are bold lines and the struck price is gone (#399). Nothing reads it.
132 const flattened = [
133 '# Pricing Overview',
134 'Source: https://platform.minimax.io/docs/pricing/overview',
135 '',
136 '## LLM',
137 '',
138 '**Standard**',
139 '',
140 '| Model | Input | Output | Prompt caching Read |',
141 '| :- | :- | :- | :- |',
142 '| **MiniMax-M3** ≤ 512k input tokens | \\$0.30 / M tokens | \\$1.20 / M tokens | \\$0.06 / M tokens |',
143 ].join('\n')
144 mockFetch({
145 ...PAGES,
146 'https://platform.minimax.io/docs/llms-full.txt': flattened,
147 })
148​
149 const listed = await provider.listModels({})
150​
151 const m3 = listed.models.find((model) => model.rawId === 'MiniMax-M3')
152 expect(m3?.pricing).toMatchObject({
153 tables: {
154 rate: {
155 base: { input_tokens: 0.3 / 1e6 },
156 '512000': { input_tokens: 0.6 / 1e6 },
157 },
158 },
159 })
160 })
161​
162 it('throws when a docs page parses nothing', async () => {
163 mockFetch({
164 ...PAGES,
165 [MINIMAX_PRICING_URL]: minimaxPricingHtml(
166 MINIMAX_PRICING_LLM_MDX.replaceAll('`Input`', '`Input (batch)`'),
167 ),
168 })
169 await expect(provider.listModels({})).rejects.toThrow(
170 'minimax pricing page: parsed 0 model rows',
171 )
172 })
173​
174 it('syncs both chat documents and binds chat rows to chat completions', async () => {
175 mockFetch(PAGES)
176​
177 const spec = await provider.fetchSpec({})
178​
179 expect(spec.sources.map((source) => source.url)).toEqual([
180 MINIMAX_CHAT_SPEC_URL,
181 MINIMAX_MESSAGES_SPEC_URL,
182 ])
183 expect(spec.specs).toHaveLength(2)
184 expect(provider.classify('/v1/chat/completions', {})).toBe('chat')
185 expect(provider.classify('/anthropic/v1/messages', {})).toBe('chat')
186 expect(
187 provider.classify('/anthropic/v1/messages/count_tokens', {}),
188 ).toBeNull()
189 expect(
190 provider.generationEndpointId?.({
191 rawId: 'MiniMax-M3',
192 activity: 'chat',
193 }),
194 ).toBe('v1/chat/completions')
195 expect(
196 provider.generationEndpointId?.({
197 rawId: 'speech-2.8-hd',
198 activity: 'audio',
199 }),
200 ).toBeNull()
201 })
202})