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

baseten.test.ts

290 lines8.4 KB

1import { afterEach, describe, expect, it } from 'vitest'
2​
3import {
4 BASETEN_CHAT_OPENAPI_URL,
5 BASETEN_MESSAGES_OPENAPI_URL,
6 BASETEN_MODELS_URL,
7 BASETEN_REASONING_URL,
8 parseBasetenModels,
9 provider,
10} from './baseten.ts'
11import { reasoningViolation } from '../types.ts'
12​
13const REASONING = `
14## Control reasoning
15​
16| Model | Slug | Reasoning | Control |
17| - | - | - | - |
18| Beam | \`reflection/Beam-1.0\` | Always on | None |
19| GLM 5.3 | \`zai-org/GLM-5.3\` | On by default | \`reasoning_effort\` |
20| Nemotron Ultra | \`nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B\` | Off by default | \`chat_template_args\` |
21| OpenAI GPT 120B | \`openai/gpt-oss-120b\` | On by default | \`reasoning_effort\` |
22​
23<span id="control-reasoning-depth" />
24​
25### Set reasoning depth
26​
27| Model | Supported values | Effective depth |
28| - | - | - |
29| Beam | \`minimal\`, \`low\`, \`medium\`, \`high\`, \`xhigh\`, \`max\` | As sent |
30| GLM 5.3 | \`none\`, \`low\`, \`high\` (default), \`max\` | \`none\` runs at \`low\` |
31| Kimi K3 | \`none\`, \`low\`, \`high\`, \`max\` (default) | As sent |
32| Nemotron Super 3.5 | \`none\` (default), \`high\` | \`none\` turns reasoning off; every other value runs at one depth, \`high\` |
33| OpenAI GPT 120B | \`none\`, \`low\`, \`medium\` (default), \`high\` | \`none\` can still reason; other values as sent |
34​
35### Set a reasoning budget
36​
37| Model | Supported values |
38| - | - |
39| Nemotron Ultra | \`none\`, \`high\` |
40​
41## Parse the response
42​
43| Model | Supported values |
44| - | - |
45| Nemotron Ultra | \`none\`, \`high\` |
47​
48const PAYLOAD = {
49 data: [
50 {
51 id: 'reflection/Beam-1.0',
52 name: 'Beam',
53 output_modalities: ['text'],
54 pricing: { prompt: '0.000001', completion: '0.000004' },
55 },
56 {
57 id: 'zai-org/GLM-5.3',
58 name: 'GLM 5.3',
59 created: 1787927191,
60 context_length: 1048576,
61 max_completion_tokens: 262144,
62 input_modalities: ['text', 'image'],
63 output_modalities: ['text'],
64 pricing: {
65 prompt: '0.0000014',
66 completion: '0.0000044',
67 image: '0',
68 request: '0',
69 input_cache_read: '0.00000014',
70 },
71 },
72 {
73 id: 'openai/gpt-oss-120b',
74 name: 'OpenAI GPT 120B',
75 created: 1754410981,
76 context_length: 128072,
77 max_completion_tokens: 128072,
78 input_modalities: ['text'],
79 output_modalities: ['text'],
80 pricing: {
81 prompt: '0.0000001',
82 completion: '0.0000005',
83 image: '0',
84 request: '0',
85 input_cache_read: '0.0000001',
86 },
87 },
88 {
89 id: 'nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B',
90 name: 'Nemotron Ultra',
91 created: 1780594202,
92 context_length: 202800,
93 max_completion_tokens: 202800,
94 input_modalities: ['text'],
95 output_modalities: ['text'],
96 pricing: {
97 prompt: '0.0000006',
98 completion: '0.0000024',
99 input_cache_read: '0',
100 },
101 },
102 ],
104​
105const HASH = 'a'.repeat(64)
106const SOURCE = {
107 url: BASETEN_MODELS_URL,
108 hash: HASH,
109 extractedAt: '2026-10-06T00:00:00.000Z',
111​
112const SPEC = {
113 openapi: '3.1.0',
114 paths: { '/v1/chat/completions': { post: {} } },
116const MESSAGES = { openapi: '3.1.0', paths: { '/v1/messages': { post: {} } } }
117​
118const originalFetch = globalThis.fetch
119​
120afterEach(() => {
121 globalThis.fetch = originalFetch
122})
123​
124describe('baseten', () => {
125 it('reads per-token prices and joins efforts by display name', () => {
126 const models = parseBasetenModels(PAYLOAD, REASONING, SOURCE, HASH)
127 const byId = new Map(models.map((model) => [model.rawId, model]))
128​
129 expect(byId.get('zai-org/GLM-5.3')).toMatchObject({
130 displayName: 'GLM 5.3',
131 activity: 'chat',
132 contextWindow: 1048576,
133 maxOutput: 262144,
134 modalities: { input: ['text', 'image'], output: ['text'] },
135 releasedAt: 1787927191,
136 reasoning: {
137 mode: 'effort',
138 mandatory: true,
139 efforts: ['low', 'high', 'max'],
140 },
141 pricing: {
142 tables: {
143 rate: {
144 base: {
145 input_tokens: 0.0000014,
146 output_tokens: 0.0000044,
147 cache_read_tokens: 0.00000014,
148 },
149 },
150 },
151 },
152 })
153 expect(byId.get('openai/gpt-oss-120b')?.pricing).toMatchObject({
154 tables: {
155 rate: {
156 base: {
157 input_tokens: 0.0000001,
158 output_tokens: 0.0000005,
159 cache_read_tokens: 0.0000001,
160 },
161 },
162 },
163 })
164 expect(byId.get('zai-org/GLM-5.3')?.pricing).not.toHaveProperty(
165 'tables.rate.base.image',
166 )
167 expect(
168 byId.get('nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B')?.reasoning,
169 ).toBeNull()
170 expect(
171 byId.get('nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B')?.pricing,
172 ).not.toHaveProperty('tables.rate.base.cache_read_tokens')
173 expect(byId.get('zai-org/GLM-5.3')?.factSources?.reasoning?.sourceUrl).toBe(
174 BASETEN_REASONING_URL,
175 )
176 })
177​
178 it('reads mandatory from what effective depth says about none', () => {
179 const names = ['Beam', 'Kimi K3', 'Nemotron Super 3.5', 'OpenAI GPT 120B']
180 const models = parseBasetenModels(
181 { data: names.map((name) => ({ id: name, name })) },
182 REASONING,
183 SOURCE,
184 HASH,
185 )
186 const reasoning = new Map(
187 models.map((model) => [model.rawId, model.reasoning]),
188 )
189​
190 expect(reasoning.get('Beam')).toEqual({
191 mode: 'effort',
192 mandatory: true,
193 efforts: ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'],
194 })
195 expect(reasoning.get('Kimi K3')?.mandatory).toBe(false)
196 expect(reasoning.get('Nemotron Super 3.5')?.mandatory).toBe(false)
197 expect(reasoning.get('OpenAI GPT 120B')).toEqual({
198 mode: 'effort',
199 mandatory: null,
200 efforts: ['none', 'low', 'medium', 'high'],
201 })
202 for (const model of models) {
203 expect(reasoningViolation(model.reasoning)).toBeNull()
204 }
205 })
206​
207 it('reads the table under the older ## heading too', () => {
208 const models = parseBasetenModels(
209 PAYLOAD,
210 REASONING.replace(
211 '### Set reasoning depth',
212 '## Control reasoning depth',
213 ),
214 SOURCE,
215 HASH,
216 )
217 expect(
218 models.find((model) => model.rawId === 'zai-org/GLM-5.3')?.reasoning
219 ?.efforts,
220 ).toEqual(['low', 'high', 'max'])
221 })
222​
223 it('throws when the reasoning page has no effort table', () => {
224 expect(() =>
225 parseBasetenModels(
226 PAYLOAD,
227 REASONING.replace('### Set reasoning depth', '### Depth'),
228 SOURCE,
229 HASH,
230 ),
231 ).toThrow(/no effort table/)
232 })
233​
234 it('throws when the payload has no ids', () => {
235 expect(() =>
236 parseBasetenModels({ data: [] }, REASONING, SOURCE, HASH),
237 ).toThrow(/listed no ids/)
238 })
239​
240 it('skips without a key and lists from the inference host with one', async () => {
241 const urls: Array<string> = []
242 const headers: Array<string> = []
243 globalThis.fetch = ((url: string, init?: RequestInit) => {
244 urls.push(String(url))
245 const authorization = new Headers(init?.headers).get('Authorization')
246 if (authorization) headers.push(authorization)
247 const body =
248 String(url) === BASETEN_MODELS_URL
249 ? JSON.stringify(PAYLOAD)
250 : String(url) === BASETEN_REASONING_URL
251 ? REASONING
252 : String(url) === BASETEN_CHAT_OPENAPI_URL
253 ? JSON.stringify(SPEC)
254 : String(url) === BASETEN_MESSAGES_OPENAPI_URL
255 ? JSON.stringify(MESSAGES)
256 : null
257 if (body === null) {
258 return Promise.reject(new Error(`unexpected fetch: ${String(url)}`))
259 }
260 return Promise.resolve(new Response(body))
261 }) as typeof fetch
262​
263 const skipped = await provider.listModels({})
264 expect(skipped.skipped).toBe('baseten: BASETEN_API_KEY not set — skipped')
265 expect(skipped.models).toEqual([])
266 expect(urls).toEqual([])
267​
268 const listed = await provider.listModels({ BASETEN_API_KEY: 'test-key' })
269 const spec = await provider.fetchSpec({})
270​
271 expect(listed.skipped).toBeUndefined()
272 expect(listed.models).toHaveLength(4)
273 expect(headers).toEqual(['Bearer test-key'])
274 expect(spec.sources.map((source) => source.url)).toEqual([
275 BASETEN_CHAT_OPENAPI_URL,
276 BASETEN_MESSAGES_OPENAPI_URL,
277 ])
278 expect(
279 urls.some((url) =>
280 /models\.dev|openrouter|baseten\.co\/pricing/i.test(url),
281 ),
282 ).toBe(false)
283 expect(urls).toEqual([
284 BASETEN_MODELS_URL,
285 BASETEN_REASONING_URL,
286 BASETEN_CHAT_OPENAPI_URL,
287 BASETEN_MESSAGES_OPENAPI_URL,
288 ])
289 })
290})