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

baseten.test.ts

205 lines5.7 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'
11​
12const REASONING = `
13## Control reasoning depth
14​
15| Model | Supported values |
16| - | - |
17| GLM 5.3 | \`none\`, \`low\`, \`high\` (default), \`max\` |
18| OpenAI GPT 120B | \`none\`, \`low\`, \`medium\` (default), \`high\` |
19​
20Thinking is always on for the GLM 5.3 family, so \`none\` does not turn it off.
21​
22## Set a reasoning token budget
24​
25const PAYLOAD = {
26 data: [
27 {
28 id: 'zai-org/GLM-5.3',
29 name: 'GLM 5.3',
30 created: 1787927191,
31 context_length: 1048576,
32 max_completion_tokens: 262144,
33 input_modalities: ['text', 'image'],
34 output_modalities: ['text'],
35 pricing: {
36 prompt: '0.0000014',
37 completion: '0.0000044',
38 image: '0',
39 request: '0',
40 input_cache_read: '0.00000014',
41 },
42 },
43 {
44 id: 'openai/gpt-oss-120b',
45 name: 'OpenAI GPT 120B',
46 created: 1754410981,
47 context_length: 128072,
48 max_completion_tokens: 128072,
49 input_modalities: ['text'],
50 output_modalities: ['text'],
51 pricing: {
52 prompt: '0.0000001',
53 completion: '0.0000005',
54 image: '0',
55 request: '0',
56 input_cache_read: '0.0000001',
57 },
58 },
59 {
60 id: 'nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B',
61 name: 'Nemotron Ultra',
62 created: 1780594202,
63 context_length: 202800,
64 max_completion_tokens: 202800,
65 input_modalities: ['text'],
66 output_modalities: ['text'],
67 pricing: {
68 prompt: '0.0000006',
69 completion: '0.0000024',
70 input_cache_read: '0',
71 },
72 },
73 ],
75​
76const HASH = 'a'.repeat(64)
77const SOURCE = {
78 url: BASETEN_MODELS_URL,
79 hash: HASH,
80 extractedAt: '2026-10-06T00:00:00.000Z',
82​
83const SPEC = {
84 openapi: '3.1.0',
85 paths: { '/v1/chat/completions': { post: {} } },
87const MESSAGES = { openapi: '3.1.0', paths: { '/v1/messages': { post: {} } } }
88​
89const originalFetch = globalThis.fetch
90​
91afterEach(() => {
92 globalThis.fetch = originalFetch
93})
94​
95describe('baseten', () => {
96 it('reads per-token prices and joins efforts by display name', () => {
97 const models = parseBasetenModels(PAYLOAD, REASONING, SOURCE, HASH)
98 const byId = new Map(models.map((model) => [model.rawId, model]))
99​
100 expect(byId.get('zai-org/GLM-5.3')).toMatchObject({
101 displayName: 'GLM 5.3',
102 activity: 'chat',
103 contextWindow: 1048576,
104 maxOutput: 262144,
105 modalities: { input: ['text', 'image'], output: ['text'] },
106 releasedAt: 1787927191,
107 reasoning: {
108 mode: 'effort',
109 mandatory: true,
110 efforts: ['none', 'low', 'high', 'max'],
111 },
112 pricing: {
113 tables: {
114 rate: {
115 base: {
116 input_tokens: 0.0000014,
117 output_tokens: 0.0000044,
118 cache_read_tokens: 0.00000014,
119 },
120 },
121 },
122 },
123 })
124 expect(byId.get('openai/gpt-oss-120b')?.pricing).toMatchObject({
125 tables: {
126 rate: {
127 base: {
128 input_tokens: 0.0000001,
129 output_tokens: 0.0000005,
130 cache_read_tokens: 0.0000001,
131 },
132 },
133 },
134 })
135 expect(byId.get('zai-org/GLM-5.3')?.pricing).not.toHaveProperty(
136 'tables.rate.base.image',
137 )
138 expect(
139 byId.get('nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B')?.reasoning,
140 ).toBeNull()
141 expect(
142 byId.get('nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B')?.pricing,
143 ).not.toHaveProperty('tables.rate.base.cache_read_tokens')
144 expect(byId.get('zai-org/GLM-5.3')?.factSources?.reasoning?.sourceUrl).toBe(
145 BASETEN_REASONING_URL,
146 )
147 })
148​
149 it('throws when the payload has no ids', () => {
150 expect(() =>
151 parseBasetenModels({ data: [] }, REASONING, SOURCE, HASH),
152 ).toThrow(/listed no ids/)
153 })
154​
155 it('skips without a key and lists from the inference host with one', async () => {
156 const urls: Array<string> = []
157 const headers: Array<string> = []
158 globalThis.fetch = ((url: string, init?: RequestInit) => {
159 urls.push(String(url))
160 const authorization = new Headers(init?.headers).get('Authorization')
161 if (authorization) headers.push(authorization)
162 const body =
163 String(url) === BASETEN_MODELS_URL
164 ? JSON.stringify(PAYLOAD)
165 : String(url) === BASETEN_REASONING_URL
166 ? REASONING
167 : String(url) === BASETEN_CHAT_OPENAPI_URL
168 ? JSON.stringify(SPEC)
169 : String(url) === BASETEN_MESSAGES_OPENAPI_URL
170 ? JSON.stringify(MESSAGES)
171 : null
172 if (body === null) {
173 return Promise.reject(new Error(`unexpected fetch: ${String(url)}`))
174 }
175 return Promise.resolve(new Response(body))
176 }) as typeof fetch
177​
178 const skipped = await provider.listModels({})
179 expect(skipped.skipped).toBe('baseten: BASETEN_API_KEY not set — skipped')
180 expect(skipped.models).toEqual([])
181 expect(urls).toEqual([])
182​
183 const listed = await provider.listModels({ BASETEN_API_KEY: 'test-key' })
184 const spec = await provider.fetchSpec({})
185​
186 expect(listed.skipped).toBeUndefined()
187 expect(listed.models).toHaveLength(3)
188 expect(headers).toEqual(['Bearer test-key'])
189 expect(spec.sources.map((source) => source.url)).toEqual([
190 BASETEN_CHAT_OPENAPI_URL,
191 BASETEN_MESSAGES_OPENAPI_URL,
192 ])
193 expect(
194 urls.some((url) =>
195 /models\.dev|openrouter|baseten\.co\/pricing/i.test(url),
196 ),
197 ).toBe(false)
198 expect(urls).toEqual([
199 BASETEN_MODELS_URL,
200 BASETEN_REASONING_URL,
201 BASETEN_CHAT_OPENAPI_URL,
202 BASETEN_MESSAGES_OPENAPI_URL,
203 ])
204 })
205})