MCPcopy Create free account
hub / github.com/pollinations/pollinations / fetchCatalogModels

Function fetchCatalogModels

packages/sdk/src/models.ts:129–151  ·  view source on GitHub ↗
(
    baseUrl: string,
    apiKey: string | null | undefined,
    signal?: AbortSignal,
)

Source from the content-addressed store, hash-verified

127}
128
129async function fetchCatalogModels(
130 baseUrl: string,
131 apiKey: string | null | undefined,
132 signal?: AbortSignal,
133): Promise<ModelCatalogItem[]> {
134 const rawModels = await fetchJson(baseUrl, "/models", apiKey, signal);
135 // A 2xx response with a non-array body means the endpoint returned
136 // something unexpected (e.g. an error envelope). Surface it instead of
137 // silently treating it as an empty catalog.
138 if (!Array.isArray(rawModels)) {
139 throw new PollinationsError(
140 "Model catalog endpoint /models returned a non-array response",
141 "MODEL_CATALOG",
142 502,
143 );
144 }
145
146 return sortModels(
147 (rawModels as ModelInfo[])
148 .map(normalizeModel)
149 .filter((model): model is ModelCatalogItem => model !== null),
150 );
151}
152
153function trimTrailingSlashes(value: string): string {
154 let end = value.length;

Callers 1

fetchModelCatalogFunction · 0.70

Calls 2

fetchJsonFunction · 0.70
sortModelsFunction · 0.70

Tested by

no test coverage detected