/** * LLM call cost calculator. * * Given a model id and a token-usage shape from the LLM SDK, compute the * cost — either in the table's base currency (USD by default) or converted * to a local currency via a foreign-exchange rate. * * Use cases: * - Per-user budget caps: refuse an AI turn once the user's running cost * exceeds a threshold (read it back via `UsageCounter`). * - Per-tenant unit economics: log every turn's cost to Analytics Engine * and graph it on the dashboard. * - Cross-provider comparison: swap `'openai:gpt-4o-mini'` for * `'anthropic:claude-haiku-4-5'` and immediately know the delta. * * The price table is data, not code — extend `DEFAULT_PRICE_TABLE` or pass * your own. Prices are quoted per-million tokens to match how OpenAI, * Anthropic, and Azure document them on their pricing pages. * * Aliases: `'gpt-4o-mini'` and `'openai:gpt-4o-mini'` both resolve to the * same entry. The provider prefix is documentation; the lookup is exact on * the bare model id with the prefix stripped. */ export interface ModelPrice { /** USD per 1,000,000 input tokens. */ inputPerM: number; /** USD per 1,000,000 output tokens. */ outputPerM: number; } export type PriceTable = Record; export interface LLMUsage { inputTokens?: number; outputTokens?: number; /** Some SDKs use these names; we accept both. */ prompt_tokens?: number; completion_tokens?: number; } export interface LLMCostArgs { model: string; usage: LLMUsage | null | undefined; priceTable?: PriceTable; /** Currency code for the returned amount. Default 'USD'. */ currency?: string; /** Multiplier applied to the USD subtotal. Default 1 (USD). */ fxRate?: number; /** * Model id to use when `model` isn't in the table. Default null — * unknown models return 0. Set to a real id (e.g. `'gpt-4o-mini'`) to * over-estimate against the cheapest known model instead of zero. */ fallbackModel?: string | null; /** Number of decimal places in the returned amount. Default 6. */ decimals?: number; } export interface LLMCostResult { model: string; currency: string; amount: number; inputTokens: number; outputTokens: number; resolvedFrom: 'exact' | 'fallback' | 'unknown'; } /** * Shipped price table — accurate as of the 0.4 release; treat as a * starting point. The framework deliberately doesn't auto-update this * (silent cost drift is worse than a stale-but-stable number). */ export declare const DEFAULT_PRICE_TABLE: PriceTable; /** * One-shot cost computation. Side-effect-free; prefer `LLMCostCalculator` * when you call it from a hot path against a fixed table. */ export declare function computeLLMCost(args: LLMCostArgs): LLMCostResult; export interface LLMCostCalculatorOptions { priceTable?: PriceTable; currency?: string; fxRate?: number; fallbackModel?: string | null; decimals?: number; } /** * Bind a price table + currency + fxRate once, then call `.compute()` per * turn. Useful when every turn uses the same conversion (one tenant, one * currency) and you don't want to repeat the boilerplate. */ export declare class LLMCostCalculator { readonly priceTable: PriceTable; readonly currency: string; readonly fxRate: number; readonly fallbackModel: string | null; readonly decimals: number; constructor({ priceTable, currency, fxRate, fallbackModel, decimals, }?: LLMCostCalculatorOptions); compute(model: string, usage: LLMUsage | null | undefined): LLMCostResult; /** Add or override one model's price. Useful for new deployments. */ withPrice(model: string, price: ModelPrice): LLMCostCalculator; } //# sourceMappingURL=llm_cost.d.ts.map