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

hyperbolic.ts

107 lines3.1 KB

1/**
2 * Hyperbolic — OpenAI-compatible inference API. No public spec; schemas
3 * are generated from the canonical OpenAI document.
4 */
5import { hyperbolicListingCard } from '../catalog-prices.ts'
6import {
7 classifyOpenAiCompat,
8 fetchOpenAiCompatibleSpec,
9 listOpenAiCompatibleModels,
10 openAiCompatModelFacts,
11} from '../openai-compat.ts'
12import type { OpenAiCompatModelRow } from '../openai-compat.ts'
13import {
14 compatGenerationEndpointId,
15 flaggedChatModalities,
16 hyperbolicModelActivity,
17} from '../model-meta.ts'
18import type {
19 ModelInfo,
20 ProviderConfig,
21 ProviderSecrets,
22 SpecFetchResult,
23} from '../types.ts'
24​
25const HYPERBOLIC_DOCS_URL = 'https://docs.hyperbolic.xyz'
26const HYPERBOLIC_MODELS_URL = 'https://api.hyperbolic.xyz/v1/models'
27const HYPERBOLIC_SERVER_URL = 'https://api.hyperbolic.xyz/v1'
28​
29/**
30 * `supports_tools` is the only capability the models list states. A false
31 * flag is an empty list, not an unknown one. Other row flags (features,
32 * sampling) still count; the boolean wins for `tools`.
33 */
34function hyperbolicCapabilities(
35 row: OpenAiCompatModelRow,
36): Pick<ModelInfo, 'capabilities' | 'exactCapabilities' | 'factSources'> {
37 if (typeof row.supports_tools !== 'boolean') return {}
38 const listed = openAiCompatModelFacts(row).capabilities
39 const caps = new Set(Array.isArray(listed) ? listed : [])
40 if (row.supports_tools) caps.add('tools')
41 else caps.delete('tools')
42 const capabilities = [...caps]
43 return {
44 capabilities,
45 exactCapabilities: true,
46 ...(capabilities.includes('tools')
47 ? {
48 factSources: {
49 capabilities: {
50 tools: {
51 derivation: 'listing',
52 sourceUrl: HYPERBOLIC_MODELS_URL,
53 path: 'supports_tools',
54 },
55 },
56 },
57 }
58 : {}),
59 }
61​
62async function fetchSpec(_env: ProviderSecrets): Promise<SpecFetchResult> {
63 const { spec, url, hash } = await fetchOpenAiCompatibleSpec({
64 title: 'Hyperbolic',
65 serverUrl: HYPERBOLIC_SERVER_URL,
66 include: ['/chat/completions'],
67 })
68 return {
69 specs: [spec],
70 sources: [{ url, hash }],
71 outputStrategy: 'post-200',
72 }
74​
75export const provider: ProviderConfig = {
76 id: 'hyperbolic',
77 displayName: 'Hyperbolic',
78 authEnvVar: 'HYPERBOLIC_API_KEY',
79 specSourceUrl: HYPERBOLIC_DOCS_URL,
80 modelsEndpoint: HYPERBOLIC_MODELS_URL,
81 defaultDerivation: 'generated',
82 fetchSpec,
83 listModels: (env) =>
84 listOpenAiCompatibleModels({
85 providerId: 'hyperbolic',
86 url: HYPERBOLIC_MODELS_URL,
87 env,
88 envVar: 'HYPERBOLIC_API_KEY',
89 activity: hyperbolicModelActivity,
90 extend: async (row) => {
91 const pricing = await hyperbolicListingCard(
92 row.input_price,
93 row.output_price,
94 HYPERBOLIC_MODELS_URL,
95 )
96 return {
97 ...(row.supports_chat !== undefined
98 ? { modalities: flaggedChatModalities(row) }
99 : {}),
100 ...(pricing ? { pricing } : {}),
101 ...hyperbolicCapabilities(row),
102 }
103 },
104 }),
105 classify: classifyOpenAiCompat,
106 generationEndpointId: ({ activity }) => compatGenerationEndpointId(activity),