| 150 | } |
| 151 | |
| 152 | async function fetchAnthropicModels(apiKey?: string): Promise<FetchedModel[]> { |
| 153 | const response = await fetch( |
| 154 | "https://api.anthropic.com/v1/models?limit=100", |
| 155 | { |
| 156 | headers: { |
| 157 | "x-api-key": apiKey ?? "", |
| 158 | "anthropic-version": "2023-06-01", |
| 159 | }, |
| 160 | }, |
| 161 | ); |
| 162 | if (!response.ok) { |
| 163 | throw new Error(`Failed to fetch Anthropic models: ${response.status}`); |
| 164 | } |
| 165 | const data = await response.json(); |
| 166 | return (data.data ?? []).map((m: any) => ({ |
| 167 | name: m.display_name ?? m.id, |
| 168 | modelId: m.id, |
| 169 | icon: "anthropic.png", |
| 170 | contextLength: m.max_input_tokens, |
| 171 | maxTokens: m.max_tokens, |
| 172 | supportsTools: true, |
| 173 | })); |
| 174 | } |
| 175 | |
| 176 | async function fetchGeminiModels( |
| 177 | apiKey?: string, |