MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / fetchModelsFromProvider

Function fetchModelsFromProvider

src/api/providers/fetchers/modelCache.ts:183–231  ·  view source on GitHub ↗

* Fetch models from the provider API. * Extracted to avoid duplication between getModels() and refreshModels(). * * @param options - Provider options for fetching models * @returns Fresh models from the provider API

(options: GetModelsOptions)

Source from the content-addressed store, hash-verified

181 * @returns Fresh models from the provider API
182 */
183async function fetchModelsFromProvider(options: GetModelsOptions): Promise<ModelRecord> {
184 const { provider } = options
185
186 let models: ModelRecord
187
188 switch (provider) {
189 case "openrouter":
190 models = await getOpenRouterModels()
191 break
192 case "requesty":
193 // Requesty models endpoint requires an API key for per-user custom policies.
194 models = await getRequestyModels(options.baseUrl, options.apiKey)
195 break
196 case "unbound":
197 models = await getUnboundModels(options.apiKey)
198 break
199 case "litellm":
200 models = await getLiteLLMModels(options.apiKey ?? "", options.baseUrl)
201 break
202 case "ollama":
203 models = await getOllamaModels(options.baseUrl, options.apiKey)
204 break
205 case "lmstudio":
206 models = await getLMStudioModels(options.baseUrl)
207 break
208 case "vercel-ai-gateway":
209 models = await getVercelAiGatewayModels()
210 break
211 case "opencode-go":
212 models = await getOpencodeGoModels(options.apiKey)
213 break
214 case "poe":
215 models = await getPoeModels(options.apiKey, options.baseUrl)
216 break
217 case "deepseek":
218 models = await getDeepSeekModels(options.baseUrl, options.apiKey)
219 break
220 case "zoo-gateway":
221 models = await getZooGatewayModels({ zooSessionToken: options.apiKey, zooGatewayBaseUrl: options.baseUrl })
222 break
223 default: {
224 // Ensures router is exhaustively checked if RouterName is a strict union.
225 const exhaustiveCheck: never = provider
226 throw new Error(`Unknown provider: ${exhaustiveCheck}`)
227 }
228 }
229
230 return models
231}
232
233/**
234 * Get models from the cache or fetch them from the provider and cache them.

Callers 2

getModelsFunction · 0.85
refreshModelsFunction · 0.85

Calls 11

getOpenRouterModelsFunction · 0.90
getRequestyModelsFunction · 0.90
getUnboundModelsFunction · 0.90
getLiteLLMModelsFunction · 0.90
getOllamaModelsFunction · 0.90
getLMStudioModelsFunction · 0.90
getVercelAiGatewayModelsFunction · 0.90
getOpencodeGoModelsFunction · 0.90
getPoeModelsFunction · 0.90
getDeepSeekModelsFunction · 0.90
getZooGatewayModelsFunction · 0.90

Tested by

no test coverage detected