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):
inputTokensexcludescachedReadTokensandcacheWriteTokens- the cache legs are billed separately at their own rates, so pass the non-cached prompt count to avoid double-billing.reasoningTokensare billed atoutputUsdPerTokenunless the model entry declares an explicitreasoningUsdPerToken.cachedReadTokensare billed atcachedReadUsdPerTokenwhen 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).cacheWriteTokensare billed atcacheWriteUsdPerTokenwhen 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
| Parameter | Type | Default value |
|---|---|---|
args | LookupPriceArgs & { cachedReadTokens?: number; cacheWriteTokens?: number; inputTokens: number; outputTokens: number; reasoningTokens?: number; } | undefined |
snapshot | PricingSnapshot | BUNDLED_SNAPSHOT |
Returns
| { amount: number; currency: "USD"; } | null