Anthropic — list models via /models API
(endpoint: AIEndpoint)
| 204 | |
| 205 | /** Anthropic — list models via /models API */ |
| 206 | async function fetchAnthropicModels(endpoint: AIEndpoint): Promise<string[]> { |
| 207 | const requestUrl = buildProviderModelsUrl( |
| 208 | "anthropic", |
| 209 | endpoint.baseUrl, |
| 210 | endpoint.apiKey, |
| 211 | endpoint.useExactRequestUrl, |
| 212 | ); |
| 213 | const response = await fetch(requestUrl, { |
| 214 | headers: { |
| 215 | "x-api-key": endpoint.apiKey, |
| 216 | "anthropic-version": "2023-06-01", |
| 217 | "anthropic-dangerous-direct-browser-access": "true", |
| 218 | }, |
| 219 | }); |
| 220 | if (!response.ok) { |
| 221 | if (response.status === 404 || response.status === 405) { |
| 222 | return [ |
| 223 | "claude-sonnet-4-20250514", |
| 224 | "claude-opus-4-20250514", |
| 225 | "claude-3-7-sonnet-20250219", |
| 226 | "claude-3-5-sonnet-20241022", |
| 227 | "claude-3-5-haiku-20241022", |
| 228 | "claude-3-opus-20240229", |
| 229 | "claude-3-haiku-20240307", |
| 230 | ]; |
| 231 | } |
| 232 | throw new Error(`Failed to fetch Anthropic models: ${response.status} ${response.statusText}`); |
| 233 | } |
| 234 | const data = await response.json(); |
| 235 | return (data.data || []) |
| 236 | .map((m: { id: string }) => m.id) |
| 237 | .sort((a: string, b: string) => a.localeCompare(b)); |
| 238 | } |
| 239 | |
| 240 | /** Google Gemini — list models via generativelanguage API */ |
| 241 | async function fetchGoogleModels(endpoint: AIEndpoint): Promise<string[]> { |
no test coverage detected