/** * Provider taxonomy as used throughout routerlab. Note this is a strict * superset of tokenometer's provider list (anthropic/openai/google/mistral/ * cohere), because routerlab also routes across third-party hosting * platforms (groq, together, hf, openrouter) that re-serve open-weight * models from Meta, Mistral, etc. * * The cost module maps the hosting-platform providers down to the model * family's *base* tokenizer (e.g. `groq` + Llama → tokenometer's `openai` * cl100k/o200k path as a safe approximation, since Meta tokenizers are * not in tokenometer; `together` + Mixtral → tokenometer's `mistral` * SentencePiece path). */ export type CostProvider = "anthropic" | "openai" | "google" | "mistral" | "cohere" | "groq" | "together" | "hf" | "openrouter"; export type TokenSource = "tokenometer-empirical" | "tokenometer-offline" | "atlas-calibrated" | "proxy"; export type Confidence = "high" | "medium" | "low"; /** * Per-million-token pricing. Mirrors the shape used by router engine's * `ModelPricing` so a caller can pass the same object to both modules. */ export interface CostPricing { inputUsdPerMtok: number; outputUsdPerMtok: number; } export interface CostInput { /** The user-supplied prompt text. Counted in input tokens. */ prompt: string; /** Canonical model id, e.g. "claude-opus-4-7", "llama-3.3-70b". */ model: string; /** Provider hosting the model. */ provider: CostProvider; /** Per-million-token pricing for the model. */ pricing: CostPricing; /** * Optional caller hint for how many tokens the model is expected to * generate. If absent, a task-class heuristic is used (see * `defaultOutputTokens`). Pass an explicit value when the caller knows * better — e.g. a classification task is bounded to a label vocab. */ expectedOutputTokens?: number; /** * Optional task-class hint used to choose the default expected output * length when `expectedOutputTokens` is not provided. Defaults to "qa". */ taskClass?: TaskClass; } export interface CostEstimate { model: string; provider: CostProvider; inputTokens: number; outputTokensEstimate: number; inputUsd: number; outputUsd: number; totalUsd: number; tokenSource: TokenSource; confidence: Confidence; /** * Human-readable notes describing how this estimate was derived. Useful * for debugging routing decisions and for surfacing source attribution * to end users (e.g. "atlas calibration applied: factor 1.62 for * anthropic/cl100k_base"). */ notes: string[]; } /** * Routing task classes. Mirrors the `TaskClass` enum declared in * `./types.ts` by the routing engine. We re-declare locally rather than * importing because `cost.ts` is published as a leaf module and must * compile in isolation — atlas-grounding is the contribution; the rest * of the engine is layered on top. The two declarations are kept in * lockstep by the build orchestrator's integration sweep. */ export type TaskClass = "qa" | "codegen" | "summarization" | "classification" | "reasoning"; export type CostEstimationFailure = { kind: "unknown-provider"; provider: string; } | { kind: "tokenometer-unreachable"; cause: unknown; } | { kind: "calibration-malformed"; path: string; cause: unknown; } | { kind: "invalid-input"; field: string; reason: string; }; /** * Discriminated error type thrown by the cost module for typed failure * handling at the call site. */ export declare class CostEstimationError extends Error { readonly failure: CostEstimationFailure; constructor(failure: CostEstimationFailure); } /** * Test-only hook. Forces the next call to `getCalibration()` to re-read * the atlas file. Not part of the public API; tests reach in via the * exported symbol for memoization control. */ export declare const __resetCalibrationCacheForTest: () => void; /** * Estimate the USD cost of running `input.prompt` through `input.model`, * grounded in tokenometer's offline tokenizer output and (when available) * the llm-tokens-atlas per-provider correction factors. * * This function is pure: same input → same output. It performs no network * I/O. The atlas calibration file is read once at module load (memoized); * tokenometer's offline tokenizers are pure local operations. */ export declare const estimateCost: (input: CostInput) => CostEstimate; /** * Estimate cost for a batch of inputs. Convenience wrapper around * `estimateCost`; the underlying call is pure so this is just `inputs.map`. * Provided as a public surface so callers (e.g. the routing engine) can * vectorize without re-importing. */ export declare const estimateCostBatch: (inputs: readonly CostInput[]) => CostEstimate[]; //# sourceMappingURL=cost.d.ts.map