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

Function fetchJson

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

Source from the content-addressed store, hash-verified

105}
106
107async function fetchJson(
108 baseUrl: string,
109 path: string,
110 apiKey: string | null | undefined,
111 signal?: AbortSignal,
112): Promise<unknown> {
113 const headers: Record<string, string> = {};
114 if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
115
116 const response = await fetch(`${baseUrl}${path}`, { headers, signal });
117
118 if (!response.ok) {
119 throw new PollinationsError(
120 `Failed to fetch model catalog from ${path}`,
121 "MODEL_CATALOG",
122 response.status,
123 );
124 }
125
126 return response.json();
127}
128
129async function fetchCatalogModels(
130 baseUrl: string,

Callers 1

fetchCatalogModelsFunction · 0.70

Calls 2

jsonMethod · 0.80
fetchFunction · 0.50

Tested by

no test coverage detected