/** * Token-usage accounting and budget enforcement. * * Phase-1 sibling of the reference engines' cost tracking. Accumulates token * usage across a turn's model calls, optionally converts it to a USD cost via a * per-model pricing table, and lets a turn stop early once a token or cost budget * is hit. Usage is exact; cost depends on the (approximate, overridable) pricing. */ export interface Usage { promptTokens: number; completionTokens: number; } export declare function totalTokens(u: Usage): number; /** USD per 1,000,000 tokens, input and output. */ export interface ModelPricing { inputPerMTok: number; outputPerMTok: number; } export declare function pricingCost(p: ModelPricing, u: Usage): number; /** Approximate default pricing (USD / 1M tokens). Override via AgentOptions.pricing. */ export declare const DEFAULT_PRICING: Record; /** * The response headers the LLM gateway reports per-request cost in, in PRECEDENCE * order. Mirrors the Rust reference's candidate list exactly * (`rust/smooth-operator-core/src/llm.rs`). * * LiteLLM splits cost across a few headers: `-margin-amount` is what the caller * actually pays (includes the gateway's markup), `-original` is the raw upstream * cost, and the bare `x-litellm-response-cost` is the legacy shape older versions * emit. The last two are generic fallbacks for other OpenAI-compatible gateways. */ export declare const GATEWAY_COST_HEADERS: readonly string[]; /** Anything that can look up a header by (case-insensitive) name. */ export type HeaderLike = Headers | Record | { get(name: string): string | null | undefined; }; /** * Read the gateway's authoritative per-request cost from response headers, taking * the FIRST NON-ZERO candidate. * * Returns `undefined` when every candidate is absent OR reports zero. That * distinction is the whole point: `undefined` means "unmeasured", so the caller * falls back to local {@link ModelPricing}, whereas locking in 0 would pin cost at * zero for the rest of the dispatch. LiteLLM's config on llm.smoo.ai currently * reports 0 for `smooth-*` aliases on every response, so taking a zero at face * value silently zeroes real spend. */ export declare function parseGatewayCost(headers: HeaderLike | null | undefined): number | undefined; /** A ceiling for a turn. Either limit may be set; the first hit stops the turn. */ export interface CostBudget { maxUsd?: number; maxTokens?: number; } /** Accumulates usage + cost across a turn's model calls. */ export declare class CostTracker { usage: Usage; costUsd: number; record(model: string, usage: Usage, pricing?: Record): void; /** * Record usage, preferring the gateway's authoritative per-request cost when it * measured one. `undefined` means "unmeasured" and falls back to the local * {@link ModelPricing} estimate — which is the whole reason * {@link parseGatewayCost} returns `undefined` rather than 0. Aliased models * (`smooth-*`) price at $0 locally, so the gateway's number is often the only * real one available. */ recordWithGatewayCost(model: string, usage: Usage, gatewayCostUsd: number | undefined, pricing?: Record): void; exceeds(budget?: CostBudget): boolean; } //# sourceMappingURL=cost.d.ts.map