Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import {
4 parseGroqCachedInput,
5 parseGroqCachingModels,
6 parseGroqPrice,
7 parseGroqPricing,
8} from './groq-pricing.ts'
9
10const PAGE = `# Supported Models
11
12| MODEL ID | SPEED | PRICE PER 1M TOKENS | RATE LIMITS |
13| --- | --- | --- | --- |
14| [GPT OSS 120B](/docs/model/openai/gpt-oss-120b)openai/gpt-oss-120b | 500 | $0.15 input$0.60 output | 250K TPM |
15| [Llama 3.1 8B](/docs/model/llama-3.1-8b-instant)Enterprisellama-3.1-8b-instant | 560 | ContactSales | ContactSales |
16| [Whisper](/docs/model/whisper-large-v3)whisper-large-v3 | - | $0.111 per hour | 200K ASH |
17| [Orpheus](/docs/model/canopylabs/orpheus-v1-english)canopylabs/orpheus-v1-english | - | $22.00 per 1M characters | 50K TPM |
18| [Qwen](/docs/model/qwen/qwen3.8-27b)qwen/qwen3.8-27b | 450 | $0.80 input$4.00 output | 250K TPM |
19| [New](/docs/model/new)new-model | - | $1 per request | - |
20`
21
22describe('groq models page', () => {
23 it('reads token, hour, and character prices and skips unpublished ones', () => {
24 const rates = parseGroqPricing(PAGE)
25 expect(rates.get('openai/gpt-oss-120b')).toEqual({
26 kind: 'tokens',
27 rates: { input_tokens: 0.15e-6, output_tokens: 0.6e-6 },
28 })
29 const oss = rates.get('openai/gpt-oss-120b')
30 expect(oss?.kind === 'tokens' ? oss.rates : {}).not.toHaveProperty(
31 'cache_read_tokens',
32 )
33 expect(rates.get('qwen/qwen3.8-27b')).toEqual({
34 kind: 'tokens',
35 rates: { input_tokens: 0.8 / 1e6, output_tokens: 4 / 1e6 },
36 })
37 expect(rates.get('whisper-large-v3')).toEqual({
38 kind: 'unit',
39 unit: {
40 quantity: { param: 'audio_seconds', bound: 'usage' },
41 rates: 0.111 / 3600,
42 },
43 })
44 expect(rates.get('canopylabs/orpheus-v1-english')).toEqual({
45 kind: 'unit',
46 unit: {
47 quantity: { param: 'characters', bound: 'usage' },
48 rates: 22 / 1e6,
49 },
50 })
51 expect(rates.has('llama-3.1-8b-instant')).toBe(false)
52 expect(rates.has('new-model')).toBe(false)
53 expect(parseGroqPrice('$1 per request')).toBe('refuse')
54 })
55})
56
57const CACHING = `# Prompt Caching
58
59## [Supported Models](#supported-models)
60
61| Model ID | Model |
62| ---------------------------- | ----------------------------------------------------------------- |
63| openai/gpt-oss-20b | [GPT-OSS 20B](https://console.groq.com/docs/model/openai/gpt-oss-20b) |
64| openai/gpt-oss-120b | [GPT-OSS 120B](https://console.groq.com/docs/model/openai/gpt-oss-120b) |
65
66We're starting with a limited selection of models.
67
68## [Pricing](#pricing)
69
70| Not | A model |
71| --- | --- |
72| x/y | z |
73`
74
75const MODEL_PAGE = `### PRICING
76
77Input
78
79$0.075
80
8113M / $1
82
83Cached Input
84
85$0.037
86
8727M / $1
88
89Output
90
91$0.30
92`
93
94describe('groq cached-input prices (#411)', () => {
95 it('reads the Supported Models table only', () => {
96 expect(parseGroqCachingModels(CACHING)).toEqual([
97 'openai/gpt-oss-20b',
98 'openai/gpt-oss-120b',
99 ])
100 })
101
102 it('throws when the doc lists no caching model', () => {
103 expect(() => parseGroqCachingModels('# Prompt Caching\n')).toThrow(
104 /no Supported Models rows/,
105 )
106 })
107
108 it("reads the model page's stated Cached Input price", () => {
109 expect(parseGroqCachedInput(MODEL_PAGE, 'openai/gpt-oss-20b')).toBe(
110 0.037 / 1e6,
111 )
112 })
113
114 it('throws when a caching model page states no Cached Input price', () => {
115 expect(() =>
116 parseGroqCachedInput('Input\n\n$0.075\n\nOutput\n\n$0.30\n', 'm'),
117 ).toThrow(/no Cached Input price/)
118 })
119})