feat: initial prototype
Code Analysis / SonarQube (push) Failing after 19s
Node.js CI / Lint and Test (push) Has been cancelled

This commit is contained in:
2025-10-09 11:28:28 -07:00
parent 00cbbdab24
commit 68f7eabe2c
27 changed files with 6158 additions and 14 deletions
+30
View File
@@ -0,0 +1,30 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { Usage } from "@anthropic-ai/sdk/resources/index.js";
/**
* Calculates the cost of a command run by a user, and sends to
* our logging service.
* @param usage -- The usage payload from Anthropic.
* @returns A string containing the usage and cost information.
*/
export const calculateCost = (
usage: Usage,
): string => {
const inputCost = usage.input_tokens * ((usage.input_tokens > 200_000
? 6
: 3) / 1_000_000);
const outputCost = usage.output_tokens * ((usage.output_tokens > 200_000
? 22.5
: 15) / 1_000_000);
const totalCost = inputCost + outputCost;
return `-# Accepted ${usage.input_tokens.toString()} and generated ${usage.output_tokens.toString()}.
-# Total cost: ${totalCost.toLocaleString("en-GB", {
currency: "USD",
style: "currency",
})}`;
};