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

model-facts.test.ts

1,336 lines41.7 KB

1import { describe, expect, it, vi } from 'vitest'
2​
3import { anthropicCapabilities } from './anthropic.ts'
4import { parseAnthropicPricing } from './anthropic-pricing.ts'
5import { ANTHROPIC_PRICING_PAGE } from './fixtures/anthropic-pricing.ts'
6import { geminiModelPricing, parseGeminiPricing } from './gemini-pricing.ts'
7import { geminiCapabilities } from './gemini.ts'
8import {
9 grokImageCard,
10 grokRateCard,
11 grokVideoCard,
12 parseGrokContextWindows,
13 parseGrokMaxOutput,
14 grokReasons,
15 parseGrokVideoPrices,
16 withGrokImageQuality,
17} from './grok.ts'
18import {
19 llmsFullPage,
20 markdownTableRows,
21 tokenCount,
22 undatedId,
23} from './model-facts.ts'
24import { price } from '@modelschemas/rate-card'
25import { openAiCompatModelFacts } from './openai-compat.ts'
26import {
27 pageSlugFor,
28 parseModelIndex,
29 parseModelPage,
30 parseModelPricing,
31 parseOpenAiSearchPricing,
32 parseReasoningEffort,
33} from './openai-model-docs.ts'
34​
35describe('model-facts helpers', () => {
36 it('parses token counts with separators and k/M suffixes', () => {
37 expect(tokenCount('1,048,576')).toBe(1_048_576)
38 expect(tokenCount('500k')).toBe(500_000)
39 expect(tokenCount('1M')).toBe(1_000_000)
40 })
41​
42 it('strips snapshot dates', () => {
43 expect(undatedId('gpt-5-2025-08-07')).toBe('gpt-5')
44 expect(undatedId('claude-opus-4-5-20251101')).toBe('claude-opus-4-5')
45 expect(undatedId('grok-4.20-0309-reasoning')).toBe(
46 'grok-4.20-0309-reasoning',
47 )
48 })
49​
50 it('splits markdown table rows and drops separators', () => {
51 expect(
52 markdownTableRows('| a | b |\n| --- | ---: |\n| 1 | 2 |\ntext'),
53 ).toEqual([
54 ['a', 'b'],
55 ['1', '2'],
56 ])
57 })
58​
59 it('cuts one page out of llms-full.txt by its Source line', () => {
60 const full = [
61 '# A',
62 'Source: https://docs.example/a',
63 'a body',
64 '# B',
65 'Source: https://docs.example/b',
66 '# not a page: no Source line follows',
67 'b body',
68 '# C',
69 'Source: https://docs.example/c',
70 'c body',
71 ].join('\n')
72 expect(llmsFullPage(full, 'https://docs.example/b')).toBe(
73 [
74 '# B',
75 'Source: https://docs.example/b',
76 '# not a page: no Source line follows',
77 'b body',
78 ].join('\n'),
79 )
80 expect(llmsFullPage(full, 'https://docs.example/c')).toBe(
81 '# C\nSource: https://docs.example/c\nc body',
82 )
83 expect(() => llmsFullPage(full, 'https://docs.example/d')).toThrow(
84 'llms-full.txt names https://docs.example/d 0 times, not once',
85 )
86 expect(() =>
87 llmsFullPage(`${full}\n${full}`, 'https://docs.example/a'),
88 ).toThrow('2 times')
89 })
90})
91​
92describe('anthropic models api', () => {
93 it('derives request features only from the capability tree', () => {
94 expect(
95 anthropicCapabilities({
96 id: 'claude-fable-5-1',
97 capabilities: {
98 thinking: { supported: true },
99 effort: { supported: true },
100 structured_outputs: { supported: true },
101 },
102 }),
103 ).toEqual([
104 'reasoning',
105 'reasoning_effort',
106 'structured_outputs',
107 'response_format',
108 ])
109 expect(
110 anthropicCapabilities({ id: 'claude-x', capabilities: {} }),
111 ).toBeNull()
112 })
113})
114​
115describe('gemini models api', () => {
116 it('derives request features only from row fields', () => {
117 expect(
118 geminiCapabilities({ thinking: true, temperature: 1, topP: 0.95 }),
119 ).toEqual(['reasoning', 'temperature', 'top_p'])
120 expect(geminiCapabilities({})).toBeNull()
121 })
122})
123​
124describe('xai model docs', () => {
125 it('reads context windows and ignores the per-image table', () => {
126 const md = `
127| Model | Context | Input / 1M tokens | Cached input / 1M tokens | Output / 1M tokens |
128| --- | --- | --- | --- | --- |
129| grok-4.6 (< 200k prompt tokens) | 500k | $2.00 | $0.50 | $6.00 |
130| grok-4.6 (≥ 200k prompt tokens) | 500k | $4.00 | $1.00 | $12.00 |
131| grok-4.3 (< 200k prompt tokens) | 1M | $1.25 | $0.20 | $2.50 |
132​
133| Model | Cost |
134| --- | --- |
135| grok-imagine-image | $0.02 / image |
137 expect([...parseGrokContextWindows(md)]).toEqual([
138 ['grok-4.6', 500_000],
139 ['grok-4.3', 1_000_000],
140 ])
141 })
142})
143​
144describe('xai per-model docs', () => {
145 it('reads the Reasoning capability bullet', () => {
146 const page = (value: string) =>
147 `# Grok\n\n## Capabilities\n\n- **Function calling:** Yes\n- **Reasoning:** ${value}\n- **Reasoning efforts (supported):** \`low\`\n`
148 expect(grokReasons(page('Yes'))).toBe(true)
149 expect(grokReasons(page('No'))).toBe(false)
150 expect(grokReasons('# Grok\n\n## Capabilities\n')).toBe(false)
151 })
152})
153​
154describe('openai model docs', () => {
155 const page = `# GPT-5
156​
157Model ID: \`gpt-5\`
158​
159Reasoning.effort supports: minimal, low, medium, and high.
160​
161## Model details
162​
163- Default snapshot: \`gpt-5-2025-08-07\`
164- Input modalities: text, image
165- Output modalities: text
166- 400,000 context window
167- Maximum input tokens: 272,000
168- 128,000 max output tokens
169- Reasoning token support
170​
171## Supported features
172​
173- streaming
174- structured_outputs
175- function_calling
176​
177## Supported tools
178​
179- function_calling
180- web_search
181- hosted_shell
182- skills
183- computer_use
184​
185## Snapshots
186​
187- \`gpt-5-2025-08-07\`
188- \`gpt-5-2025-09-01\`
189​
190## Rate limits
192 it('parses details, features, snapshots', () => {
193 const parsed = parseModelPage(page)
194 expect(parsed?.ids).toEqual([
195 'gpt-5',
196 'gpt-5-2025-08-07',
197 'gpt-5-2025-09-01',
198 ])
199 expect(parsed?.pricedIds).toEqual(['gpt-5', 'gpt-5-2025-08-07'])
200 expect(parsed?.facts).toEqual({
201 contextWindow: 400_000,
202 maxOutput: 128_000,
203 modalities: { input: ['text', 'image'], output: ['text'] },
204 capabilities: [
205 'tools',
206 'reasoning',
207 'structured_outputs',
208 'response_format',
209 ],
210 reasoning: {
211 mode: 'effort',
212 mandatory: null,
213 efforts: ['minimal', 'low', 'medium', 'high'],
214 },
215 // Docs names map to Responses tool types; client-side ones drop.
216 serverTools: ['web_search', 'shell', 'computer'],
217 })
218 })
219​
220 it('adds file input when the page lists file_uploads', () => {
221 const withFiles = page.replace(
222 '- function_calling\n\n## Supported tools',
223 '- function_calling\n- file_uploads\n\n## Supported tools',
224 )
225 expect(parseModelPage(withFiles)?.facts.modalities).toEqual({
226 input: ['text', 'image', 'file'],
227 output: ['text'],
228 })
229 const noModalities = withFiles.replace(
230 /^- (In|Out)put modalities.*\n/gm,
231 '',
232 )
233 expect(parseModelPage(noModalities)?.facts.modalities).toBeNull()
234 })
235​
236 it('leaves serverTools null when the page names no tool ids', () => {
237 const bare = page.replace(
238 /## Supported tools[\s\S]*?## Snapshots/,
239 '## Snapshots',
240 )
241 expect(parseModelPage(bare)?.facts.serverTools).toBeNull()
242 })
243​
244 it('reads every effort phrasing; none makes reasoning optional', () => {
245 expect(
246 parseReasoningEffort(
247 'Reasoning.effort supports: none (default), low, medium, and high.',
248 ),
249 ).toEqual({
250 mode: 'effort',
251 mandatory: false,
252 efforts: ['none', 'low', 'medium', 'high'],
253 })
254 expect(
255 parseReasoningEffort(
256 'GPT-5.2 Pro supports reasoning.effort: medium, high, xhigh.',
257 ),
258 ).toEqual({
259 mode: 'effort',
260 mandatory: null,
261 efforts: ['medium', 'high', 'xhigh'],
262 })
263 expect(
264 parseReasoningEffort(
265 'GPT-5 Pro defaults to (and only supports) `reasoning.effort: high`.',
266 ),
267 ).toEqual({ mode: 'effort', mandatory: true, efforts: ['high'] })
268 expect(parseReasoningEffort('No effort prose.')).toBeNull()
269 })
270​
271 it('resolves listed ids to index slugs, dated snapshots via the alias', () => {
272 const slugs = parseModelIndex(
273 '- [GPT-5](/api/docs/models/gpt-5.md): x\n- [Whisper](/api/docs/models/whisper-1.md): y',
274 )
275 expect(pageSlugFor('gpt-5-2025-08-07', slugs)).toBe('gpt-5')
276 expect(pageSlugFor('whisper-1', slugs)).toBe('whisper-1')
277 expect(pageSlugFor('gpt-5-search-api', slugs)).toBeNull()
278 // The models index dropped Sora after the Videos API shutdown. The
279 // pages still publish per-second rates, so the slug is fetched anyway.
280 expect(pageSlugFor('sora-2', slugs)).toBe('sora-2')
281 expect(pageSlugFor('sora-2-pro', slugs)).toBe('sora-2-pro')
282 expect(pageSlugFor('sora-2-2025-10-06', slugs)).toBe('sora-2')
283 expect(pageSlugFor('sora-2-pro-2025-10-06', slugs)).toBe('sora-2-pro')
284 // Dated TTS snapshots have no page of their own and are not the
285 // family's default snapshot, so they do not inherit tts-1's price.
286 expect(pageSlugFor('tts-1-1106', slugs)).toBeNull()
287 expect(pageSlugFor('tts-1-hd-1106', slugs)).toBeNull()
288 })
289})
290​
291describe('openai-compatible model rows', () => {
292 it('maps the extension fields groq/jina/fireworks/moonshot/mistral publish', () => {
293 expect(
294 openAiCompatModelFacts({
295 id: 'openai/gpt-oss-120b',
296 context_window: 131072,
297 max_completion_tokens: 65536,
298 input_modalities: ['text'],
299 output_modalities: ['text'],
300 supported_sampling_parameters: ['temperature', 'top_p', 'stop'],
301 supported_features: [
302 'tools',
303 'json_mode',
304 'structured_outputs',
305 'reasoning',
306 ],
307 }),
308 ).toEqual({
309 contextWindow: 131072,
310 maxOutput: 65536,
311 modalities: { input: ['text'], output: ['text'] },
312 capabilities: [
313 'tools',
314 'reasoning',
315 'temperature',
316 'top_p',
317 'structured_outputs',
318 'response_format',
319 ],
320 })
321 expect(
322 openAiCompatModelFacts({
323 id: 'kimi-k2.6',
324 context_length: 262144,
325 supports_reasoning: true,
326 }),
327 ).toEqual({ contextWindow: 262144, capabilities: ['reasoning'] })
328 expect(
329 openAiCompatModelFacts({
330 id: 'mistral-large-latest',
331 max_context_length: 262144,
332 capabilities: {
333 function_calling: true,
334 vision: true,
335 reasoning: false,
336 },
337 }),
338 ).toEqual({ contextWindow: 262144, capabilities: ['tools'] })
339 expect(openAiCompatModelFacts({ id: 'x', max_output_length: 0 })).toEqual(
340 {},
341 )
342 })
343})
344​
345describe('openai-compatible model rows (novita / cohere vocab)', () => {
346 it('normalises hyphenated features and cohere feature names', () => {
347 expect(
348 openAiCompatModelFacts({
349 id: 'zai-org/glm-5.3-flash',
350 context_size: 1_048_576,
351 max_output_tokens: 131_072,
352 input_modalities: ['text', 'image', 'video'],
353 output_modalities: ['text'],
354 features: ['function-calling', 'structured-outputs', 'reasoning'],
355 }),
356 ).toEqual({
357 contextWindow: 1_048_576,
358 maxOutput: 131_072,
359 modalities: { input: ['text', 'image', 'video'], output: ['text'] },
360 capabilities: [
361 'tools',
362 'reasoning',
363 'structured_outputs',
364 'response_format',
365 ],
366 })
367 expect(
368 openAiCompatModelFacts({
369 id: 'command-a-03-2025',
370 context_length: 288_000,
371 features: ['json_mode', 'json_schema', 'tools', 'tool_choice'],
372 }),
373 ).toEqual({
374 contextWindow: 288_000,
375 capabilities: [
376 'tools',
377 'tool_choice',
378 'structured_outputs',
379 'response_format',
380 ],
381 })
382 })
383})
384​
385describe('openai pricing tables', () => {
386 const pricing = (body: string) =>
387 `# Model\n\nModel ID: \`m\`\n\n## Pricing\n\n${body}\n## Endpoints\n`
388​
389 it('reads every token lever off the per-million tables', () => {
390 expect(
391 parseModelPricing(
392 pricing(`### Text tokens
393​
394| Metric | Price | Unit |
395| --- | ---: | --- |
396| Input | $1.25 | 1M tokens |
397| Cached input | $0.125 | 1M tokens |
398| Output | $10 | 1M tokens |
399​
400### Audio tokens
401​
402| Metric | Price | Unit |
403| --- | ---: | --- |
404| Input | $32 | 1M tokens |
405| Output | $64 | 1M tokens |
406`),
407 ),
408 ).toEqual({
409 rates: {
410 input_tokens: 1.25e-6,
411 cache_read_tokens: 0.125e-6,
412 output_tokens: 10e-6,
413 audio_tokens: 32e-6,
414 audio_output_tokens: 64e-6,
415 },
416 tiers: [],
417 })
418 })
419​
420 it('uses the first Text tokens table when the heading is repeated', () => {
421 // o3.md publishes standard rates, then the same heading again at half
422 // price for batch/flex, with no label on the second table.
423 expect(
424 parseModelPricing(
425 pricing(`### Text tokens
426​
427| Metric | Price | Unit |
428| --- | ---: | --- |
429| Input | $2 | 1M tokens |
430| Cached input | $0.5 | 1M tokens |
431| Output | $8 | 1M tokens |
432​
433### Text tokens
434​
435| Metric | Price | Unit |
436| --- | ---: | --- |
437| Input | $1 | 1M tokens |
438| Cached input | $0.25 | 1M tokens |
439| Output | $4 | 1M tokens |
440`),
441 ),
442 ).toEqual({
443 rates: {
444 input_tokens: 0.000002,
445 cache_read_tokens: 5e-7,
446 output_tokens: 0.000008,
447 },
448 tiers: [],
449 })
450 })
451​
452 it('prices the alias and default snapshot, not an older dated snapshot', () => {
453 const parsed = parseModelPage(`# GPT-4o
454​
455Model ID: \`gpt-4o\`
456​
457## Model details
458​
459- Default snapshot: \`gpt-4o-2024-08-06\`
460​
461## Pricing
462​
463### Text tokens
464​
465| Metric | Price | Unit |
466| --- | ---: | --- |
467| Input | $2.50 | 1M tokens |
468| Cached input | $1.25 | 1M tokens |
469| Output | $10 | 1M tokens |
470​
471## Snapshots
472​
473- \`gpt-4o-2024-08-06\`
474- \`gpt-4o-2024-11-20\`
475- \`gpt-4o-2024-05-13\`
476`)
477 expect(parsed?.pricedIds).toEqual(['gpt-4o', 'gpt-4o-2024-08-06'])
478 expect(parsed?.ids).toContain('gpt-4o-2024-05-13')
479 expect(parsed?.pricing?.rates).toEqual({
480 input_tokens: 2.5e-6,
481 cache_read_tokens: 1.25e-6,
482 output_tokens: 10e-6,
483 })
484 })
485​
486 it('reads an embeddings page', () => {
487 expect(
488 parseModelPricing(
489 pricing(`### Embeddings
490​
491| Metric | Price | Unit |
492| --- | ---: | --- |
493| Cost | $0.02 | 1M tokens |
494`),
495 ),
496 ).toEqual({ rates: { input_tokens: 0.02e-6 }, tiers: [] })
497 })
498​
499 it('treats the per-image table as a restatement of the token price', () => {
500 // OpenAI bills image models per token; the per-image table is the
501 // equivalent cost of one image at a size and quality.
502 expect(
503 parseModelPricing(
504 pricing(`### Image tokens
505​
506| Metric | Price | Unit |
507| --- | ---: | --- |
508| Input | $10 | 1M tokens |
509| Output | $40 | 1M tokens |
510​
511### Image generation
512​
513| Metric | Price | Unit |
514| --- | ---: | --- |
515| Quality | Low | image |
516| 1024x1024 | $0.011 | image |
517`),
518 ),
519 ).toEqual({
520 rates: { image_tokens: 10e-6, image_output_tokens: 40e-6 },
521 tiers: [],
522 })
523 })
524​
525 it('refuses a section priced in a unit it has no lever for', () => {
526 expect(
527 parseModelPricing(
528 pricing(`### Pricing
529​
530| Metric | Price | Unit |
531| --- | ---: | --- |
532| Cost | $0.10 | GB-hour |
533`),
534 ),
535 ).toBeNull()
536 })
537​
538 it('reads the long-prompt re-quote and cache-write multiplier', () => {
539 const page = pricing(`### Text tokens
540​
541| Metric | Price | Unit |
542| --- | ---: | --- |
543| Input | $10 | 1M tokens |
544| Cached input | $1 | 1M tokens |
545| Output | $50 | 1M tokens |
546​
547- Prompts with more than 272K input tokens are priced at 2x input and cache rates and 1.5x output for the full request.
548- Cache writes are billed at 1.25x the uncached input token rate.
549- Batch and Flex are priced at 50% of Standard rates.
550`)
551 expect(parseModelPricing(page)).toEqual({
552 rates: {
553 input_tokens: 10e-6,
554 cache_read_tokens: 1e-6,
555 cache_write_tokens: 12.5e-6,
556 output_tokens: 50e-6,
557 },
558 tiers: [
559 {
560 minPromptTokens: 272_000,
561 rates: {
562 input_tokens: 20e-6,
563 cache_read_tokens: 2e-6,
564 cache_write_tokens: 25e-6,
565 output_tokens: (50 / 1e6) * 1.5,
566 },
567 },
568 ],
569 })
570 })
571​
572 it('stamps a promo end so the card is re-read after it', () => {
573 const page = pricing(`### Text tokens
574​
575| Metric | Price | Unit |
576| --- | ---: | --- |
577| Input | $4 | 1M tokens |
578| Output | $20 | 1M tokens |
579​
580- GPT-5.6 Sol costs $4 per million input tokens and $20 per million output tokens, a 20% reduction in input pricing. GPT-5.6 Sol’s promotional pricing is available at least through November 21, 2026.
581`)
582 expect(parseModelPricing(page)?.expiresAt).toBe('2026-11-22T00:00:00.000Z')
583 })
584​
585 it('prices a per-minute model by the duration the caller measures', () => {
586 expect(
587 parseModelPricing(
588 pricing(`### Transcription audio duration
589​
590| Metric | Price | Unit |
591| --- | ---: | --- |
592| Price | $0.0045 | minute |
593`),
594 ),
595 ).toEqual({
596 rates: {},
597 tiers: [],
598 unit: {
599 quantity: { param: 'audio_seconds', bound: 'usage' },
600 rates: 0.0045 / 60,
601 },
602 })
603 })
604​
605 it('prices sora-2 and sora-2-pro from their own video tables', () => {
606 expect(
607 parseModelPricing(
608 pricing(`### Video generation
609​
610| Metric | Price | Unit |
611| --- | ---: | --- |
612| Portrait: 720x1280
613Landscape: 1280x720 | $0.1 | second |
614`),
615 )?.unit,
616 ).toEqual({
617 quantity: { param: 'seconds', bound: 'request' },
618 keys: [{ param: 'size', values: ['720x1280', '1280x720'] }],
619 rates: { '720x1280': 0.1, '1280x720': 0.1 },
620 })
621 expect(
622 parseModelPricing(
623 pricing(`### Video generation
624​
625| Metric | Price | Unit |
626| --- | ---: | --- |
627| Portrait: 720x1280
628Landscape: 1280x720 | $0.3 | second |
629| Portrait: 1024x1792
630Landscape: 1792x1024 | $0.5 | second |
631| Portrait: 1080x1920
632Landscape: 1920x1080 | $0.7 | second |
633`),
634 )?.unit?.rates,
635 ).toEqual({
636 '720x1280': 0.3,
637 '1280x720': 0.3,
638 '1024x1792': 0.5,
639 '1792x1024': 0.5,
640 '1080x1920': 0.7,
641 '1920x1080': 0.7,
642 })
643 })
644​
645 it('leaves image-2, moderation, and dated TTS snapshots unpriced', () => {
646 const image = parseModelPage(`# GPT-Image-2
647​
648Model ID: \`gpt-image-2\`
649​
650GPT Image 2 points at the [pricing page](/api/docs/pricing#image-generation) but this page lists no amount.
651​
652## Model details
653​
654- Default snapshot: \`gpt-image-2-2026-04-21\`
655​
656## Snapshots
657​
658- \`gpt-image-2-2026-04-21\`
659`)
660 expect(image?.pricing).toBeNull()
661 expect(image?.pricedIds).toEqual(['gpt-image-2', 'gpt-image-2-2026-04-21'])
662​
663 const moderation = parseModelPage(`# omni-moderation
664​
665Model ID: \`omni-moderation-latest\`
666​
667Moderation models are free models designed to detect harmful content.
668​
669## Model details
670​
671- Default snapshot: \`omni-moderation-2024-09-26\`
672​
673## Snapshots
674​
675- \`omni-moderation-2024-09-26\`
676`)
677 expect(moderation?.pricing).toBeNull()
678​
679 const tts = parseModelPage(`# TTS-1
680​
681Model ID: \`tts-1\`
682​
683## Model details
684​
685- Default snapshot: \`tts-1\`
686​
687## Pricing
688​
689### Pricing
690​
691| Metric | Price | Unit |
692| --- | ---: | --- |
693| Use case | Speech generation | 1M tokens |
694| Cost | $15 | 1M characters |
695​
696## Snapshots
697​
698- \`tts-1\`
699`)
700 expect(tts?.pricedIds).toEqual(['tts-1'])
701 expect(tts?.ids).not.toContain('tts-1-1106')
702 expect(tts?.pricing?.unit?.rates).toBe(15 / 1e6)
703 })
704​
705 it('prices speech by character and video by size and second', () => {
706 expect(
707 parseModelPricing(
708 pricing(`### Pricing
709​
710| Metric | Price | Unit |
711| --- | ---: | --- |
712| Use case | Speech generation | 1M tokens |
713| Cost | $15 | 1M characters |
714`),
715 )?.unit,
716 ).toEqual({
717 quantity: { param: 'characters', bound: 'usage' },
718 rates: 15 / 1e6,
719 })
720 // A video row names both orientations of one size in its metric cell,
721 // and the cell's newline splits the row across two lines.
722 expect(
723 parseModelPricing(
724 pricing(`### Video generation
725​
726| Metric | Price | Unit |
727| --- | ---: | --- |
728| Portrait: 720x1280
729Landscape: 1280x720 | $0.3 | second |
730| Portrait: 1080x1920
731Landscape: 1920x1080 | $0.7 | second |
732`),
733 )?.unit,
734 ).toEqual({
735 quantity: { param: 'seconds', bound: 'request' },
736 keys: [
737 {
738 param: 'size',
739 values: ['720x1280', '1280x720', '1080x1920', '1920x1080'],
740 },
741 ],
742 rates: {
743 '720x1280': 0.3,
744 '1280x720': 0.3,
745 '1080x1920': 0.7,
746 '1920x1080': 0.7,
747 },
748 })
749 })
750​
751 it('refuses a page that mixes a token table with a per-unit one', () => {
752 expect(
753 parseModelPricing(
754 pricing(`### Text tokens
755​
756| Metric | Price | Unit |
757| --- | ---: | --- |
758| Input | $5 | 1M tokens |
759​
760### Live session duration
761​
762| Metric | Price | Unit |
763| --- | ---: | --- |
764| Per minute | $0.05 | minute |
765`),
766 ),
767 ).toBeNull()
768 })
769​
770 it('accepts a cached-input bullet that restates the table', () => {
771 const page = pricing(`### Text tokens
772​
773| Metric | Price | Unit |
774| --- | ---: | --- |
775| Input | $0.1 | 1M tokens |
776| Cached input | $0.01 | 1M tokens |
777| Cache writes | $0.125 | 1M tokens |
778| Output | $0.5 | 1M tokens |
779​
780- Cached input tokens are priced at 10% of the uncached input token rate.
781- Cache writes are billed at 1.25x the uncached input token rate.
782- Regional processing adds a 10% premium where available.
783`)
784 expect(parseModelPricing(page)?.rates).toEqual({
785 input_tokens: 0.1 / 1e6,
786 cache_read_tokens: 0.01 / 1e6,
787 cache_write_tokens: 0.125 / 1e6,
788 output_tokens: 0.5 / 1e6,
789 })
790 })
791​
792 it('refuses a cached-input bullet that disagrees with the table', () => {
793 const page = pricing(`### Text tokens
794​
795| Metric | Price | Unit |
796| --- | ---: | --- |
797| Input | $1 | 1M tokens |
798| Cached input | $0.5 | 1M tokens |
799| Output | $2 | 1M tokens |
800​
801- Cached input tokens are priced at 10% of the uncached input token rate.
802`)
803 expect(parseModelPricing(page)).toBeNull()
804 })
805​
806 it('refuses an unrecognised bullet that quotes a surcharge', () => {
807 const page = pricing(`### Text tokens
808​
809| Metric | Price | Unit |
810| --- | ---: | --- |
811| Input | $10 | 1M tokens |
812| Output | $50 | 1M tokens |
813​
814- Requests using the widget tool are charged a 3x multiplier.
815`)
816 expect(parseModelPricing(page)).toBeNull()
817 })
818​
819 it('refuses an unpriced row and a page with no pricing', () => {
820 expect(
821 parseModelPricing(
822 pricing(`### Text tokens
823​
824| Metric | Price | Unit |
825| --- | ---: | --- |
826| Input | Free | 1M tokens |
827`),
828 ),
829 ).toBeNull()
830 expect(parseModelPricing('# Model\n\nModel ID: `m`\n')).toBeNull()
831 })
832​
833 it('prices gpt-5-search-api from the specialized table and not a dated twin', () => {
834 const page = `Specialized models
835​
836Prices per 1M tokens.
837​
838Standard
839​
840### Grouped Pricing Table data
841​
842| Category | Model | Input | Cached input | Output |
843| --- | --- | --- | --- | --- |
844| Search | gpt-5-search-api | $1.25 | $0.125 | $10.00 |
845| Embedding | text-embedding-3-small | $0.02 | - | - |
846| Moderation | omni-moderation-latest | Free | - | - |
847​
848Fast
849​
850### Grouped Pricing Table data
851​
852| Category | Model | Input | Cached input | Output |
853| --- | --- | --- | --- | --- |
854| Search | gpt-5-search-api | $9.99 | $9.99 | $9.99 |
856 const rates = parseOpenAiSearchPricing(page)
857 expect(rates.get('gpt-5-search-api')).toEqual({
858 input_tokens: 1.25 / 1e6,
859 cache_read_tokens: 0.125 / 1e6,
860 output_tokens: 10 / 1e6,
861 })
862 expect(rates.has('text-embedding-3-small')).toBe(false)
863 expect(rates.has('omni-moderation-latest')).toBe(false)
864 expect(rates.has('gpt-5-search-api-2025-10-14')).toBe(false)
865 expect(rates.has('gpt-3.5-turbo-16k')).toBe(false)
866 })
867})
868​
869describe('anthropic pricing page', () => {
870 it('reads HTML-footnoted cache rates from the upstream table', () => {
871 const rows = parseAnthropicPricing(ANTHROPIC_PRICING_PAGE)
872 expect(rows.size).toBe(18)
873 expect(rows.get('claude opus 5.5')?.cache_read_tokens).toBeCloseTo(
874 0.2e-6,
875 15,
876 )
877 expect(rows.get('claude fable 5.1')?.cache_read_tokens).toBe(0.25e-6)
878 expect(rows.get('claude sonnet 5')?.input_tokens).toBe(2e-6)
879 expect(rows.get('claude sonnet 5')?.output_tokens).toBe(10e-6)
880 for (const [name, rates] of rows) {
881 if ('cache_write_tokens' in rates || 'cache_write_1h_tokens' in rates) {
882 expect(
883 rates.cache_read_tokens,
884 `${name} must price cache reads`,
885 ).toBeGreaterThan(0)
886 }
887 }
888 })
889​
890 const page = `# Pricing
891​
892## Model pricing
893​
894| Model | Base input tokens | 5m cache writes | 1h cache writes | Cache hits and refreshes | Output tokens |
895| --- | --- | --- | --- | --- | --- |
896| Claude Fable 5.1 | $10 / MTok | $12.50 / MTok | $20 / MTok | $0.25 / MTok1 | $50 / MTok |
897| Claude Opus 4 ([retired](https://example.com/deprecations)) | $15 / MTok | $18.75 / MTok | $30 / MTok | $1.50 / MTok | $75 / MTok |
898​
899## Batch pricing
900​
901| Model | Batch input | Batch output |
902| --- | --- | --- |
903| Claude Fable 5.1 | $5 / MTok | $25 / MTok |
905​
906 it('keys rows by display name and reads every lever column', () => {
907 const rows = parseAnthropicPricing(page)
908 expect(rows.get('claude fable 5.1')).toEqual({
909 input_tokens: 10e-6,
910 cache_write_tokens: 12.5e-6,
911 cache_write_1h_tokens: 20e-6,
912 cache_read_tokens: 0.25e-6,
913 output_tokens: 50e-6,
914 })
915 // The name cell's retirement link is not part of the key.
916 expect(rows.get('claude opus 4')?.input_tokens).toBe(15e-6)
917 // Batch rates live in another section and are not levers.
918 expect(rows.size).toBe(2)
919 })
920​
921 it('parses nothing when the section is gone', () => {
922 expect(parseAnthropicPricing('# Pricing\n\n## Something else\n').size).toBe(
923 0,
924 )
925 })
926})
927​
928describe('grok model prices', () => {
929 const model = {
930 id: 'grok-4.20-0309-reasoning',
931 prompt_text_token_price: 12_500,
932 cached_prompt_text_token_price: 2_000,
933 completion_text_token_price: 25_000,
934 prompt_text_token_price_long_context: 25_000,
935 cached_prompt_text_token_price_long_context: 4_000,
936 completion_text_token_price_long_context: 50_000,
937 long_context_threshold: 200_000,
938 }
939​
940 it('reads xAI’s 1e-10 USD units as per-token rates', async () => {
941 const card = await grokRateCard(model)
942 if (!card) throw new Error('did not compile')
943 expect(
944 price(card, {}, { input_tokens: 1e5, output_tokens: 0 }),
945 ).toBeCloseTo(0.125, 9)
946 expect(
947 price(card, {}, { input_tokens: 0, output_tokens: 1e5 }),
948 ).toBeCloseTo(0.25, 9)
949 })
950​
951 it('bills the long-context rate at the threshold, not above it', async () => {
952 const card = await grokRateCard(model)
953 if (!card) throw new Error('did not compile')
954 const perMillion = (tokens: number) =>
955 (price(card, {}, { input_tokens: tokens, output_tokens: 0 }) / tokens) *
956 1e6
957 expect(perMillion(199_999)).toBeCloseTo(1.25, 6)
958 expect(perMillion(200_000)).toBeCloseTo(2.5, 6)
959 })
960​
961 it('has no card for a model xAI does not price', async () => {
962 expect(await grokRateCard({ id: 'grok-imagine-video' })).toBeNull()
963 })
964​
965 it('prices images per image, by the (quality, resolution) matrix when there is one', async () => {
966 const card = await grokImageCard({
967 id: 'grok-imagine-image',
968 image_price: 200_000_000,
969 })
970 if (!card) throw new Error('did not compile')
971 expect(price(card, {}, {})).toBeCloseTo(0.02, 9)
972 expect(price(card, { n: 4 }, {})).toBeCloseTo(0.08, 9)
973 // Live 2026-10-04: grok-imagine-image-2.0 prices by quality and
974 // resolution. `quality` is a request field (the guide and xai-sdk-ts;
975 // the OpenAPI document omits it) and defaults to `auto`, which serves
976 // `low` for generation. The pricing page's $0.04 is the low/1k cell.
977 const matrix = await grokImageCard({
978 id: 'grok-imagine-image-2.0',
979 image_price: 600_000_000,
980 pricing: [
981 { quality: 'low', resolution: '1k', price_per_image: 4e8 },
982 { quality: 'low', resolution: '2k', price_per_image: 6e8 },
983 { quality: 'medium', resolution: '1k', price_per_image: 6e8 },
984 { quality: 'medium', resolution: '2k', price_per_image: 8e8 },
985 ],
986 })
987 if (!matrix) throw new Error('did not compile')
988 expect(price(matrix, {}, {})).toBeCloseTo(0.04, 9)
989 expect(price(matrix, { quality: 'auto' }, {})).toBeCloseTo(0.04, 9)
990 expect(
991 price(matrix, { quality: 'medium', resolution: '2k' }, {}),
992 ).toBeCloseTo(0.08, 9)
993 expect(
994 price(matrix, { quality: 'low', resolution: '2k', n: 2 }, {}),
995 ).toBeCloseTo(0.12, 9)
996 expect(matrix.inputs.quality).toMatchObject({
997 bound: 'request',
998 default: 'auto',
999 })
1000 // A dimension the request cannot state has no card, flat price or not.
1001 expect(
1002 await grokImageCard({
1003 id: 'grok-imagine-image',
1004 image_price: 200_000_000,
1005 pricing: [{ tier: 'pro', price_per_image: 7e8 }],
1006 }),
1007 ).toBeNull()
1008 })
1009​
1010 it('adds the documented quality field the OpenAPI document omits', () => {
1011 const spec = withGrokImageQuality({
1012 components: {
1013 schemas: {
1014 GenerateImageRequest: { properties: { prompt: { type: 'string' } } },
1015 EditImageRequest: { properties: { prompt: { type: 'string' } } },
1016 GenerateVideoRequest: { properties: { prompt: { type: 'string' } } },
1017 },
1018 },
1019 })
1020 const schemas = spec.components?.schemas as Record<
1021 string,
1022 { properties: Record<string, unknown> }
1024 expect(schemas.GenerateImageRequest?.properties.quality).toMatchObject({
1025 enum: ['low', 'medium', 'auto'],
1026 })
1027 expect(schemas.EditImageRequest?.properties.quality).toBeDefined()
1028 expect(schemas.GenerateVideoRequest?.properties.quality).toBeUndefined()
1029 })
1030​
1031 it('reads a stated output cap and ignores "no limit" and price rows', () => {
1032 const page = `# Grok 3
1033​
1034## At a glance
1035​
1036- **Context window:** 131,072 tokens
1037- **Output limit:** 8,192 tokens
1039 expect(parseGrokMaxOutput(page)).toBe(8_192)
1040 expect(
1041 parseGrokMaxOutput(
1042 '| Property | Value |\n| --- | --- |\n| Output limit | No text output limit |\n',
1043 ),
1044 ).toBeNull()
1045 expect(
1046 parseGrokMaxOutput(
1047 '| Type | Price |\n| --- | --- |\n| Output | $6.00 |\n',
1048 ),
1049 ).toBeNull()
1050 })
1051​
1052 it('prices video per second off the docs table', async () => {
1053 const rates = parseGrokVideoPrices(`### Imagine Pricing
1054​
1055| Model | Cost |
1056| --- | --- |
1057| grok-imagine-image | $0.02 / image |
1058| grok-imagine-video | $0.050 / sec |
1059| grok-imagine-video-1.5 | $0.080 / sec |
1061 expect([...rates]).toEqual([
1062 ['grok-imagine-video', 0.05],
1063 ['grok-imagine-video-1.5', 0.08],
1064 ])
1065 const card = await grokVideoCard(rates.get('grok-imagine-video'))
1066 if (!card) throw new Error('did not compile')
1067 expect(price(card, { duration: 6 }, {})).toBeCloseTo(0.3, 9)
1068 expect(await grokVideoCard(undefined)).toBeNull()
1069 })
1071​
1072describe('gemini pricing page', () => {
1073 const section = (
1074 id: string,
1075 rows: string,
1076 extraIds: Array<string> = [],
1077 ) => `<div class="models-section">
1078 <div class="heading-group"><h2 id="${id}">Name</h2>
1079 <em>${[id, ...extraIds]
1080 .map(
1081 (each) =>
1082 `<a href="/gemini-api/docs/models/${each}"><code translate="no" dir="ltr">${each}</code></a>`,
1084 .join('')}</em></div>
1085 </div>
1086 <div><devsite-selector><section><h3 id="standard" data-text="Standard">Standard</h3><table class="pricing-table">
1087 <thead><tr><th></th><th scope="col">Free Tier</th><th scope="col">Paid Tier, per 1M tokens in USD</th></tr></thead>
1088 <tbody>${rows}</tbody></table></section>
1089 <section><h3 id="batch" data-text="Batch">Batch</h3><table class="pricing-table"><tbody>
1090 <tr><td>Input price</td><td>Not available</td><td>$0.15</td></tr>
1091 </tbody></table></section></devsite-selector></div>`
1092​
1093 const NOW = Date.UTC(2026, 8, 16)
1094​
1095 it('reads text and audio rates off the Standard table', () => {
1096 const rows = parseGeminiPricing(
1097 section(
1098 'gemini-2.5-flash',
1099 `<tr><td>Input price</td><td>Free of charge</td><td>$0.30 (text / image / video)<br>$1.00 (audio)</td></tr>
1100 <tr><td>Output price (including thinking tokens)</td><td>Free of charge</td><td>$2.50</td></tr>
1101 <tr><td>Context caching price</td><td>Not available</td><td>$0.03 (text / image / video)<br>$0.1 (audio)<br>$1.00 / 1,000,000 tokens per hour (storage price)</td></tr>
1102 <tr><td>Grounding with Google Search</td><td>Free</td><td>1,500 RPD (free), then $35 / 1,000 grounded prompts</td></tr>`,
1103 ),
1104 NOW,
1106 expect(rows.get('gemini-2.5-flash')?.base).toEqual({
1107 input_tokens: 0.3e-6,
1108 audio_tokens: 1e-6,
1109 output_tokens: 2.5e-6,
1110 cache_read_tokens: 0.03e-6,
1111 audio_cache_tokens: 0.1 / 1e6,
1112 })
1113 // Batch is a separate tab, and cache storage is a per-hour rate.
1114 expect(rows.get('gemini-2.5-flash')?.tiers).toEqual([])
1115 })
1116​
1117 it('copies one Standard table onto every id the heading names', () => {
1118 const rows = parseGeminiPricing(
1119 section(
1120 'gemini-3.1-pro-preview',
1121 `<tr><td>Input price</td><td>Not available</td><td>$2.00</td></tr>
1122 <tr><td>Output price (including thinking tokens)</td><td>Not available</td><td>$12.00</td></tr>`,
1123 ['gemini-3.1-pro-preview-customtools'],
1124 ),
1125 NOW,
1127 expect(rows.get('gemini-3.1-pro-preview')?.base).toEqual({
1128 input_tokens: 2e-6,
1129 output_tokens: 12e-6,
1130 })
1131 expect(rows.get('gemini-3.1-pro-preview-customtools')?.base).toEqual(
1132 rows.get('gemini-3.1-pro-preview')?.base,
1134 })
1135​
1136 it('does not price models the heading does not name', () => {
1137 const rows = parseGeminiPricing(
1138 section(
1139 'gemini-2.5-flash',
1140 `<tr><td>Input price</td><td>Free of charge</td><td>$0.30</td></tr>
1141 <tr><td>Output price (including thinking tokens)</td><td>Free of charge</td><td>$2.50</td></tr>`,
1142 ),
1143 NOW,
1145 expect(rows.has('gemini-2.5-flash')).toBe(true)
1146 expect(rows.has('aqa')).toBe(false)
1147 expect(rows.has('antigravity-preview-09-2026')).toBe(false)
1148 expect(rows.has('gemini-flash-latest')).toBe(false)
1149 })
1150​
1151 it('compiles the long-prompt re-quote as a tier', () => {
1152 const rows = parseGeminiPricing(
1153 section(
1154 'gemini-2.5-pro',
1155 `<tr><td>Input price</td><td>Free of charge</td><td>$1.25, prompts <= 200k tokens<br>$2.50, prompts > 200k tokens</td></tr>
1156 <tr><td>Output price (including thinking tokens)</td><td>Free of charge</td><td>$10.00, prompts <= 200k<br>$15.00, prompts > 200k</td></tr>`,
1157 ),
1158 NOW,
1160 expect(rows.get('gemini-2.5-pro')?.base).toEqual({
1161 input_tokens: 1.25e-6,
1162 output_tokens: 10e-6,
1163 })
1164 expect(rows.get('gemini-2.5-pro')?.tiers).toEqual([
1166 minPromptTokens: 200_000,
1167 rates: { input_tokens: 2.5e-6, output_tokens: 15e-6 },
1168 },
1169 ])
1170 })
1171​
1172 it('takes the dated price in effect and stamps its expiry', () => {
1173 const page = section(
1174 'gemini-3.8-flash',
1175 `<tr><td>Input price</td><td>Not available</td><td>$0.75 through December 31, 2026.<br>$1.50 starting January 1, 2027.</td></tr>
1176 <tr><td>Output price (including thinking tokens)</td><td>Not available</td><td>$3.75 through December 31, 2026.<br>$7.50 starting January 1, 2027.</td></tr>`,
1178 expect(parseGeminiPricing(page, NOW).get('gemini-3.8-flash')).toEqual({
1179 base: { input_tokens: 0.75e-6, output_tokens: 3.75e-6 },
1180 tiers: [],
1181 expiresAt: '2027-01-01T00:00:00.000Z',
1182 })
1183 expect(
1184 parseGeminiPricing(page, Date.UTC(2027, 5, 1)).get('gemini-3.8-flash'),
1185 ).toEqual({
1186 base: { input_tokens: 1.5e-6, output_tokens: 7.5e-6 },
1187 tiers: [],
1188 })
1189 })
1190​
1191 it('reads a caching rate scoped to implicit caching', () => {
1192 // gemini-4-argon, 2026-10-22: the note after the dated pair quotes no
1193 // amount and must not refuse the model.
1194 const page = section(
1195 'gemini-4-argon',
1196 `<tr><td>Input price</td><td>Not available</td><td>$2.00 through November 30, 2026.<br>$4.00 starting December 1, 2026.</td></tr>
1197 <tr><td>Output price (including thinking tokens)</td><td>Not available</td><td>$10.00 through November 30, 2026.<br>$20.00 starting December 1, 2026.</td></tr>
1198 <tr><td>Context caching price</td><td>Not available</td><td>$0.10 through November 30, 2026.<br>$0.20 starting December 1, 2026.<br>Implicit caching only (explicit caching is not supported).</td></tr>`,
1200 expect(parseGeminiPricing(page, NOW).get('gemini-4-argon')).toEqual({
1201 base: {
1202 input_tokens: 2e-6,
1203 output_tokens: 10e-6,
1204 cache_read_tokens: 0.1 / 1e6,
1205 },
1206 tiers: [],
1207 expiresAt: '2026-12-01T00:00:00.000Z',
1208 })
1209 // Any other unpriced note on that row still refuses the model.
1210 const other = page.replace('Implicit caching only', 'Billed separately')
1211 expect(parseGeminiPricing(other, NOW).has('gemini-4-argon')).toBe(false)
1212 })
1213​
1214 it('gives a separately priced modality its own lever', () => {
1215 // Gemini sums text, image and video into one prompt-token count, so a
1216 // rate covering them all is the input lever; audio is priced apart.
1217 const rows = parseGeminiPricing(
1218 section(
1219 'gemini-3-pro-image',
1220 `<tr><td>Input price</td><td>Not available</td><td>$2.00 (text/image),<br>equivalent to $0.0011 per image</td></tr>
1221 <tr><td>Output price</td><td>Not available</td><td>$12.00 (text and thinking)<br>$120.00 (images)<br>Equivalent to $0.134 per 1K/2K image<br>and $0.24 per 4K image</td></tr>`,
1222 ),
1223 NOW,
1225 // The per-image lines restate the token rate; they are not extra cost.
1226 expect(rows.get('gemini-3-pro-image')?.base).toEqual({
1227 input_tokens: 2e-6,
1228 output_tokens: 12e-6,
1229 image_output_tokens: 120e-6,
1230 })
1231 })
1232​
1233 it('reads a per-modality row and an audio-only rate', () => {
1234 const rows = parseGeminiPricing(
1235 section(
1236 'gemini-embedding-2',
1237 `<tr><td>Text input price</td><td>Not available</td><td>$0.20</td></tr>
1238 <tr><td>Image input price</td><td>Not available</td><td>$0.45 ($0.00012 per image)</td></tr>
1239 <tr><td>Audio input price</td><td>Not available</td><td>$6.50 ($0.00016 per second)</td></tr>`,
1240 ),
1241 NOW,
1243 expect(rows.get('gemini-embedding-2')?.base).toEqual({
1244 input_tokens: 0.2 / 1e6,
1245 image_tokens: 0.45 / 1e6,
1246 audio_tokens: 6.5 / 1e6,
1247 })
1248 })
1249​
1250 it('cards a per-second section, one row per model id', () => {
1251 const page = `<div class="models-section">
1252 <div class="heading-group"><h2 id="veo-3.1">Veo 3.1</h2>
1253 <em><a href="/a"><code translate="no" dir="ltr">veo-3.1-generate-preview</code></a>,
1254 <a href="/b"><code translate="no" dir="ltr">veo-3.1-fast-generate-preview</code></a>,
1255 <a href="/c"><code translate="no" dir="ltr">veo-3.1-lite-generate-preview</code></a></em></div>
1256 </div>
1257 <table class="pricing-table"><thead><tr><th></th><th scope="col">Free Tier</th>
1258 <th scope="col">Paid Tier, per second in USD</th></tr></thead><tbody>
1259 <tr><td>Veo 3.1 Standard video with audio price (default)</td><td>Not available</td><td>$0.40 (720p and 1080p)<br>$0.60 (4k)</td></tr>
1260 <tr><td>Veo 3.1 Fast video with audio price (default)</td><td>Not available</td><td>$0.10 (720p)<br>$0.30 (4k)</td></tr>
1261 <tr><td>Veo 3.1 Lite video with audio price (default)</td><td>Not available</td><td>$0.05 (720p)<br>(4k output not supported)</td></tr>
1262 <tr><td>Used to improve our products</td><td>Yes</td><td>No</td></tr>
1263 </tbody></table>`
1264 const rows = parseGeminiPricing(page, Date.UTC(2026, 8, 16))
1265 expect(rows.get('veo-3.1-generate-preview')?.unit).toEqual({
1266 // Duration and size sit under the request's untyped `parameters`.
1267 quantity: { param: 'video_seconds', bound: 'usage' },
1268 keys: [
1270 param: 'resolution',
1271 bound: 'usage',
1272 values: ['720p', '1080p', '4k'],
1273 },
1274 ],
1275 rates: { '720p': 0.4, '1080p': 0.4, '4k': 0.6 },
1276 })
1277 expect(rows.get('veo-3.1-fast-generate-preview')?.unit?.rates).toEqual({
1278 '720p': 0.1,
1279 '4k': 0.3,
1280 })
1281 // A size the model cannot output is not a rate.
1282 expect(rows.get('veo-3.1-lite-generate-preview')?.unit?.rates).toEqual({
1283 '720p': 0.05,
1284 })
1285 })
1286​
1287 it('cards a per-request section flat', () => {
1288 const page = `<div class="models-section">
1289 <div class="heading-group"><h2 id="lyria">Lyria</h2>
1290 <em><a href="/a"><code translate="no" dir="ltr">lyria-3-clip-preview</code></a>,
1291 <a href="/b"><code translate="no" dir="ltr">lyria-3-pro-preview</code></a></em></div>
1292 </div>
1293 <table class="pricing-table"><thead><tr><th></th><th scope="col">Free Tier</th>
1294 <th scope="col">Paid Tier, per request in USD</th></tr></thead><tbody>
1295 <tr><td>Lyria 3 Clip Preview (30s)</td><td>Not available</td><td>$0.04 per song</td></tr>
1296 <tr><td>Lyria 3 Pro Preview (Full Song)</td><td>Not available</td><td>$0.08 per song</td></tr>
1297 </tbody></table>`
1298 const rows = parseGeminiPricing(page, Date.UTC(2026, 8, 16))
1299 expect(rows.get('lyria-3-clip-preview')?.unit).toEqual({ rates: 0.04 })
1300 expect(rows.get('lyria-3-pro-preview')?.unit).toEqual({ rates: 0.08 })
1301 })
1302​
1303 it('refuses a model whose bill is not only tokens', () => {
1304 // A row priced per image (not a restatement of a token rate), a
1305 // modality the row has no lever for, and a priced row with no lever.
1306 const perImage = `<tr><td>Input price</td><td>Not available</td><td>$0.30 (text / image)</td></tr>
1307 <tr><td>Output price</td><td>Not available</td><td>$0.039 per image</td></tr>`
1308 const perSong = `<tr><td>Lyria 3.5 (Full Song)</td><td>Not available</td><td>$0.08 per song</td></tr>`
1309 const unknownModality = `<tr><td>Input price</td><td>Not available</td><td>$1.00 (hologram)</td></tr>`
1310 for (const rows of [perImage, perSong, unknownModality]) {
1311 expect(parseGeminiPricing(section('m', rows), NOW).size).toBe(0)
1313 })
1314​
1315 it('clears the price of an id no section names, and only that', async () => {
1316 const tokens = `<tr><td>Input price</td><td>Free</td><td>$0.75</td></tr>
1317 <tr><td>Output price</td><td>Free</td><td>$3.75</td></tr>`
1318 const perSong = `<tr><td>Lyria 3.5 (Full Song)</td><td>Not available</td><td>$0.08 per song</td></tr>`
1319 const page =
1320 section('gemini-3.6-flash', tokens) + section('lyria-3.5', perSong)
1321 vi.stubGlobal('fetch', () => Promise.resolve(new Response(page)))
1322 try {
1323 const pricing = await geminiModelPricing()
1324 expect(pricing('gemini-3.6-flash').pricing).toBeTruthy()
1325 expect(pricing('gemini-3.6-flash').absent).toBeUndefined()
1326 // Deprecated and routed to 3.6: the page has no section for it.
1327 expect(pricing('gemini-3.5-flash')).toEqual({
1328 absent: { pricing: 'cleared' },
1329 })
1330 // Named but refused by the parser: the stored card is kept.
1331 expect(pricing('lyria-3.5')).toEqual({})
1332 } finally {
1333 vi.unstubAllGlobals()
1335 })