Files
hikari/bot/prod/utils/calculateCost.js
Naomi Carrigan cd5c3761f4
All checks were successful
Node.js CI / Lint and Test (pull_request) Successful in 1m17s
feat: build out discord support agent
2025-07-05 23:06:45 -07:00

24 lines
859 B
JavaScript

/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { logger } from "./logger.js";
/**
* Calculates the cost of a command run by a user, and sends to
* our logging service.
* @param usage -- The usage payload from Anthropic.
* @param uuid -- The Discord ID of the user who ran the command.
*/
export const calculateCost = async (usage, uuid) => {
const inputCost = usage.input_tokens * (3 / 1_000_000);
const outputCost = usage.output_tokens * (15 / 1_000_000);
const totalCost = inputCost + outputCost;
await logger.log("info", `User ${uuid} used the bot, which accepted ${usage.input_tokens.toString()} tokens and generated ${usage.output_tokens.toString()} tokens.
Total cost: ${totalCost.toLocaleString("en-GB", {
currency: "USD",
style: "currency",
})}`);
};