MCPcopy Index your code
hub / github.com/di-sukharev/opencommit / fetchOpenAIModels

Function fetchOpenAIModels

out/cli.cjs:86217–86235  ·  view source on GitHub ↗
(apiKey)

Source from the content-addressed store, hash-verified

86215 (0, import_fs5.writeFileSync)(MODEL_CACHE_PATH, JSON.stringify(cache, null, 2), "utf8");
86216 } catch {
86217 }
86218}
86219function isCacheValid(cache) {
86220 if (!cache) return false;
86221 return Date.now() - cache.timestamp < CACHE_TTL_MS;
86222}
86223async function fetchOpenAIModels(apiKey) {
86224 try {
86225 const response = await fetch("https://api.openai.com/v1/models", {
86226 headers: {
86227 Authorization: `Bearer ${apiKey}`
86228 }
86229 });
86230 if (!response.ok) {
86231 return MODEL_LIST.openai;
86232 }
86233 const data = await response.json();
86234 const models = data.data.map((m5) => m5.id).filter(
86235 (id) => id.startsWith("gpt-") || id.startsWith("o1") || id.startsWith("o3") || id.startsWith("o4")
86236 ).sort();
86237 return models.length > 0 ? models : MODEL_LIST.openai;
86238 } catch {

Callers 1

fetchModelsForProviderFunction · 0.70

Calls 4

filterMethod · 0.80
startsWithMethod · 0.80
jsonMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…