Skip to content
Français

calculateUsageCost

import { calculateUsageCost } from "@elie-laloum/outpost/workflows";

Estimate token charges in the table’s currency from Usage.models. Rates are per million tokens. Cache reads and writes are charged once using each model’s input convention; omitted cache rates use the input rate. Missing model attribution, prices or usage return complete: false and a lower bound. Invalid counters or prices throw. This is an estimate, not an invoice.

Complete example and detailed rules.

  • usageRequired
    Usage
    Aggregate token usage with optional model-attributed counters.
  • pricesRequired
    ModelPriceTable
    Explicit rates and currency used for this estimate.

UsageCost

export declare function calculateUsageCost(
  usage: Usage,
  prices: ModelPriceTable,
): UsageCost;