Skip to content

Instantly share code, notes, and snippets.

@opsJson
Created January 30, 2025 03:03
Show Gist options
  • Save opsJson/d6b5ac8973e2c55692335b9e2f377e95 to your computer and use it in GitHub Desktop.
Save opsJson/d6b5ac8973e2c55692335b9e2f377e95 to your computer and use it in GitHub Desktop.
Calcular gasto com API do ChatGPT
let inputTokens1M = 0.150;
let outputTokens1M = 0.6;
let messageTokens = 30;
let messagesInChat = 5;
let chatsInDay = 50;
let daysInMonth = 30;
let USDtoBRL = 6;
const inputTokenPrice = inputTokens1M / 1000000;
const outputTokenPrice = outputTokens1M / 1000000;
let price = 0;
price += outputTokenPrice * messageTokens * (messagesInChat / 2) * chatsInDay * daysInMonth;
let inputPrice = 0;
for (let i=0; i<messagesInChat; i++) {
const contextMessages = i *2+1;
inputPrice += inputTokenPrice * messageTokens * contextMessages;
}
price += inputPrice * chatsInDay * daysInMonth;
price *= USDtoBRL;
console.log(price.toFixed(2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment