mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
* Chore: Pretier for consistant formatting - TODO: This PR needs to be updated by Saoud after he runs `npm install` & `npm format:fix` and commits the results of the prettier changes. * Revert prettier config * Run npm install * Fix prettier config and ignore package lock * Run format --------- Co-authored-by: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com>
25 lines
923 B
TypeScript
25 lines
923 B
TypeScript
import { ModelInfo } from "../shared/api"
|
|
|
|
export function calculateApiCost(
|
|
modelInfo: ModelInfo,
|
|
inputTokens: number,
|
|
outputTokens: number,
|
|
cacheCreationInputTokens?: number,
|
|
cacheReadInputTokens?: number,
|
|
): number {
|
|
const modelCacheWritesPrice = modelInfo.cacheWritesPrice
|
|
let cacheWritesCost = 0
|
|
if (cacheCreationInputTokens && modelCacheWritesPrice) {
|
|
cacheWritesCost = (modelCacheWritesPrice / 1_000_000) * cacheCreationInputTokens
|
|
}
|
|
const modelCacheReadsPrice = modelInfo.cacheReadsPrice
|
|
let cacheReadsCost = 0
|
|
if (cacheReadInputTokens && modelCacheReadsPrice) {
|
|
cacheReadsCost = (modelCacheReadsPrice / 1_000_000) * cacheReadInputTokens
|
|
}
|
|
const baseInputCost = ((modelInfo.inputPrice || 0) / 1_000_000) * inputTokens
|
|
const outputCost = ((modelInfo.outputPrice || 0) / 1_000_000) * outputTokens
|
|
const totalCost = cacheWritesCost + cacheReadsCost + baseInputCost + outputCost
|
|
return totalCost
|
|
}
|