MCPcopy
hub / github.com/continuedev/continue / fetchOpenRouterModels

Function fetchOpenRouterModels

core/llm/fetchModels.ts:124–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

122}
123
124async function fetchOpenRouterModels(): Promise<FetchedModel[]> {
125 try {
126 const response = await fetch("https://openrouter.ai/api/v1/models");
127 if (!response.ok) {
128 throw new Error(`Failed to fetch OpenRouter models: ${response.status}`);
129 }
130
131 const data = await response.json();
132 if (!data.data || !Array.isArray(data.data)) {
133 return [];
134 }
135
136 return data.data
137 .filter((m: any) => m.id && m.name)
138 .map((m: any) => ({
139 name: m.name,
140 modelId: m.id,
141 icon: "openrouter.png",
142 contextLength: m.context_length,
143 maxTokens: m.top_provider?.max_completion_tokens,
144 supportsTools: (m.supported_parameters ?? []).includes("tools"),
145 }));
146 } catch (error) {
147 console.error("Error fetching OpenRouter models:", error);
148 return [];
149 }
150}
151
152async function fetchAnthropicModels(apiKey?: string): Promise<FetchedModel[]> {
153 const response = await fetch(

Callers 1

fetchModelsFunction · 0.85

Calls 2

errorMethod · 0.80
fetchFunction · 0.70

Tested by

no test coverage detected