MCPcopy
hub / github.com/codedogQBY/ReadAny / fetchModelsFromEndpoint

Function fetchModelsFromEndpoint

packages/core/src/stores/settings-store.ts:90–113  ·  view source on GitHub ↗

* Fetch available models from an AI provider endpoint. * Supports OpenAI-compatible (/v1/models), Anthropic, and Google Gemini.

(endpoint: AIEndpoint)

Source from the content-addressed store, hash-verified

88 * Supports OpenAI-compatible (/v1/models), Anthropic, and Google Gemini.
89 */
90async function fetchModelsFromEndpoint(endpoint: AIEndpoint): Promise<string[]> {
91 if (providerRequiresApiKey(endpoint.provider) && !endpoint.apiKey) return [];
92 if (endpoint.useExactRequestUrl && providerSupportsExactRequestUrl(endpoint.provider)) {
93 throw new Error(
94 "Exact request URL mode cannot infer the model list automatically. Add models manually.",
95 );
96 }
97
98 switch (endpoint.provider) {
99 case "anthropic":
100 return fetchAnthropicModels(endpoint);
101 case "google":
102 return fetchGoogleModels(endpoint);
103 case "deepseek":
104 return fetchDeepSeekModels(endpoint);
105 case "ollama":
106 return fetchOllamaModels(endpoint);
107 case "lmstudio":
108 return fetchLMStudioModels(endpoint);
109 case "openai":
110 default:
111 return fetchOpenAIModels(endpoint);
112 }
113}
114
115/** OpenAI-compatible /v1/models */
116async function fetchOpenAIModels(endpoint: AIEndpoint): Promise<string[]> {

Callers 1

settings-store.tsFile · 0.70

Calls 8

providerRequiresApiKeyFunction · 0.90
fetchAnthropicModelsFunction · 0.70
fetchGoogleModelsFunction · 0.70
fetchDeepSeekModelsFunction · 0.70
fetchOllamaModelsFunction · 0.70
fetchLMStudioModelsFunction · 0.70
fetchOpenAIModelsFunction · 0.70

Tested by

no test coverage detected