* 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)
| 181 | * @returns Fresh models from the provider API |
| 182 | */ |
| 183 | async 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. |
no test coverage detected