MCPcopy Create free account
hub / github.com/TanStack/ai / calculateCost

Function calculateCost

examples/ts-code-mode-web/src/lib/efficiency.ts:104–116  ·  view source on GitHub ↗

* Calculate cost from tokens using model pricing.

(
  tokens: number,
  pricing: { input: number; output: number },
)

Source from the content-addressed store, hash-verified

102 * Calculate cost from tokens using model pricing.
103 */
104function calculateCost(
105 tokens: number,
106 pricing: { input: number; output: number },
107): number {
108 // Assume 80% input, 20% output
109 const inputTokens = tokens * 0.8
110 const outputTokens = tokens * 0.2
111
112 const inputCost = (inputTokens / 1_000_000) * pricing.input
113 const outputCost = (outputTokens / 1_000_000) * pricing.output
114
115 return inputCost + outputCost
116}
117
118/**
119 * Calculate comprehensive efficiency metrics from byte measurements.

Callers 2

calculateEfficiencyFunction · 0.85
estimateCostFromBytesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected