(apiKey: string)
| 172 | } |
| 173 | |
| 174 | export async function fetchOpenRouterModels(apiKey: string): Promise<string[]> { |
| 175 | try { |
| 176 | const response = await fetch('https://openrouter.ai/api/v1/models', { |
| 177 | headers: { |
| 178 | Authorization: `Bearer ${apiKey}` |
| 179 | } |
| 180 | }); |
| 181 | |
| 182 | if (!response.ok) { |
| 183 | return MODEL_LIST.openrouter; |
| 184 | } |
| 185 | |
| 186 | const data = await response.json(); |
| 187 | // Filter to text-capable models only (exclude image/audio models) |
| 188 | const models = data.data |
| 189 | ?.filter( |
| 190 | (m: { id: string; context_length?: number }) => |
| 191 | m.context_length && m.context_length > 0 |
| 192 | ) |
| 193 | .map((m: { id: string }) => m.id) |
| 194 | .sort(); |
| 195 | |
| 196 | return models && models.length > 0 ? models : MODEL_LIST.openrouter; |
| 197 | } catch { |
| 198 | return MODEL_LIST.openrouter; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | export async function fetchDeepSeekModels(apiKey: string): Promise<string[]> { |
| 203 | try { |
no test coverage detected
searching dependent graphs…