(apiKey?: string | null)
| 5 | import { parseApiPrice } from "../../../shared/cost" |
| 6 | |
| 7 | export async function getUnboundModels(apiKey?: string | null): Promise<Record<string, ModelInfo>> { |
| 8 | const models: Record<string, ModelInfo> = {} |
| 9 | |
| 10 | try { |
| 11 | const headers: Record<string, string> = {} |
| 12 | |
| 13 | if (apiKey) { |
| 14 | headers["Authorization"] = `Bearer ${apiKey}` |
| 15 | } |
| 16 | |
| 17 | const response = await axios.get("https://api.getunbound.ai/models", { headers }) |
| 18 | const rawModels = response.data?.data ?? response.data |
| 19 | |
| 20 | for (const rawModel of rawModels) { |
| 21 | const modelInfo: ModelInfo = { |
| 22 | maxTokens: rawModel.max_output_tokens ?? 8192, |
| 23 | contextWindow: rawModel.context_window ?? 200_000, |
| 24 | supportsPromptCache: rawModel.supports_caching ?? false, |
| 25 | supportsImages: rawModel.supports_vision ?? false, |
| 26 | inputPrice: parseApiPrice(rawModel.input_price), |
| 27 | outputPrice: parseApiPrice(rawModel.output_price), |
| 28 | description: rawModel.description, |
| 29 | cacheWritesPrice: parseApiPrice(rawModel.caching_price), |
| 30 | cacheReadsPrice: parseApiPrice(rawModel.cached_price), |
| 31 | } |
| 32 | |
| 33 | models[rawModel.id] = modelInfo |
| 34 | } |
| 35 | } catch (error) { |
| 36 | console.error(`Error fetching Unbound models: ${JSON.stringify(error, Object.getOwnPropertyNames(error), 2)}`) |
| 37 | } |
| 38 | |
| 39 | return models |
| 40 | } |
no test coverage detected