Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type CurrencyState = {
}

const CACHE_TTL_MS = 24 * 60 * 60 * 1000
const FETCH_TIMEOUT_MS = 10_000
const FRANKFURTER_URL = 'https://api.frankfurter.app/latest?from=USD&to='
// Defensive bounds on any fetched FX rate. Outside this band the rate is either a parser bug
// or a tampered Frankfurter response, and we refuse to multiply it into displayed costs.
Expand Down Expand Up @@ -63,7 +64,7 @@ function getRateCachePath(): string {
}

async function fetchRate(code: string): Promise<number> {
const response = await fetch(`${FRANKFURTER_URL}${code}`)
const response = await fetch(`${FRANKFURTER_URL}${code}`, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) })
if (!response.ok) throw new Error(`HTTP ${response.status}`)
const data = await response.json() as { rates?: Record<string, unknown> }
const rate = data.rates?.[code]
Expand Down
3 changes: 2 additions & 1 deletion src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type LiteLLMEntry = {
}

const LITELLM_URL = 'https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json'
const FETCH_TIMEOUT_MS = 10_000
const CACHE_TTL_MS = 24 * 60 * 60 * 1000
const WEB_SEARCH_COST = 0.01

Expand Down Expand Up @@ -74,7 +75,7 @@ function parseLiteLLMEntry(entry: LiteLLMEntry): ModelCosts | null {
}

async function fetchAndCachePricing(): Promise<Map<string, ModelCosts>> {
const response = await fetch(LITELLM_URL)
const response = await fetch(LITELLM_URL, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) })
if (!response.ok) throw new Error(`HTTP ${response.status}`)
const data = await response.json() as Record<string, LiteLLMEntry>
const pricing = new Map<string, ModelCosts>()
Expand Down
Loading