Open History to see the last commit
1import { readFileSync } from 'node:fs'
2
3import { describe, expect, it } from 'vitest'
4
5import { price } from '@modelschemas/rate-card'
6import type { RateCard } from '@modelschemas/rate-card'
7
8import { provider as cerebras } from './adapters/cerebras.ts'
9import { provider as deepseek } from './adapters/deepseek.ts'
10import { dashscopeListedModel } from './adapters/dashscope.ts'
11import { provider as fireworks } from './adapters/fireworks.ts'
12import { provider as hyperbolic } from './adapters/hyperbolic.ts'
13import { provider as jina } from './adapters/jina.ts'
14import { provider as moonshot } from './adapters/moonshot.ts'
15import { provider as novita } from './adapters/novita.ts'
16import { provider as perplexity } from './adapters/perplexity.ts'
17import { provider as sambanova } from './adapters/sambanova.ts'
18import { parseDeepseekPricing } from './deepseek-pricing.ts'
19import { parseFireworksPricing } from './fireworks-pricing.ts'
20import { parseKimiDocTables } from './kimi-doc-tables.ts'
21import { parseMoonshotPricing } from './moonshot-pricing.ts'
22import { DEEPSEEK_THINKING_URL, KIMI_THINKING_URL } from './provider-replay.ts'
23import {
24 DEEPSEEK_REPLAY_FIXTURE,
25 KIMI_REPLAY_FIXTURE,
26} from './fixtures/provider-replay.ts'
27import {
28 cerebrasCatalogRows,
29 parseCerebrasModelPage,
30} from './cerebras-pricing.ts'
31
32const DEEPSEEK_HTML = `
33<table>
34<tr><td>MODEL</td><td>deepseek-flash</td><td>deepseek-v4-pro</td></tr>
35<tr><td>PRICING</td></tr>
36<tr><td>OFF-PEAK</td><td>$0.003</td><td>$0.022</td></tr>
37<tr><td>PEAK</td><td>$0.006</td><td>$0.044</td></tr>
38<tr><td>OFF-PEAK</td><td>$0.15</td><td>$0.66</td></tr>
39<tr><td>PEAK</td><td>$0.3</td><td>$1.32</td></tr>
40<tr><td>OFF-PEAK</td><td>$0.6</td><td>$1.98</td></tr>
41<tr><td>PEAK</td><td>$1.2</td><td>$3.96</td></tr>
42<tr><td>Concurrency Limit</td><td>2500</td><td>500</td></tr>
43</table>`
44
45const FIREWORKS_MD = `
46| Model | Standard | Priority |
47| - | - | - |
48| [DeepSeek V4.1 Flash](https://app.fireworks.ai/models/fireworks/deepseek-v4p1-flash) | $0.30 / $0.006 / $1.20 | $0.375 / $0.0075 / $1.50 |
49| [DeepSeek V4.1 Flash (US)](https://app.fireworks.ai/models/fireworks/deepseek-v4p1-flash) | $0.45 / $0.009 / $1.80 | $0.56 / $0.01 / $2.25 |
50| [Kimi K3 Fast](https://app.fireworks.ai/models/fireworks/kimi-k3) | $4.50 / $0.45 / $22.50 | — |
51| Less than 4B parameters | $0.10 |
52`
53
54// The compiled MDX body of platform.kimi.ai/docs/pricing/chat (2026-10-23).
55const MOONSHOT_PAGE = readFileSync(
56 new URL('./fixtures/platform.kimi.ai-pricing-chat.html.txt', import.meta.url),
57 'utf8',
58)
59
60const CEREBRAS_CATALOG = `
61| [OpenAI GPT OSS](/models/openai-oss) | \`gpt-oss-120b\` | 120 billion |
62`
63
64// The MDX-source <ModelInfo> JSX (the .md export before issue #381).
65const CEREBRAS_PAGE = `
66<ModelInfo
67 modelId="gpt-oss-120b"
68 pricing={{
69 inputPrice: "$0.35 / M tokens",
70 outputPrice: "$0.75 / M tokens"
71 }}
72 inputOutput={{
73 inputFormats: ["text"],
74 outputFormats: ["text"]
75 }}
76 features={[
77 "Reasoning",
78 "Tool Calling"
79 ]}
80 contextLength={{
81 paidTiers: "131k tokens"
82 }}
83 maxOutput={{
84 freeTier: "32k tokens",
85 paidTiers: "40k tokens"
86 }}
87/>
88`
89
90// The HTML page's compiled MDX (issue #381), trimmed from
91// inference-docs.cerebras.ai/models/qwen-3.8-27b on 2026-10-20.
92const CEREBRAS_HTML = `<script>self.__next_f.push([1,"_jsx(_components.p,{children:['Model ID: ',_jsx(_components.code,{children:\`qwen-3.8-27b\`}),\`. Context window: 64K tokens (65,536) for Free Trial and 128K tokens (131,072) for paid tiers and trial customers. Maximum output: 32K tokens (32,768) for Free Trial and 40K tokens (40,960) for paid tiers and trial customers. Pricing: \`]}),_jsx(_MdxComponentBoundary,{name:\`ModelInfo\`,children:_jsx(ModelInfo,{modelId:\`qwen-3.8-27b\`,playgroundUrl:\`https://cloud.cerebras.ai\`,contextLength:{freeTier:\`64k tokens\`,paidTiers:\`128k tokens\`},maxOutput:{freeTier:\`32k tokens\`,paidTiers:\`40k tokens\`},speed:{value:\`~1850\`,unit:\`tokens/sec\`},pricing:{inputPrice:\`$0.99 / M tokens\`,outputPrice:\`$1.49 / M tokens\`},rateLimits:[{tier:\`Free Trial\`,requestsPerMin:\`5\`}],endpoints:[\`Chat Completions\`],features:[\`Image Inputs\`,\`Reasoning\`,\`Tool Calling\`],inputOutput:{inputFormats:[\`text\`,\`image\`],outputFormats:[\`text\`]},knownLimitations:[_jsxs(_components.span,{children:[\`Reasoning is enabled by default at \`,_jsx(_components.code,{children:\`high\`}),\`.\`]})]})})"])</script>`
93
94// A minimal compiled ModelInfo for the listModels test (hand-built).
95const CEREBRAS_OSS_HTML = `<script>self.__next_f.push([1,"_jsx(ModelInfo,{modelId:\`gpt-oss-120b\`,contextLength:{freeTier:\`65k tokens\`,paidTiers:\`131k tokens\`},maxOutput:{freeTier:\`32k tokens\`,paidTiers:\`40k tokens\`},pricing:{inputPrice:\`$0.35 / M tokens\`,outputPrice:\`$0.75 / M tokens\`},features:[\`Reasoning\`,\`Tool Calling\`],inputOutput:{inputFormats:[\`text\`],outputFormats:[\`text\`]}})"])</script>`
96
97function inputUsd(card: unknown): number {
98 return price(card as RateCard, {}, { input_tokens: 1e6, output_tokens: 0 })
99}
100
101function json(body: unknown): Response {
102 return new Response(JSON.stringify(body), {
103 status: 200,
104 headers: { 'content-type': 'application/json' },
105 })
106}
107
108async function withFetch(
109 handler: (url: string) => Response,
110 run: () => Promise<void>,
111): Promise<void> {
112 const original = globalThis.fetch
113 globalThis.fetch = ((url: string) =>
114 Promise.resolve(handler(String(url)))) as typeof fetch
115 try {
116 await run()
117 } finally {
118 globalThis.fetch = original
119 }
120}
121
122describe('deepseek pricing page', () => {
123 it('keeps both periods and drops a model the table does not name', () => {
124 const parsed = parseDeepseekPricing(DEEPSEEK_HTML)
125 expect(parsed.get('deepseek-flash')).toEqual({
126 off_peak: { cacheRead: 0.003, input: 0.15, output: 0.6 },
127 peak: { cacheRead: 0.006, input: 0.3, output: 1.2 },
128 })
129 expect(parsed.get('deepseek-v4-pro')?.off_peak.input).toBe(0.66)
130 expect(parsed.get('deepseek-v4-pro')?.peak.input).toBe(1.32)
131 expect(parsed.has('deepseek-chat')).toBe(false)
132 })
133
134 it('throws when a named model lacks a peak set', () => {
135 const offPeakOnly = [
136 'MODEL',
137 'deepseek-flash',
138 'PRICING',
139 '$0.003',
140 '$0.15',
141 '$0.6',
142 'Concurrency',
143 ].join('\n')
144 expect(() => parseDeepseekPricing(offPeakOnly)).toThrow(/expected 6 prices/)
145 })
146})
147
148describe('fireworks pricing page', () => {
149 it('maps standard cells, skips US and size bands, and splits fast routers', () => {
150 const parsed = parseFireworksPricing(FIREWORKS_MD)
151 expect(parsed.get('accounts/fireworks/models/deepseek-v4p1-flash')).toEqual(
152 { input: 0.3, cacheRead: 0.006, output: 1.2 },
153 )
154 expect(parsed.get('accounts/fireworks/routers/kimi-k3-fast')?.input).toBe(
155 4.5,
156 )
157 expect(parsed.size).toBe(2)
158 })
159})
160
161describe('moonshot pricing page', () => {
162 it('reads K2 cache columns and K3 cache-write columns by title', () => {
163 const parsed = parseMoonshotPricing(parseKimiDocTables(MOONSHOT_PAGE))
164 expect(parsed.get('kimi-k2.6')).toEqual({
165 cacheRead: 0.16,
166 input: 0.95,
167 output: 4,
168 })
169 expect(parsed.get('kimi-k3')).toEqual({
170 cacheWrite: 3,
171 cacheWrite1h: 6,
172 cacheRead: 0.3,
173 input: 3,
174 output: 15,
175 })
176 })
177
178 it('leaves a row unpriced when a price cell is not plain text', () => {
179 // Struck cache-hit and cache-miss cells must not shift the K3 output
180 // and cache writes into the input levers.
181 const struck = (amount: string) =>
182 `_jsx(_components.del,{children:\`$${amount}\`})`
183 const page = MOONSHOT_PAGE.replace(
184 '`$3.00 / MTok`,`$15.00 / MTok`,`$0.30 / MTok`',
185 () =>
186 `${struck('3.00 / MTok')},${struck('15.00 / MTok')},\`$0.30 / MTok\``,
187 )
188 expect(page).not.toBe(MOONSHOT_PAGE)
189 const parsed = parseMoonshotPricing(parseKimiDocTables(page))
190 expect(parsed.has('kimi-k3')).toBe(false)
191 expect(parsed.has('kimi-k2.6')).toBe(true)
192 })
193
194 it.each([
195 ['a unit suffix', '`$0.16 / MTok (promo)`'],
196 ['another unit', '`$0.16 / KTok`'],
197 ['a yuan price', '`¥0.16 / MTok`'],
198 ['no cache-hit price', '`—`'],
199 ])('leaves a row with %s unpriced', (_name, to) => {
200 const page = MOONSHOT_PAGE.replace('`$0.16 / MTok`', to)
201 expect(page).not.toBe(MOONSHOT_PAGE)
202 const parsed = parseMoonshotPricing(parseKimiDocTables(page))
203 expect(parsed.has('kimi-k2.6')).toBe(false)
204 expect(parsed.has('kimi-k3')).toBe(true)
205 })
206
207 it('prices no row of a table with a title it does not know', () => {
208 const page = MOONSHOT_PAGE.replace(
209 '{title:`Output`,width:`22%`}',
210 '{title:`Batch output`,width:`22%`}',
211 )
212 expect(page).not.toBe(MOONSHOT_PAGE)
213 const parsed = parseMoonshotPricing(parseKimiDocTables(page))
214 expect(parsed.has('kimi-k2.6')).toBe(false)
215 expect(parsed.has('kimi-k3')).toBe(true)
216 })
217})
218
219describe('cerebras model pages', () => {
220 it('reads the catalog link and the ModelInfo price', () => {
221 expect(cerebrasCatalogRows(CEREBRAS_CATALOG)).toEqual([
222 { slug: 'openai-oss', id: 'gpt-oss-120b' },
223 ])
224 // As of 2026-10-22 the catalog links the .md export (issue #437).
225 expect(
226 cerebrasCatalogRows(
227 '| [Qwen 3.8 27B](/models/qwen-3.8-27b.md) | `qwen-3.8-27b` | 27 billion |',
228 ),
229 ).toEqual([{ slug: 'qwen-3.8-27b', id: 'qwen-3.8-27b' }])
230 // As of 2026-10-23 the links carry the docs origin (issue #486).
231 expect(
232 cerebrasCatalogRows(
233 '| [OpenAI GPT OSS](https://inference-docs.cerebras.ai/models/openai-oss.md) | `gpt-oss-120b` | 120 billion |',
234 ),
235 ).toEqual([{ slug: 'openai-oss', id: 'gpt-oss-120b' }])
236 const facts = parseCerebrasModelPage(CEREBRAS_PAGE)
237 expect(facts?.inputPerMillion).toBe(0.35)
238 expect(facts?.outputPerMillion).toBe(0.75)
239 expect(facts?.modalities).toEqual({ input: ['text'], output: ['text'] })
240 expect(facts?.capabilities).toEqual(['reasoning', 'tools'])
241 expect(facts?.maxOutput).toBe(40_000)
242 expect(facts?.contextWindow).toBe(131_000)
243 })
244
245 it('reads the compiled ModelInfo props from the HTML page', () => {
246 expect(parseCerebrasModelPage(CEREBRAS_HTML)).toEqual({
247 inputPerMillion: 0.99,
248 outputPerMillion: 1.49,
249 modalities: { input: ['text', 'image'], output: ['text'] },
250 capabilities: ['reasoning', 'tools'],
251 contextWindow: 131_072,
252 maxOutput: 40_960,
253 })
254 })
255
256 it('reads the compiled copy with pricing when an unpriced copy comes first', () => {
257 const unpriced =
258 '_jsx(ModelInfo,{modelId:`gpt-oss-120b`,features:[`Reasoning`]})'
259 expect(
260 parseCerebrasModelPage(`${unpriced}${CEREBRAS_OSS_HTML}`),
261 ).toMatchObject({ inputPerMillion: 0.35, maxOutput: 40_000 })
262 })
263
264 it('throws when two priced compiled copies disagree', () => {
265 const other = CEREBRAS_OSS_HTML.replace('$0.35', '$0.40')
266 expect(() =>
267 parseCerebrasModelPage(`${CEREBRAS_OSS_HTML}${other}`),
268 ).toThrow('ModelInfo copies disagree')
269 })
270
271 it('keeps the context sentence out of the max output sentence', () => {
272 const facts = parseCerebrasModelPage(
273 `\`. Context window: 65k tokens (free tier), 131k tokens (paid). Max output: 32K tokens (32,768) for Free Trial and 40K tokens (40,960) for paid tiers.\`${CEREBRAS_OSS_HTML}`,
274 )
275 expect(facts?.contextWindow).toBe(131_000)
276 expect(facts?.maxOutput).toBe(40_960)
277 })
278
279 it('prefers the paid parenthetical context window over 128k', () => {
280 const facts = parseCerebrasModelPage(`
281Context window: 64K tokens (65,536) for Free Trial and 128K tokens (131,072) for paid tiers and trial customers.
282<ModelInfo
283 contextLength={{
284 paidTiers: "128k tokens"
285 }}
286/>
287`)
288 expect(facts?.contextWindow).toBe(131_072)
289 })
290
291 it('prefers the paid parenthetical output cap over 40k', () => {
292 const facts = parseCerebrasModelPage(`
293Maximum output: 32K tokens (32,768) for Free Trial and 40K tokens (40,960) for paid tiers.
294<ModelInfo
295 maxOutput={{
296 freeTier: "32k tokens",
297 paidTiers: "40k tokens"
298 }}
299/>
300`)
301 expect(facts?.maxOutput).toBe(40_960)
302 })
303})
304
305describe('issue #109 listModels', () => {
306 it('sets deepseek activity and a period card, and leaves an unpriced id null', async () => {
307 await withFetch(
308 (url) => {
309 if (url.includes('api.deepseek.com/models')) {
310 return json({
311 data: [
312 {
313 id: 'deepseek-flash',
314 output_modalities: ['text'],
315 input_modalities: ['text', 'image'],
316 effort: { supported_levels: ['high'] },
317 },
318 { id: 'deepseek-other' },
319 ],
320 })
321 }
322 if (url.includes('quick_start/pricing')) {
323 return new Response(DEEPSEEK_HTML, { status: 200 })
324 }
325 if (url === DEEPSEEK_THINKING_URL)
326 return new Response(DEEPSEEK_REPLAY_FIXTURE)
327 return new Response('missing', { status: 404 })
328 },
329 async () => {
330 const { models } = await deepseek.listModels({
331 DEEPSEEK_API_KEY: 'test',
332 })
333 const flash = models.find((model) => model.rawId === 'deepseek-flash')
334 const other = models.find((model) => model.rawId === 'deepseek-other')
335 expect(flash?.activity).toBe('chat')
336 expect(flash?.modalities).toEqual({
337 input: ['text', 'image'],
338 output: ['text'],
339 })
340 expect(flash?.pricing).toBeTruthy()
341 const card = flash?.pricing as RateCard
342 expect(card.inputs.pricing_period).toMatchObject({
343 bound: 'usage',
344 values: ['off_peak', 'peak'],
345 })
346 expect(card.inputs.pricing_period).not.toHaveProperty('default')
347 expect(
348 price(
349 card,
350 {},
351 {
352 input_tokens: 1e6,
353 output_tokens: 0,
354 pricing_period: 'off_peak',
355 },
356 ),
357 ).toBeCloseTo(0.15, 9)
358 expect(
359 price(
360 card,
361 {},
362 {
363 input_tokens: 1e6,
364 output_tokens: 0,
365 pricing_period: 'peak',
366 },
367 ),
368 ).toBeCloseTo(0.3, 9)
369 expect(other?.activity).toBeNull()
370 expect(other?.pricing ?? null).toBeNull()
371 },
372 )
373 })
374
375 it('prices a cerebras chat row from its model page and leaves an unlisted id null', async () => {
376 await withFetch(
377 (url) => {
378 if (url.includes('api.cerebras.ai')) {
379 return json({
380 data: [{ id: 'gpt-oss-120b' }, { id: 'not-on-the-page' }],
381 })
382 }
383 if (url.endsWith('/models/overview.md')) {
384 return new Response(CEREBRAS_CATALOG, { status: 200 })
385 }
386 if (url.endsWith('/models/openai-oss')) {
387 return new Response(CEREBRAS_OSS_HTML, { status: 200 })
388 }
389 if (url.endsWith('/capabilities/reasoning.md')) {
390 return new Response(
391 `
392| Model | Default effort | Availability |
393| - | - | - |
394| [GPT OSS 120B](#gpt-oss-120b) | \`medium\` | Shared and Dedicated Inference |
395
396## Model behavior
397
398### GPT OSS 120B
399
400[\`gpt-oss-120b\`](/models/openai-oss) always enables reasoning. Use \`reasoning_effort\` to select one of the following levels.
401
402| Value | Behavior |
403| - | - |
404| \`low\` | Selects low reasoning effort |
405| \`medium\` (default) | Selects medium reasoning effort |
406| \`high\` | Selects high reasoning effort |
407| \`none\` | Not supported |
408`,
409 { status: 200 },
410 )
411 }
412 if (url.endsWith('/openapi.yaml')) {
413 return new Response(
414 `
415 max_completion_tokens:
416 type: integer
417 description: The maximum number of tokens that can be generated.
418 max_tokens:
419 type: integer
420 description: >
421 An alias for \`max_completion_tokens\`. Do not send both parameters
422 in the same request.
423 Developer messages are supported only by \`gpt-oss-120b\`.
424`,
425 { status: 200 },
426 )
427 }
428 return new Response('missing', { status: 404 })
429 },
430 async () => {
431 const { models } = await cerebras.listModels({
432 CEREBRAS_API_KEY: 'test',
433 })
434 const priced = models.find((model) => model.rawId === 'gpt-oss-120b')
435 const bare = models.find((model) => model.rawId === 'not-on-the-page')
436 expect(priced?.activity).toBe('chat')
437 expect(priced?.modalities).toEqual({
438 input: ['text'],
439 output: ['text'],
440 })
441 expect(inputUsd(priced?.pricing)).toBeCloseTo(0.35, 9)
442 expect(priced?.maxOutput).toBe(40_000)
443 expect(priced?.contextWindow).toBe(131_000)
444 expect(priced?.reasoning).toEqual({
445 mode: 'effort',
446 mandatory: true,
447 efforts: ['low', 'medium', 'high'],
448 })
449 expect(priced?.requestMap).toMatchObject({
450 maxTokensField: 'max_completion_tokens',
451 developerRole: true,
452 reasoningEffort: true,
453 thinking: {
454 on: { reasoning_effort: 'high' },
455 off: null,
456 },
457 })
458 expect(priced?.factSources?.maxOutput?.sourceUrl).toBe(
459 'https://inference-docs.cerebras.ai/models/openai-oss',
460 )
461 expect(priced?.factSources?.reasoning?.sourceUrl).toBe(
462 'https://inference-docs.cerebras.ai/capabilities/reasoning.md',
463 )
464 expect(bare?.activity).toBe('chat')
465 expect(bare?.pricing ?? null).toBeNull()
466 expect(bare?.maxOutput ?? null).toBeNull()
467 expect(bare?.reasoning ?? null).toBeNull()
468 expect(bare?.requestMap?.developerRole).toBe(false)
469 expect(bare?.requestMap?.maxTokensField).toBe('max_completion_tokens')
470 },
471 )
472 })
473
474 it('prices moonshot from the docs table and keeps a zero quote null', async () => {
475 await withFetch(
476 (url) => {
477 if (url.includes('api.moonshot.ai')) {
478 return json({
479 data: [
480 {
481 id: 'kimi-k2.6',
482 supports_image_in: true,
483 supports_video_in: false,
484 supports_reasoning: true,
485 context_length: 262144,
486 },
487 { id: 'kimi-free' },
488 ],
489 })
490 }
491 if (url.includes('pricing/chat')) {
492 return new Response(MOONSHOT_PAGE, { status: 200 })
493 }
494 if (url === KIMI_THINKING_URL) return new Response(KIMI_REPLAY_FIXTURE)
495 return new Response('missing', { status: 404 })
496 },
497 async () => {
498 const { models } = await moonshot.listModels({
499 MOONSHOT_API_KEY: 'test',
500 })
501 const kimi = models.find((model) => model.rawId === 'kimi-k2.6')
502 const free = models.find((model) => model.rawId === 'kimi-free')
503 expect(kimi?.activity).toBe('chat')
504 expect(kimi?.modalities).toEqual({
505 input: ['text', 'image'],
506 output: ['text'],
507 })
508 expect(kimi?.capabilities).toEqual(['reasoning'])
509 expect(inputUsd(kimi?.pricing)).toBeCloseTo(0.95, 9)
510 expect(free?.activity).toBe('chat')
511 expect(free?.pricing ?? null).toBeNull()
512 },
513 )
514 })
515
516 it('prices a fireworks chat row and leaves a reranker and a missing price null', async () => {
517 await withFetch(
518 (url) => {
519 // This pricing-only synthetic case states no reasoning evidence.
520 // Distinguish model metadata from the inference listing response.
521 for (const id of ['deepseek-v4p1-flash', 'unpriced']) {
522 const name = 'accounts/fireworks/models/' + id
523 if (url === 'https://api.fireworks.ai/v1/' + name)
524 return json({ name, description: '' })
525 }
526 if (url.includes('api.fireworks.ai')) {
527 return json({
528 data: [
529 {
530 id: 'accounts/fireworks/models/deepseek-v4p1-flash',
531 kind: 'HF_BASE_MODEL',
532 supports_chat: true,
533 supports_image_input: true,
534 supports_tools: true,
535 },
536 {
537 id: 'accounts/fireworks/models/qwen3-reranker-8b',
538 kind: 'HF_BASE_MODEL',
539 supports_chat: true,
540 },
541 {
542 id: 'accounts/fireworks/models/unpriced',
543 kind: 'HF_BASE_MODEL',
544 supports_chat: true,
545 supports_image_input: false,
546 },
547 ],
548 })
549 }
550 if (url.includes('serverless/pricing.md')) {
551 return new Response(FIREWORKS_MD, { status: 200 })
552 }
553 return new Response('missing', { status: 404 })
554 },
555 async () => {
556 const { models } = await fireworks.listModels({
557 FIREWORKS_API_KEY: 'test',
558 })
559 const chat = models.find((model) => model.rawId.includes('deepseek'))
560 const rerank = models.find((model) => model.rawId.includes('reranker'))
561 const bare = models.find((model) => model.rawId.includes('unpriced'))
562 expect(chat?.activity).toBe('chat')
563 expect(chat?.modalities).toEqual({
564 input: ['text', 'image'],
565 output: ['text'],
566 })
567 expect(chat?.capabilities).toEqual(['tools'])
568 expect(inputUsd(chat?.pricing)).toBeCloseTo(0.3, 9)
569 expect(rerank?.activity).toBeNull()
570 expect(rerank?.pricing ?? null).toBeNull()
571 expect(bare?.activity).toBe('chat')
572 expect(bare?.pricing ?? null).toBeNull()
573 },
574 )
575 })
576
577 it('compiles a novita decimal and leaves a tiered row null', async () => {
578 await withFetch(
579 () =>
580 json({
581 data: [
582 {
583 id: 'zai-org/glm',
584 model_type: 'chat',
585 input_modalities: ['text'],
586 output_modalities: ['text'],
587 features: ['function-calling'],
588 pricing: {
589 prompt: { price_per_m_decimal: '0.15' },
590 completion: { price_per_m_decimal: '0.5' },
591 },
592 },
593 {
594 id: 'tiered',
595 model_type: 'chat',
596 is_tiered_billing: true,
597 pricing: {
598 prompt: { price_per_m_decimal: '1' },
599 completion: { price_per_m_decimal: '2' },
600 },
601 },
602 ],
603 }),
604 async () => {
605 const { models } = await novita.listModels({ NOVITA_API_KEY: 'test' })
606 const chat = models.find((model) => model.rawId === 'zai-org/glm')
607 const tiered = models.find((model) => model.rawId === 'tiered')
608 expect(chat?.activity).toBe('chat')
609 expect(chat?.capabilities).toContain('tools')
610 expect(inputUsd(chat?.pricing)).toBeCloseTo(0.15, 9)
611 expect(tiered?.activity).toBe('chat')
612 expect(tiered?.pricing ?? null).toBeNull()
613 },
614 )
615 })
616
617 it('compiles perplexity per-million quotes and rejects an untagged unit', async () => {
618 await withFetch(
619 (url) =>
620 url.endsWith('/models.md')
621 ? new Response('<Tab title="x">\n| `perplexity/sonar` | — |\n</Tab>')
622 : url.endsWith('/effort.md')
623 ? new Response(
624 '<Accordion title="x — current effort level values">\n* **Model:** `a/b`\n* **Tools:** `web_search`\n</Accordion>',
625 )
626 : json({
627 data: [
628 {
629 id: 'perplexity/sonar',
630 pricing: { input: 1, output: 1, unit: 'usd_per_1m_tokens' },
631 },
632 {
633 id: 'mystery',
634 pricing: { input: 1, output: 1, unit: 'credits' },
635 },
636 ],
637 }),
638 async () => {
639 const { models } = await perplexity.listModels({
640 PERPLEXITY_API_KEY: 'test',
641 })
642 const sonar = models.find((model) => model.rawId === 'perplexity/sonar')
643 const mystery = models.find((model) => model.rawId === 'mystery')
644 expect(sonar?.activity).toBe('chat')
645 expect(inputUsd(sonar?.pricing)).toBeCloseTo(1, 9)
646 expect(
647 perplexity.generationEndpointId?.({
648 rawId: 'perplexity/sonar',
649 activity: 'chat',
650 }),
651 ).toBe('v1/agent')
652 expect(mystery?.pricing ?? null).toBeNull()
653 },
654 )
655 })
656
657 it('sets jina activity from output modalities and skips an all-zero price', async () => {
658 const chatSpec = {
659 openapi: '3.1.0',
660 components: {
661 schemas: {
662 ChatCompletionRequest: {
663 type: 'object',
664 properties: {
665 messages: {
666 type: 'array',
667 items: { $ref: '#/components/schemas/ChatMessage' },
668 },
669 model: { type: 'string', const: 'jina-ocr-v1' },
670 max_completion_tokens: { type: 'integer', minimum: 1 },
671 },
672 required: ['messages', 'model'],
673 },
674 ChatMessage: {
675 type: 'object',
676 properties: {
677 role: {
678 type: 'string',
679 enum: ['system', 'developer', 'user', 'assistant'],
680 },
681 },
682 },
683 },
684 },
685 }
686 await withFetch(
687 (url) =>
688 url.endsWith('/openapi.json')
689 ? json(chatSpec)
690 : json({
691 data: [
692 {
693 id: 'jina-embeddings-v3',
694 output_modalities: ['embeddings'],
695 input_modalities: ['text'],
696 pricing: { prompt: '0.00000005', completion: '0' },
697 },
698 {
699 id: 'jina-reranker-v3',
700 output_modalities: ['text'],
701 input_modalities: ['text'],
702 pricing: { prompt: '0', completion: '0' },
703 },
704 ],
705 }),
706 async () => {
707 const { models } = await jina.listModels({ JINA_API_KEY: 'test' })
708 const embed = models.find((model) => model.rawId.includes('embeddings'))
709 const rerank = models.find((model) => model.rawId.includes('reranker'))
710 expect(embed?.activity).toBe('embeddings')
711 expect(inputUsd(embed?.pricing)).toBeCloseTo(0.05, 9)
712 expect(rerank?.activity).toBeNull()
713 expect(rerank?.pricing ?? null).toBeNull()
714 },
715 )
716 })
717
718 it('prices sambanova per token and leaves a zero quote null', async () => {
719 await withFetch(
720 () =>
721 json({
722 data: [
723 {
724 id: 'DeepSeek-V3.2',
725 context_length: 32768,
726 pricing: { prompt: '0.00000300', completion: '0.00000450' },
727 },
728 {
729 id: 'free',
730 pricing: { prompt: '0', completion: '0' },
731 },
732 ],
733 }),
734 async () => {
735 const { models } = await sambanova.listModels({
736 SAMBANOVA_API_KEY: 'test',
737 })
738 const chat = models.find((model) => model.rawId === 'DeepSeek-V3.2')
739 const free = models.find((model) => model.rawId === 'free')
740 expect(chat?.activity).toBe('chat')
741 expect(chat?.contextWindow).toBe(32768)
742 expect(inputUsd(chat?.pricing)).toBeCloseTo(3, 9)
743 expect(free?.pricing ?? null).toBeNull()
744 },
745 )
746 })
747
748 it('prices hyperbolic per million tokens from the listing', async () => {
749 await withFetch(
750 () =>
751 json({
752 data: [
753 {
754 id: 'deepseek-ai/DeepSeek-R1',
755 supports_chat: true,
756 supports_image_input: false,
757 supports_tools: false,
758 input_price: 2,
759 output_price: 2,
760 },
761 {
762 id: 'no-price',
763 supports_chat: true,
764 supports_image_input: false,
765 },
766 ],
767 }),
768 async () => {
769 const { models } = await hyperbolic.listModels({
770 HYPERBOLIC_API_KEY: 'test',
771 })
772 const chat = models.find((model) => model.rawId.includes('DeepSeek'))
773 const bare = models.find((model) => model.rawId === 'no-price')
774 expect(chat?.activity).toBe('chat')
775 expect(chat?.modalities).toEqual({
776 input: ['text'],
777 output: ['text'],
778 })
779 expect(chat?.capabilities).toEqual([])
780 expect(chat?.exactCapabilities).toBe(true)
781 expect(inputUsd(chat?.pricing)).toBeCloseTo(2, 9)
782 expect(bare?.activity).toBe('chat')
783 expect(bare?.capabilities).toBeUndefined()
784 expect(bare?.pricing ?? null).toBeNull()
785 },
786 )
787 })
788
789 it('maps a dashscope chat row to a card and leaves a zero quote null', async () => {
790 const priced = await dashscopeListedModel({
791 model: 'qwen3-max',
792 name: 'Qwen3-Max',
793 capabilities: ['TG'],
794 features: ['function-calling'],
795 inference_metadata: {
796 request_modality: ['Text'],
797 response_modality: ['Text'],
798 },
799 prices: [
800 {
801 range_name: 'Default',
802 prices: [
803 {
804 type: 'input_token',
805 price: '2',
806 price_unit: 'per million tokens',
807 },
808 {
809 type: 'output_token',
810 price: '6',
811 price_unit: 'per million tokens',
812 },
813 ],
814 },
815 ],
816 })
817 const free = await dashscopeListedModel({
818 model: 'decision-model-preview',
819 capabilities: ['TG'],
820 inference_metadata: {
821 request_modality: ['Text'],
822 response_modality: ['Text'],
823 },
824 prices: [
825 {
826 range_name: 'Default',
827 prices: [
828 { type: 'input_token', price: '0', price_unit: 'Per 1M tokens' },
829 ],
830 },
831 ],
832 })
833 expect(priced?.activity).toBe('chat')
834 expect(priced?.modalities).toEqual({ input: ['text'], output: ['text'] })
835 expect(priced?.capabilities).toEqual(['tools'])
836 expect(inputUsd(priced?.pricing)).toBeCloseTo(2, 9)
837 expect(free?.activity).toBe('chat')
838 expect(free?.pricing ?? null).toBeNull()
839 })
840
841 it('binds schema ids that the generated OpenAI-compat spec actually stores', () => {
842 expect(
843 hyperbolic.generationEndpointId?.({ rawId: 'x', activity: 'chat' }),
844 ).toBe('chat/completions')
845 expect(
846 sambanova.generationEndpointId?.({ rawId: 'x', activity: 'chat' }),
847 ).toBe('chat/completions')
848 expect(
849 novita.generationEndpointId?.({ rawId: 'x', activity: 'chat' }),
850 ).toBe('chat/completions')
851 expect(
852 novita.generationEndpointId?.({ rawId: 'x', activity: 'image' }),
853 ).toBe('images/generations')
854 expect(
855 novita.generationEndpointId?.({ rawId: 'x', activity: 'video' }),
856 ).toBeNull()
857 expect(
858 novita.generationEndpointId?.({ rawId: 'x', activity: 'audio' }),
859 ).toBeNull()
860 expect(
861 novita.generationEndpointId?.({ rawId: 'x', activity: 'embeddings' }),
862 ).toBeNull()
863 })
864})