(baseUrl?: string, apiKey?: string)
| 6 | import { toRequestyServiceUrl } from "../../../shared/utils/requesty" |
| 7 | |
| 8 | export async function getRequestyModels(baseUrl?: string, apiKey?: string): Promise<Record<string, ModelInfo>> { |
| 9 | const models: Record<string, ModelInfo> = {} |
| 10 | |
| 11 | try { |
| 12 | const headers: Record<string, string> = {} |
| 13 | |
| 14 | if (apiKey) { |
| 15 | headers["Authorization"] = `Bearer ${apiKey}` |
| 16 | } |
| 17 | |
| 18 | const resolvedBaseUrl = toRequestyServiceUrl(baseUrl) |
| 19 | const modelsUrl = new URL("v1/models", resolvedBaseUrl) |
| 20 | |
| 21 | const response = await axios.get(modelsUrl.toString(), { headers }) |
| 22 | const rawModels = response.data.data |
| 23 | |
| 24 | for (const rawModel of rawModels) { |
| 25 | const reasoningBudget = |
| 26 | rawModel.supports_reasoning && |
| 27 | (rawModel.id.includes("claude") || |
| 28 | rawModel.id.includes("coding/gemini-2.5") || |
| 29 | rawModel.id.includes("vertex/gemini-2.5")) |
| 30 | const reasoningEffort = |
| 31 | rawModel.supports_reasoning && |
| 32 | (rawModel.id.includes("openai") || rawModel.id.includes("google/gemini-2.5")) |
| 33 | |
| 34 | const modelInfo: ModelInfo = { |
| 35 | maxTokens: rawModel.max_output_tokens, |
| 36 | contextWindow: rawModel.context_window, |
| 37 | supportsPromptCache: rawModel.supports_caching, |
| 38 | supportsImages: rawModel.supports_vision, |
| 39 | supportsReasoningBudget: reasoningBudget, |
| 40 | supportsReasoningEffort: reasoningEffort, |
| 41 | inputPrice: parseApiPrice(rawModel.input_price), |
| 42 | outputPrice: parseApiPrice(rawModel.output_price), |
| 43 | description: rawModel.description, |
| 44 | cacheWritesPrice: parseApiPrice(rawModel.caching_price), |
| 45 | cacheReadsPrice: parseApiPrice(rawModel.cached_price), |
| 46 | } |
| 47 | |
| 48 | if (rawModel.id === "anthropic/claude-fable-5") { |
| 49 | modelInfo.supportsReasoningBudget = true |
| 50 | modelInfo.supportsReasoningBinary = true |
| 51 | modelInfo.supportsTemperature = false |
| 52 | } |
| 53 | |
| 54 | if (rawModel.id === "anthropic/claude-sonnet-5") { |
| 55 | modelInfo.supportsReasoningBudget = true |
| 56 | modelInfo.supportsReasoningBinary = true |
| 57 | modelInfo.supportsTemperature = false |
| 58 | } |
| 59 | |
| 60 | models[rawModel.id] = modelInfo |
| 61 | } |
| 62 | } catch (error) { |
| 63 | console.error(`Error fetching Requesty models: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`) |
| 64 | } |
| 65 |
no test coverage detected