export async function fetchCohereData()

in src/lib/server/providers/cohere.ts [6:35]


export async function fetchCohereData(apiKey: string | undefined): Promise<MaxTokensCache["cohere"]> {
	if (!apiKey) {
		console.warn("Cohere API key not provided. Skipping Cohere fetch.");
		return {};
	}
	try {
		const response = await fetch(COHERE_API_URL, {
			headers: {
				Authorization: `Bearer ${apiKey}`, // Use passed-in apiKey
			},
		});
		if (!response.ok) {
			throw new Error(`Cohere API request failed: ${response.status} ${response.statusText}`);
		}
		// eslint-disable-next-line @typescript-eslint/no-explicit-any
		const data: any = await response.json();
		const modelsData: MaxTokensCache["cohere"] = {};
		if (data?.models && Array.isArray(data.models)) {
			for (const model of data.models) {
				if (model.name && typeof model.context_length === "number") {
					modelsData[model.name] = model.context_length;
				}
			}
		}
		return modelsData;
	} catch (error) {
		console.error("Error fetching Cohere data:", error);
		return {};
	}
}