Skip to content
Français

loadModelPrices

import { loadModelPrices } from "@elie-laloum/outpost/harness";

Fetch a bounded, cancellable models.dev or OpenRouter catalog once and return a frozen price table for the explicitly selected model aliases. Catalog prices are USD; EUR requires a caller-supplied exchange rate. Normalize OpenRouter per-token rates to per-million rates. Refuse missing models, invalid prices and unsupported tier or extra charges; no refresh or network access occurs during workflow accounting. The table estimates token charges only; taxes, discounts, tools, images and other billing dimensions are excluded.

Complete example and detailed rules.

  • optionsRequired
    ModelPricesOptions
    Catalog selection, model aliases, currency conversion and bounded HTTP request settings.
  • options.sourceOptional
    "models.dev" | "openrouter" | undefined
    Public catalog to load: models.dev (default) or openrouter.
  • options.providerOptional
    string | undefined
    Required models.dev provider ID; ignored for OpenRouter.
  • options.modelsRequired
    Readonly<Record<string, string>>
    Outpost model names mapped to exact IDs in the selected catalog; loads only these prices.
  • options.currencyOptional
    "EUR" | "USD" | undefined
    Output currency, USD by default; EUR requires usdExchangeRate.
  • options.usdExchangeRateOptional
    number | undefined
    Caller-supplied amount of EUR for one USD when currency is EUR. USD accepts only 1.
  • options.urlOptional
    string | undefined
    Optional absolute HTTP(S) catalog endpoint, without embedded credentials or fragment. Defaults to the public source URL.
  • options.signalOptional
    AbortSignal | undefined
    Cancels the catalog request and body reading.
  • options.timeoutMsOptional
    number | undefined
    Total catalog request deadline, 15000 ms by default.
  • options.maxResponseBytesOptional
    number | undefined
    Maximum catalog response bytes, 32 MiB by default.

Promise<ModelPriceTable>

export declare function loadModelPrices(
  options: ModelPricesOptions,
): Promise<ModelPriceTable>;