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-20).
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 the off-peak rate and drops a model the table does not name', () => {
124 const parsed = parseDeepseekPricing(DEEPSEEK_HTML)
125 expect(parsed.get('deepseek-flash')).toEqual({
126 cacheRead: 0.003,
127 input: 0.15,
128 output: 0.6,
129 })
130 expect(parsed.get('deepseek-v4-pro')?.input).toBe(0.66)
131 expect(parsed.has('deepseek-chat')).toBe(false)
132 })
133})
134
135describe('fireworks pricing page', () => {
136 it('maps standard cells, skips US and size bands, and splits fast routers', () => {
137 const parsed = parseFireworksPricing(FIREWORKS_MD)
138 expect(parsed.get('accounts/fireworks/models/deepseek-v4p1-flash')).toEqual(
139 { input: 0.3, cacheRead: 0.006, output: 1.2 },
140 )
141 expect(parsed.get('accounts/fireworks/routers/kimi-k3-fast')?.input).toBe(
142 4.5,
143 )
144 expect(parsed.size).toBe(2)
145 })
146})
147
148describe('moonshot pricing page', () => {
149 it('reads K2 cache columns and K3 cache-write columns', () => {
150 const parsed = parseMoonshotPricing(parseKimiDocTables(MOONSHOT_PAGE))
151 expect(parsed.get('kimi-k2.6')).toEqual({
152 cacheRead: 0.16,
153 input: 0.95,
154 output: 4,
155 })
156 expect(parsed.get('kimi-k3')).toEqual({
157 cacheWrite: 3,
158 cacheWrite1h: 6,
159 cacheRead: 0.3,
160 input: 3,
161 output: 15,
162 })
163 })
164
165 it('leaves a row unpriced when a price cell is not plain text', () => {
166 // Struck cache-hit and cache-miss cells must not shift the K3 output
167 // and cache writes into the input levers.
168 const struck = (amount: string) =>
169 `_jsx(_components.del,{children:\`$${amount}\`})`
170 const page = MOONSHOT_PAGE.replace(
171 '_jsxs(_Fragment,{children:[`$`,`0.30`]}),_jsxs(_Fragment,{children:[`$`,`3.00`]}),_jsxs(_Fragment,{children:[`$`,`15.00`]})',
172 () =>
173 `${struck('0.30')},${struck('3.00')},_jsxs(_Fragment,{children:[\`$\`,\`15.00\`]})`,
174 )
175 expect(page).not.toBe(MOONSHOT_PAGE)
176 const parsed = parseMoonshotPricing(parseKimiDocTables(page))
177 expect(parsed.has('kimi-k3')).toBe(false)
178 expect(parsed.has('kimi-k2.6')).toBe(true)
179 })
180})
181
182describe('cerebras model pages', () => {
183 it('reads the catalog link and the ModelInfo price', () => {
184 expect(cerebrasCatalogRows(CEREBRAS_CATALOG)).toEqual([
185 { slug: 'openai-oss', id: 'gpt-oss-120b' },
186 ])
187 const facts = parseCerebrasModelPage(CEREBRAS_PAGE)
188 expect(facts?.inputPerMillion).toBe(0.35)
189 expect(facts?.outputPerMillion).toBe(0.75)
190 expect(facts?.modalities).toEqual({ input: ['text'], output: ['text'] })
191 expect(facts?.capabilities).toEqual(['reasoning', 'tools'])
192 expect(facts?.maxOutput).toBe(40_000)
193 expect(facts?.contextWindow).toBe(131_000)
194 })
195
196 it('reads the compiled ModelInfo props from the HTML page', () => {
197 expect(parseCerebrasModelPage(CEREBRAS_HTML)).toEqual({
198 inputPerMillion: 0.99,
199 outputPerMillion: 1.49,
200 modalities: { input: ['text', 'image'], output: ['text'] },
201 capabilities: ['reasoning', 'tools'],
202 contextWindow: 131_072,
203 maxOutput: 40_960,
204 })
205 })
206
207 it('reads the compiled copy with pricing when an unpriced copy comes first', () => {
208 const unpriced =
209 '_jsx(ModelInfo,{modelId:`gpt-oss-120b`,features:[`Reasoning`]})'
210 expect(
211 parseCerebrasModelPage(`${unpriced}${CEREBRAS_OSS_HTML}`),
212 ).toMatchObject({ inputPerMillion: 0.35, maxOutput: 40_000 })
213 })
214
215 it('throws when two priced compiled copies disagree', () => {
216 const other = CEREBRAS_OSS_HTML.replace('$0.35', '$0.40')
217 expect(() =>
218 parseCerebrasModelPage(`${CEREBRAS_OSS_HTML}${other}`),
219 ).toThrow('ModelInfo copies disagree')
220 })
221
222 it('keeps the context sentence out of the max output sentence', () => {
223 const facts = parseCerebrasModelPage(
224 `\`. 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}`,
225 )
226 expect(facts?.contextWindow).toBe(131_000)
227 expect(facts?.maxOutput).toBe(40_960)
228 })
229
230 it('prefers the paid parenthetical context window over 128k', () => {
231 const facts = parseCerebrasModelPage(`
232Context window: 64K tokens (65,536) for Free Trial and 128K tokens (131,072) for paid tiers and trial customers.
233<ModelInfo
234 contextLength={{
235 paidTiers: "128k tokens"
236 }}
237/>
238`)
239 expect(facts?.contextWindow).toBe(131_072)
240 })
241
242 it('prefers the paid parenthetical output cap over 40k', () => {
243 const facts = parseCerebrasModelPage(`
244Maximum output: 32K tokens (32,768) for Free Trial and 40K tokens (40,960) for paid tiers.
245<ModelInfo
246 maxOutput={{
247 freeTier: "32k tokens",
248 paidTiers: "40k tokens"
249 }}
250/>
251`)
252 expect(facts?.maxOutput).toBe(40_960)
253 })
254})
255
256describe('issue #109 listModels', () => {
257 it('sets deepseek activity and an off-peak card, and leaves an unpriced id null', async () => {
258 await withFetch(
259 (url) => {
260 if (url.includes('api.deepseek.com/models')) {
261 return json({
262 data: [
263 {
264 id: 'deepseek-flash',
265 output_modalities: ['text'],
266 input_modalities: ['text', 'image'],
267 effort: { supported_levels: ['high'] },
268 },
269 { id: 'deepseek-other' },
270 ],
271 })
272 }
273 if (url.includes('quick_start/pricing')) {
274 return new Response(DEEPSEEK_HTML, { status: 200 })
275 }
276 if (url === DEEPSEEK_THINKING_URL)
277 return new Response(DEEPSEEK_REPLAY_FIXTURE)
278 return new Response('missing', { status: 404 })
279 },
280 async () => {
281 const { models } = await deepseek.listModels({
282 DEEPSEEK_API_KEY: 'test',
283 })
284 const flash = models.find((model) => model.rawId === 'deepseek-flash')
285 const other = models.find((model) => model.rawId === 'deepseek-other')
286 expect(flash?.activity).toBe('chat')
287 expect(flash?.modalities).toEqual({
288 input: ['text', 'image'],
289 output: ['text'],
290 })
291 expect(flash?.pricing).toBeTruthy()
292 expect(inputUsd(flash?.pricing)).toBeCloseTo(0.15, 9)
293 expect(other?.activity).toBeNull()
294 expect(other?.pricing ?? null).toBeNull()
295 },
296 )
297 })
298
299 it('prices a cerebras chat row from its model page and leaves an unlisted id null', async () => {
300 await withFetch(
301 (url) => {
302 if (url.includes('api.cerebras.ai')) {
303 return json({
304 data: [{ id: 'gpt-oss-120b' }, { id: 'not-on-the-page' }],
305 })
306 }
307 if (url.endsWith('/models/overview.md')) {
308 return new Response(CEREBRAS_CATALOG, { status: 200 })
309 }
310 if (url.endsWith('/models/openai-oss')) {
311 return new Response(CEREBRAS_OSS_HTML, { status: 200 })
312 }
313 if (url.endsWith('/capabilities/reasoning.md')) {
314 return new Response(
315 `
316| Model | Default | \`reasoning_effort\` | Disable reasoning | Availability |
317| - | - | - | - | - |
318| [\`gpt-oss-120b\`](/models/openai-oss) | \`medium\` | \`low\`, \`medium\`, \`high\` | Not supported | Shared Inference |
319| \`kimi-k2.7-code\` | Always enabled | Accepted but ignored | Not supported | Customer trials only |
320`,
321 { status: 200 },
322 )
323 }
324 if (url.endsWith('/openapi.yaml')) {
325 return new Response(
326 `
327 max_completion_tokens:
328 type: integer
329 description: The maximum number of tokens that can be generated.
330 max_tokens:
331 type: integer
332 description: >
333 An alias for \`max_completion_tokens\`. Do not send both parameters
334 in the same request.
335 Developer messages are supported only by \`gpt-oss-120b\`.
336`,
337 { status: 200 },
338 )
339 }
340 return new Response('missing', { status: 404 })
341 },
342 async () => {
343 const { models } = await cerebras.listModels({
344 CEREBRAS_API_KEY: 'test',
345 })
346 const priced = models.find((model) => model.rawId === 'gpt-oss-120b')
347 const bare = models.find((model) => model.rawId === 'not-on-the-page')
348 expect(priced?.activity).toBe('chat')
349 expect(priced?.modalities).toEqual({
350 input: ['text'],
351 output: ['text'],
352 })
353 expect(inputUsd(priced?.pricing)).toBeCloseTo(0.35, 9)
354 expect(priced?.maxOutput).toBe(40_000)
355 expect(priced?.contextWindow).toBe(131_000)
356 expect(priced?.reasoning).toEqual({
357 mode: 'effort',
358 mandatory: true,
359 efforts: ['low', 'medium', 'high'],
360 })
361 expect(priced?.requestMap).toMatchObject({
362 maxTokensField: 'max_completion_tokens',
363 developerRole: true,
364 reasoningEffort: true,
365 thinking: {
366 on: { reasoning_effort: 'high' },
367 off: null,
368 },
369 })
370 expect(priced?.factSources?.maxOutput?.sourceUrl).toBe(
371 'https://inference-docs.cerebras.ai/models/openai-oss',
372 )
373 expect(priced?.factSources?.reasoning?.sourceUrl).toBe(
374 'https://inference-docs.cerebras.ai/capabilities/reasoning.md',
375 )
376 expect(bare?.activity).toBe('chat')
377 expect(bare?.pricing ?? null).toBeNull()
378 expect(bare?.maxOutput ?? null).toBeNull()
379 expect(bare?.reasoning ?? null).toBeNull()
380 expect(bare?.requestMap?.developerRole).toBe(false)
381 expect(bare?.requestMap?.maxTokensField).toBe('max_completion_tokens')
382 },
383 )
384 })
385
386 it('prices moonshot from the docs table and keeps a zero quote null', async () => {
387 await withFetch(
388 (url) => {
389 if (url.includes('api.moonshot.ai')) {
390 return json({
391 data: [
392 {
393 id: 'kimi-k2.6',
394 supports_image_in: true,
395 supports_video_in: false,
396 supports_reasoning: true,
397 context_length: 262144,
398 },
399 { id: 'kimi-free' },
400 ],
401 })
402 }
403 if (url.includes('pricing/chat')) {
404 return new Response(MOONSHOT_PAGE, { status: 200 })
405 }
406 if (url === KIMI_THINKING_URL) return new Response(KIMI_REPLAY_FIXTURE)
407 return new Response('missing', { status: 404 })
408 },
409 async () => {
410 const { models } = await moonshot.listModels({
411 MOONSHOT_API_KEY: 'test',
412 })
413 const kimi = models.find((model) => model.rawId === 'kimi-k2.6')
414 const free = models.find((model) => model.rawId === 'kimi-free')
415 expect(kimi?.activity).toBe('chat')
416 expect(kimi?.modalities).toEqual({
417 input: ['text', 'image'],
418 output: ['text'],
419 })
420 expect(kimi?.capabilities).toEqual(['reasoning'])
421 expect(inputUsd(kimi?.pricing)).toBeCloseTo(0.95, 9)
422 expect(free?.activity).toBe('chat')
423 expect(free?.pricing ?? null).toBeNull()
424 },
425 )
426 })
427
428 it('prices a fireworks chat row and leaves a reranker and a missing price null', async () => {
429 await withFetch(
430 (url) => {
431 // This pricing-only synthetic case states no reasoning evidence.
432 // Distinguish model metadata from the inference listing response.
433 for (const id of ['deepseek-v4p1-flash', 'unpriced']) {
434 const name = 'accounts/fireworks/models/' + id
435 if (url === 'https://api.fireworks.ai/v1/' + name)
436 return json({ name, description: '' })
437 }
438 if (url.includes('api.fireworks.ai')) {
439 return json({
440 data: [
441 {
442 id: 'accounts/fireworks/models/deepseek-v4p1-flash',
443 kind: 'HF_BASE_MODEL',
444 supports_chat: true,
445 supports_image_input: true,
446 supports_tools: true,
447 },
448 {
449 id: 'accounts/fireworks/models/qwen3-reranker-8b',
450 kind: 'HF_BASE_MODEL',
451 supports_chat: true,
452 },
453 {
454 id: 'accounts/fireworks/models/unpriced',
455 kind: 'HF_BASE_MODEL',
456 supports_chat: true,
457 supports_image_input: false,
458 },
459 ],
460 })
461 }
462 if (url.includes('serverless/pricing.md')) {
463 return new Response(FIREWORKS_MD, { status: 200 })
464 }
465 return new Response('missing', { status: 404 })
466 },
467 async () => {
468 const { models } = await fireworks.listModels({
469 FIREWORKS_API_KEY: 'test',
470 })
471 const chat = models.find((model) => model.rawId.includes('deepseek'))
472 const rerank = models.find((model) => model.rawId.includes('reranker'))
473 const bare = models.find((model) => model.rawId.includes('unpriced'))
474 expect(chat?.activity).toBe('chat')
475 expect(chat?.modalities).toEqual({
476 input: ['text', 'image'],
477 output: ['text'],
478 })
479 expect(chat?.capabilities).toEqual(['tools'])
480 expect(inputUsd(chat?.pricing)).toBeCloseTo(0.3, 9)
481 expect(rerank?.activity).toBeNull()
482 expect(rerank?.pricing ?? null).toBeNull()
483 expect(bare?.activity).toBe('chat')
484 expect(bare?.pricing ?? null).toBeNull()
485 },
486 )
487 })
488
489 it('compiles a novita decimal and leaves a tiered row null', async () => {
490 await withFetch(
491 () =>
492 json({
493 data: [
494 {
495 id: 'zai-org/glm',
496 model_type: 'chat',
497 input_modalities: ['text'],
498 output_modalities: ['text'],
499 features: ['function-calling'],
500 pricing: {
501 prompt: { price_per_m_decimal: '0.15' },
502 completion: { price_per_m_decimal: '0.5' },
503 },
504 },
505 {
506 id: 'tiered',
507 model_type: 'chat',
508 is_tiered_billing: true,
509 pricing: {
510 prompt: { price_per_m_decimal: '1' },
511 completion: { price_per_m_decimal: '2' },
512 },
513 },
514 ],
515 }),
516 async () => {
517 const { models } = await novita.listModels({ NOVITA_API_KEY: 'test' })
518 const chat = models.find((model) => model.rawId === 'zai-org/glm')
519 const tiered = models.find((model) => model.rawId === 'tiered')
520 expect(chat?.activity).toBe('chat')
521 expect(chat?.capabilities).toContain('tools')
522 expect(inputUsd(chat?.pricing)).toBeCloseTo(0.15, 9)
523 expect(tiered?.activity).toBe('chat')
524 expect(tiered?.pricing ?? null).toBeNull()
525 },
526 )
527 })
528
529 it('compiles perplexity per-million quotes and rejects an untagged unit', async () => {
530 await withFetch(
531 (url) =>
532 url.endsWith('/models.md')
533 ? new Response('<Tab title="x">\n| `perplexity/sonar` | — |\n</Tab>')
534 : url.endsWith('/presets.md')
535 ? new Response(
536 '<Accordion title="x — current preset values">\n* **Model:** `a/b`\n* **Tools:** `web_search`\n</Accordion>',
537 )
538 : json({
539 data: [
540 {
541 id: 'perplexity/sonar',
542 pricing: { input: 1, output: 1, unit: 'usd_per_1m_tokens' },
543 },
544 {
545 id: 'mystery',
546 pricing: { input: 1, output: 1, unit: 'credits' },
547 },
548 ],
549 }),
550 async () => {
551 const { models } = await perplexity.listModels({
552 PERPLEXITY_API_KEY: 'test',
553 })
554 const sonar = models.find((model) => model.rawId === 'perplexity/sonar')
555 const mystery = models.find((model) => model.rawId === 'mystery')
556 expect(sonar?.activity).toBe('chat')
557 expect(inputUsd(sonar?.pricing)).toBeCloseTo(1, 9)
558 expect(
559 perplexity.generationEndpointId?.({
560 rawId: 'perplexity/sonar',
561 activity: 'chat',
562 }),
563 ).toBe('v1/agent')
564 expect(mystery?.pricing ?? null).toBeNull()
565 },
566 )
567 })
568
569 it('sets jina activity from output modalities and skips an all-zero price', async () => {
570 const chatSpec = {
571 openapi: '3.1.0',
572 components: {
573 schemas: {
574 ChatCompletionRequest: {
575 type: 'object',
576 properties: {
577 messages: {
578 type: 'array',
579 items: { $ref: '#/components/schemas/ChatMessage' },
580 },
581 model: { type: 'string', const: 'jina-ocr-v1' },
582 max_completion_tokens: { type: 'integer', minimum: 1 },
583 },
584 required: ['messages', 'model'],
585 },
586 ChatMessage: {
587 type: 'object',
588 properties: {
589 role: {
590 type: 'string',
591 enum: ['system', 'developer', 'user', 'assistant'],
592 },
593 },
594 },
595 },
596 },
597 }
598 await withFetch(
599 (url) =>
600 url.endsWith('/openapi.json')
601 ? json(chatSpec)
602 : json({
603 data: [
604 {
605 id: 'jina-embeddings-v3',
606 output_modalities: ['embeddings'],
607 input_modalities: ['text'],
608 pricing: { prompt: '0.00000005', completion: '0' },
609 },
610 {
611 id: 'jina-reranker-v3',
612 output_modalities: ['text'],
613 input_modalities: ['text'],
614 pricing: { prompt: '0', completion: '0' },
615 },
616 ],
617 }),
618 async () => {
619 const { models } = await jina.listModels({ JINA_API_KEY: 'test' })
620 const embed = models.find((model) => model.rawId.includes('embeddings'))
621 const rerank = models.find((model) => model.rawId.includes('reranker'))
622 expect(embed?.activity).toBe('embeddings')
623 expect(inputUsd(embed?.pricing)).toBeCloseTo(0.05, 9)
624 expect(rerank?.activity).toBeNull()
625 expect(rerank?.pricing ?? null).toBeNull()
626 },
627 )
628 })
629
630 it('prices sambanova per token and leaves a zero quote null', async () => {
631 await withFetch(
632 () =>
633 json({
634 data: [
635 {
636 id: 'DeepSeek-V3.2',
637 context_length: 32768,
638 pricing: { prompt: '0.00000300', completion: '0.00000450' },
639 },
640 {
641 id: 'free',
642 pricing: { prompt: '0', completion: '0' },
643 },
644 ],
645 }),
646 async () => {
647 const { models } = await sambanova.listModels({
648 SAMBANOVA_API_KEY: 'test',
649 })
650 const chat = models.find((model) => model.rawId === 'DeepSeek-V3.2')
651 const free = models.find((model) => model.rawId === 'free')
652 expect(chat?.activity).toBe('chat')
653 expect(chat?.contextWindow).toBe(32768)
654 expect(inputUsd(chat?.pricing)).toBeCloseTo(3, 9)
655 expect(free?.pricing ?? null).toBeNull()
656 },
657 )
658 })
659
660 it('prices hyperbolic per million tokens from the listing', async () => {
661 await withFetch(
662 () =>
663 json({
664 data: [
665 {
666 id: 'deepseek-ai/DeepSeek-R1',
667 supports_chat: true,
668 supports_image_input: false,
669 supports_tools: false,
670 input_price: 2,
671 output_price: 2,
672 },
673 {
674 id: 'no-price',
675 supports_chat: true,
676 supports_image_input: false,
677 },
678 ],
679 }),
680 async () => {
681 const { models } = await hyperbolic.listModels({
682 HYPERBOLIC_API_KEY: 'test',
683 })
684 const chat = models.find((model) => model.rawId.includes('DeepSeek'))
685 const bare = models.find((model) => model.rawId === 'no-price')
686 expect(chat?.activity).toBe('chat')
687 expect(chat?.modalities).toEqual({
688 input: ['text'],
689 output: ['text'],
690 })
691 expect(chat?.capabilities).toEqual([])
692 expect(chat?.exactCapabilities).toBe(true)
693 expect(inputUsd(chat?.pricing)).toBeCloseTo(2, 9)
694 expect(bare?.activity).toBe('chat')
695 expect(bare?.capabilities).toBeUndefined()
696 expect(bare?.pricing ?? null).toBeNull()
697 },
698 )
699 })
700
701 it('maps a dashscope chat row to a card and leaves a zero quote null', async () => {
702 const priced = await dashscopeListedModel({
703 model: 'qwen3-max',
704 name: 'Qwen3-Max',
705 capabilities: ['TG'],
706 features: ['function-calling'],
707 inference_metadata: {
708 request_modality: ['Text'],
709 response_modality: ['Text'],
710 },
711 prices: [
712 {
713 range_name: 'Default',
714 prices: [
715 {
716 type: 'input_token',
717 price: '2',
718 price_unit: 'per million tokens',
719 },
720 {
721 type: 'output_token',
722 price: '6',
723 price_unit: 'per million tokens',
724 },
725 ],
726 },
727 ],
728 })
729 const free = await dashscopeListedModel({
730 model: 'decision-model-preview',
731 capabilities: ['TG'],
732 inference_metadata: {
733 request_modality: ['Text'],
734 response_modality: ['Text'],
735 },
736 prices: [
737 {
738 range_name: 'Default',
739 prices: [
740 { type: 'input_token', price: '0', price_unit: 'Per 1M tokens' },
741 ],
742 },
743 ],
744 })
745 expect(priced?.activity).toBe('chat')
746 expect(priced?.modalities).toEqual({ input: ['text'], output: ['text'] })
747 expect(priced?.capabilities).toEqual(['tools'])
748 expect(inputUsd(priced?.pricing)).toBeCloseTo(2, 9)
749 expect(free?.activity).toBe('chat')
750 expect(free?.pricing ?? null).toBeNull()
751 })
752
753 it('binds schema ids that the generated OpenAI-compat spec actually stores', () => {
754 expect(
755 hyperbolic.generationEndpointId?.({ rawId: 'x', activity: 'chat' }),
756 ).toBe('chat/completions')
757 expect(
758 sambanova.generationEndpointId?.({ rawId: 'x', activity: 'chat' }),
759 ).toBe('chat/completions')
760 expect(
761 novita.generationEndpointId?.({ rawId: 'x', activity: 'chat' }),
762 ).toBe('chat/completions')
763 expect(
764 novita.generationEndpointId?.({ rawId: 'x', activity: 'image' }),
765 ).toBe('images/generations')
766 expect(
767 novita.generationEndpointId?.({ rawId: 'x', activity: 'video' }),
768 ).toBeNull()
769 expect(
770 novita.generationEndpointId?.({ rawId: 'x', activity: 'audio' }),
771 ).toBeNull()
772 expect(
773 novita.generationEndpointId?.({ rawId: 'x', activity: 'embeddings' }),
774 ).toBeNull()
775 })
776})