fix(models): refresh model pricing
This commit is contained in:
+16
-4
@@ -10,10 +10,22 @@
|
||||
import type { ModelLike, Usage } from "./types.ts"
|
||||
|
||||
export function calculateCommandCodeCost(model: ModelLike, usage: Usage): void {
|
||||
usage.cost.input = (model.cost.input / 1_000_000) * usage.input
|
||||
usage.cost.output = (model.cost.output / 1_000_000) * usage.output
|
||||
usage.cost.cacheRead = (model.cost.cacheRead / 1_000_000) * usage.cacheRead
|
||||
usage.cost.cacheWrite = (model.cost.cacheWrite * usage.cacheWrite) / 1_000_000
|
||||
const inputTokens = usage.input + usage.cacheRead + usage.cacheWrite
|
||||
let rates = model.cost
|
||||
let matchedThreshold = -1
|
||||
for (const tier of model.cost.tiers ?? []) {
|
||||
if (inputTokens > tier.inputTokensAbove && tier.inputTokensAbove > matchedThreshold) {
|
||||
rates = tier
|
||||
matchedThreshold = tier.inputTokensAbove
|
||||
}
|
||||
}
|
||||
|
||||
const longWrite = usage.cacheWrite1h ?? 0
|
||||
const shortWrite = usage.cacheWrite - longWrite
|
||||
usage.cost.input = (rates.input / 1_000_000) * usage.input
|
||||
usage.cost.output = (rates.output / 1_000_000) * usage.output
|
||||
usage.cost.cacheRead = (rates.cacheRead / 1_000_000) * usage.cacheRead
|
||||
usage.cost.cacheWrite = (rates.cacheWrite * shortWrite + rates.input * 2 * longWrite) / 1_000_000
|
||||
usage.cost.total =
|
||||
usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user