MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / fetchOpenPlatformModels

Function fetchOpenPlatformModels

packages/oauth/src/open-platform.ts:111–138  ·  view source on GitHub ↗
(
  platform: OpenPlatformDefinition,
  apiKey: string,
  fetchImpl: typeof fetch = fetch,
  signal?: AbortSignal,
)

Source from the content-addressed store, hash-verified

109}
110
111export async function fetchOpenPlatformModels(
112 platform: OpenPlatformDefinition,
113 apiKey: string,
114 fetchImpl: typeof fetch = fetch,
115 signal?: AbortSignal,
116): Promise<ManagedKimiCodeModelInfo[]> {
117 const res = await fetchImpl(`${platform.baseUrl.replace(/\/+$/, '')}/models`, {
118 headers: {
119 ...parseKimiCodeCustomHeaders(),
120 Authorization: `Bearer ${apiKey}`,
121 Accept: 'application/json',
122 },
123 signal,
124 });
125 if (!res.ok) {
126 throw new OpenPlatformApiError(
127 await readApiErrorMessage(res, `Failed to list models (HTTP ${res.status}).`),
128 res.status,
129 );
130 }
131 const payload: unknown = await res.json();
132 if (!isRecord(payload) || !Array.isArray(payload['data'])) {
133 throw new Error(`Unexpected models response for ${platform.baseUrl}.`);
134 }
135 return payload['data']
136 .map((item) => toModelInfo(item))
137 .filter((item): item is ManagedKimiCodeModelInfo => item !== undefined);
138}
139
140export function filterModelsByPrefix(
141 models: ManagedKimiCodeModelInfo[],

Callers 3

refreshProviderModelsFunction · 0.90
handleOpenPlatformLoginFunction · 0.85

Calls 5

readApiErrorMessageFunction · 0.90
isRecordFunction · 0.90
jsonMethod · 0.80
toModelInfoFunction · 0.70

Tested by

no test coverage detected