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

hyperbolic.test.ts

153 lines4.7 KB

1import { describe, expect, it } from 'vitest'
2​
3import { chatRequestMap } from '../request-map.ts'
4import { provider } from './hyperbolic.ts'
5​
6/** Live `GET https://api.hyperbolic.xyz/v1/models` on 2026-10-07. `created` is the poll clock, not a release date. */
7const LISTING = {
8 object: 'list',
9 data: [
10 {
11 id: 'deepseek-ai/DeepSeek-V3-0324',
12 created: 1791366236,
13 object: 'model',
14 owned_by: 'Hyperbolic',
15 number_of_inference_nodes: null,
16 supports_chat: true,
17 supports_image_input: false,
18 supports_tools: false,
19 context_length: 163840,
20 input_price: 1.25,
21 output_price: 1.25,
22 },
23 {
24 id: 'meta-llama/Llama-3.3-70B-Instruct',
25 created: 1791366236,
26 object: 'model',
27 owned_by: 'Hyperbolic',
28 number_of_inference_nodes: null,
29 supports_chat: true,
30 supports_image_input: false,
31 supports_tools: false,
32 context_length: 131072,
33 input_price: 0.4,
34 output_price: 0.4,
35 },
36 {
37 id: 'deepseek-ai/DeepSeek-R1',
38 created: 1791366236,
39 object: 'model',
40 owned_by: 'Hyperbolic',
41 number_of_inference_nodes: null,
42 supports_chat: true,
43 supports_image_input: false,
44 supports_tools: false,
45 context_length: 163840,
46 input_price: 2,
47 output_price: 2,
48 },
49 {
50 id: 'deepseek-ai/DeepSeek-R1-0528',
51 created: 1791366236,
52 object: 'model',
53 owned_by: 'Hyperbolic',
54 number_of_inference_nodes: null,
55 supports_chat: true,
56 supports_image_input: false,
57 supports_tools: false,
58 context_length: 163840,
59 input_price: 3,
60 output_price: 3,
61 },
62 {
63 id: 'Qwen/Qwen3-Coder-480B-A35B-Instruct',
64 created: 1791366236,
65 object: 'model',
66 owned_by: 'Hyperbolic',
67 number_of_inference_nodes: null,
68 supports_chat: true,
69 supports_image_input: false,
70 supports_tools: true,
71 context_length: 262144,
72 input_price: 2,
73 output_price: 2,
74 },
75 ],
77​
78describe('hyperbolic classify', () => {
79 it('maps chat completions and drops platform paths', () => {
80 expect(provider.classify('/chat/completions', {})).toBe('chat')
81 expect(provider.classify('/v1/chat/completions', {})).toBe('chat')
82 expect(provider.classify('/files', {})).toBeNull()
83 expect(provider.classify('/v1/models', {})).toBeNull()
84 expect(provider.classify('/fine_tuning/jobs', {})).toBeNull()
85 })
86})
87​
88describe('hyperbolic listModels', () => {
89 it('skips when the secret is absent', async () => {
90 const result = await provider.listModels({})
91 expect(result.models).toEqual([])
92 expect(result.skipped).toBe(
93 'hyperbolic: HYPERBOLIC_API_KEY not set — skipped',
94 )
95 })
96​
97 it('reads tools from supports_tools and leaves unpublished caps off the row', async () => {
98 const original = globalThis.fetch
99 globalThis.fetch = () =>
100 Promise.resolve(
101 new Response(JSON.stringify(LISTING), {
102 status: 200,
103 headers: { 'content-type': 'application/json' },
104 }),
105 )
106 try {
107 const { models } = await provider.listModels({
108 HYPERBOLIC_API_KEY: 'test',
109 })
110 expect(models.map((model) => model.rawId)).toEqual(
111 LISTING.data.map((row) => row.id),
112 )
113 for (const model of models) {
114 expect(model.activity).toBe('chat')
115 expect(model.maxOutput ?? null).toBeNull()
116 expect(model.modalities).toEqual({ input: ['text'], output: ['text'] })
117 expect(model.exactCapabilities).toBe(true)
118 const base = (
119 model.pricing as {
120 tables: { rate: { base: Record<string, number> } }
121 }
122 ).tables.rate.base
123 expect(Object.keys(base).sort()).toEqual([
124 'input_tokens',
125 'output_tokens',
126 ])
127 expect(
128 chatRequestMap('hyperbolic', model.rawId, model.activity),
129 ).toBeNull()
130 }
131 const qwen = models.find((model) => model.rawId.startsWith('Qwen/'))
132 expect(qwen?.contextWindow).toBe(262144)
133 expect(qwen?.capabilities).toEqual(['tools'])
134 expect(qwen?.factSources?.capabilities?.tools).toEqual({
135 derivation: 'listing',
136 sourceUrl: 'https://api.hyperbolic.xyz/v1/models',
137 path: 'supports_tools',
138 })
139 const silent = models.filter((model) => !model.rawId.startsWith('Qwen/'))
140 expect(silent).toHaveLength(4)
141 for (const model of silent) {
142 expect(model.capabilities).toEqual([])
143 expect(model.factSources?.capabilities).toBeUndefined()
144 }
145 expect(
146 models.find((model) => model.rawId === 'deepseek-ai/DeepSeek-R1')
147 ?.contextWindow,
148 ).toBe(163840)
149 } finally {
150 globalThis.fetch = original
151 }
152 })
153})