Skip to content

Graphorin API reference v0.12.1


Graphorin API reference / @graphorin/pricing / / calculateCost

Function: calculateCost()

ts
function calculateCost(args, snapshot?): 
  | {
  amount: number;
  currency: "USD";
}
  | null;

Defined in: packages/pricing/src/lookup.ts:135

Multiply a per-token price by an integer token count. Returns null when the price is unknown. Useful when caller wants to compute cost for a single LLM call without instantiating the cost tracker.

Token-count contract (PS-19):

  • inputTokens excludes cachedReadTokens and cacheWriteTokens - the cache legs are billed separately at their own rates, so pass the non-cached prompt count to avoid double-billing.
  • reasoningTokens are billed at outputUsdPerToken unless the model entry declares an explicit reasoningUsdPerToken.
  • cachedReadTokens are billed at cachedReadUsdPerToken when the entry declares one, else at the full input rate (never $0 - a cached read is at minimum a normal input token; the fallback never under-bills).
  • cacheWriteTokens are billed at cacheWriteUsdPerToken when the entry declares one, else at the full input rate (a cache write is at minimum a normal input token - the fallback never under-bills relative to no cache).

Units contract (W-045): this is the CANONICAL producer of core Cost.amount, and it returns WHOLE US dollars (per-token USD rates times token counts) - never cents / minor units. One million input tokens at inputUsdPerToken = 3e-6 cost 3 (three dollars).

Parameters

ParameterTypeDefault value
argsLookupPriceArgs & { cachedReadTokens?: number; cacheWriteTokens?: number; inputTokens: number; outputTokens: number; reasoningTokens?: number; }undefined
snapshotPricingSnapshotBUNDLED_SNAPSHOT

Returns

| { amount: number; currency: "USD"; } | null

Stable